Skip to content

feat(SelectPanel): display selected items at the top under FF #5971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

francinelucca
Copy link
Member

@francinelucca francinelucca commented Apr 25, 2025

Closes https://github.com/github/primer/issues/2409

Adds logic to SelectPanel to automatically sort items, displaying the selected items first. The sorted list gets rearranged on:

  • Filter value is cleared
  • Items have changed
  • Panel is reopened

Also adds capabilities for custom sorting, providing a sorting key, sort by ascending or descending and opt-out of "selected on top" functionality.

by default, selected items will be displayed at the top when primer_react_select_panel_order_selected_at_top FF is on

Changelog

New

  • Added sorting logic to SelectPanel
  • New Jest tests for sorting

Changed

  • Updated snapshots

Removed

  • Custom sorting logic from SelectPanel stories as it is no longer needed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

SelectPanel stories

Merge checklist

@Copilot Copilot AI review requested due to automatic review settings April 25, 2025 01:05
@francinelucca francinelucca requested a review from a team as a code owner April 25, 2025 01:05
@francinelucca francinelucca requested a review from joshblack April 25, 2025 01:05
Copy link

changeset-bot bot commented Apr 25, 2025

🦋 Changeset detected

Latest commit: b3202c9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the staff Author is a staff member label Apr 25, 2025
@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Apr 25, 2025
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces functionality to automatically sort options in the SelectPanel so that selected items are displayed first when a feature flag is enabled. It adds a new prop (showSelectedOptionsFirst), implements sorting logic within the component’s memoized items rendering, and updates tests and stories to remove obsolete custom sorting.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

File Description
packages/react/src/SelectPanel/SelectPanel.tsx Adds a new prop and state to control sorting, implements new sorting logic for selected items, and updates lifecycle handling with resetSort.
packages/react/src/SelectPanel/SelectPanel.test.tsx Introduces new Jest tests to verify the behavior of selected items being rendered on top under different flag conditions.
packages/react/src/SelectPanel/SelectPanel.stories.tsx, SelectPanel.features.stories.tsx, SelectPanel.examples.stories.tsx Removes deprecated custom sorting logic from stories to use the built-in sorting in the component.
packages/react/src/FeatureFlags/DefaultFeatureFlags.ts Enables the new feature flag (primer_react_select_panel_order_selected_at_top) by default.
Files not reviewed (1)
  • packages/react/src/SelectPanel/SelectPanel.docs.json: Language not supported

}),
)

// order selected items first
Copy link
Preview

Copilot AI Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The inline comment for itemB's selection check references 'itemA' instead of 'itemB'; please update the comment to clarify that the check is for itemB.

Copilot uses AI. Check for mistakes.

},
} as ItemProps
})
.sort((itemA, itemB) => {
Copy link
Preview

Copilot AI Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a secondary sort criteria (for example, by a stable property like the item's original index or text) when both items are equally selected/unselected to ensure a deterministic order.

Copilot uses AI. Check for mistakes.

@@ -8,4 +8,5 @@ export const DefaultFeatureFlags = FeatureFlagScope.create({
primer_react_overlay_overflow: false,
primer_react_segmented_control_tooltip: false,
primer_react_select_panel_fullscreen_on_narrow: false,
primer_react_select_panel_order_selected_at_top: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any issues with having a FF on by default? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope! Should be okay 👍

Copy link
Contributor

github-actions bot commented Apr 25, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 101.76 KB (+0.13% 🔺)
packages/react/dist/browser.umd.js 102.13 KB (+0.09% 🔺)

@github-actions github-actions bot requested a deployment to storybook-preview-5971 April 25, 2025 01:08 Abandoned
@primer-integration
Copy link

👋 Hi from github/github! Your integration PR is ready: https://github.com/github/github/pull/374845

@primer primer bot requested a review from a team as a code owner April 25, 2025 01:28
@primer primer bot requested a review from tbenning April 25, 2025 01:28
@github-actions github-actions bot added integration-tests: failing Changes in this PR cause breaking changes in gh/gh and removed update snapshots integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Apr 25, 2025
@github-actions github-actions bot requested a deployment to storybook-preview-5971 April 25, 2025 01:34 Abandoned
@github-actions github-actions bot requested a deployment to storybook-preview-5971 April 25, 2025 01:45 Abandoned
@primer-integration
Copy link

🟢 golden-jobs completed with status success.

@github-actions github-actions bot added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh and removed integration-tests: failing Changes in this PR cause breaking changes in gh/gh labels Apr 25, 2025
Copy link
Contributor

@emilybrick emilybrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

design & behavior LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh staff Author is a staff member status: review needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants