Repository navigation
feat(cmdk): Group project settings actions #112913
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2118410
ref(cmdk) add project settings search
JonasBa 0944e8c
feat(cmdk): Group project settings actions
JonasBa a3a6c5b
Merge branch 'master' into jb/cmdk/project-settings-context
JonasBa f33d167
fix(cmdk): Use stable section IDs for project settings grouping logic
JonasBa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
static/app/views/settings/project/projectSettingsCommandPaletteActions.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import {OrganizationFixture} from 'sentry-fixture/organization'; | ||
| import {PluginFixture} from 'sentry-fixture/plugin'; | ||
| import {ProjectFixture} from 'sentry-fixture/project'; | ||
|
|
||
| import {getProjectSettingsCommandPaletteSections} from 'sentry/views/settings/project/projectSettingsCommandPaletteActions'; | ||
|
|
||
| describe('ProjectSettingsCommandPaletteActions', () => { | ||
| it('returns current project settings sections with visibility rules applied', () => { | ||
| const organization = OrganizationFixture({ | ||
| access: ['project:write'], | ||
| features: ['performance-view'], | ||
| slug: 'acme', | ||
| }); | ||
| const project = ProjectFixture({ | ||
| slug: 'frontend', | ||
| plugins: [ | ||
| PluginFixture({enabled: true, id: 'github', isDeprecated: false, name: 'GitHub'}), | ||
| PluginFixture({ | ||
| enabled: true, | ||
| id: 'legacy', | ||
| isDeprecated: true, | ||
| name: 'Legacy Plugin', | ||
| }), | ||
| ], | ||
| }); | ||
|
|
||
| const sections = getProjectSettingsCommandPaletteSections({organization, project}); | ||
|
|
||
| expect(sections).toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| label: 'Project Settings', | ||
| items: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| label: 'General', | ||
| items: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| display: expect.objectContaining({label: 'General Settings'}), | ||
| to: '/settings/acme/projects/frontend/', | ||
| }), | ||
| ]), | ||
| }), | ||
| expect.objectContaining({ | ||
| label: 'Processing', | ||
| items: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| display: expect.objectContaining({label: 'Performance'}), | ||
| to: '/settings/acme/projects/frontend/performance/', | ||
| }), | ||
| ]), | ||
| }), | ||
| expect.objectContaining({ | ||
| label: 'SDK setup', | ||
| }), | ||
| expect.objectContaining({ | ||
| display: expect.objectContaining({label: 'Legacy Integrations'}), | ||
| to: '/settings/acme/projects/frontend/plugins/', | ||
| }), | ||
| ]), | ||
| }), | ||
| ]) | ||
| ); | ||
|
|
||
| expect(sections).not.toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| label: 'Project Settings', | ||
| items: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| label: 'Processing', | ||
| items: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| to: '/settings/acme/projects/frontend/replays/', | ||
| }), | ||
| ]), | ||
| }), | ||
| ]), | ||
| }), | ||
| ]) | ||
| ); | ||
|
|
||
| expect(sections).not.toEqual( | ||
| expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| items: expect.arrayContaining([ | ||
| expect.objectContaining({ | ||
| to: '/settings/acme/projects/frontend/plugins/legacy/', | ||
| }), | ||
| ]), | ||
| }), | ||
| ]) | ||
| ); | ||
| }); | ||
| }); | ||
176 changes: 176 additions & 0 deletions
176
static/app/views/settings/project/projectSettingsCommandPaletteActions.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| import {Fragment} from 'react'; | ||
| import type {ReactNode} from 'react'; | ||
|
|
||
| import {ProjectAvatar} from '@sentry/scraps/avatar'; | ||
|
|
||
| import {CMDKAction} from 'sentry/components/commandPalette/ui/cmdk'; | ||
| import {CommandPaletteSlot} from 'sentry/components/commandPalette/ui/commandPaletteSlot'; | ||
| import {IconCode, IconProject, IconStack} from 'sentry/icons'; | ||
| import {t} from 'sentry/locale'; | ||
| import type {Organization} from 'sentry/types/organization'; | ||
| import type {Project} from 'sentry/types/project'; | ||
| import {replaceRouterParams} from 'sentry/utils/replaceRouterParams'; | ||
| import {getNavigationConfiguration} from 'sentry/views/settings/project/navigationConfiguration'; | ||
| import type {NavigationGroupProps, NavigationItem} from 'sentry/views/settings/types'; | ||
|
|
||
| type ProjectSettingsCommandPaletteEntry = { | ||
| display: { | ||
| label: string; | ||
| }; | ||
| keywords: string[]; | ||
| to: string; | ||
| }; | ||
|
|
||
| type ProjectSettingsCommandPaletteGroup = { | ||
| items: Array<{ | ||
| display: { | ||
| label: string; | ||
| }; | ||
| keywords: string[]; | ||
| to: string; | ||
| }>; | ||
| label: string; | ||
| icon?: ReactNode; | ||
| }; | ||
|
|
||
| type ProjectSettingsCommandPaletteSection = { | ||
| items: Array<ProjectSettingsCommandPaletteEntry | ProjectSettingsCommandPaletteGroup>; | ||
| label: string; | ||
| icon?: ReactNode; | ||
| }; | ||
|
|
||
| function shouldShowItem( | ||
| item: NavigationItem, | ||
| context: Omit<NavigationGroupProps, 'items' | 'name' | 'id'>, | ||
| section: {id: string; items: NavigationItem[]; name: string} | ||
| ) { | ||
| if (typeof item.show === 'function') { | ||
| return item.show({...context, ...section}); | ||
| } | ||
|
|
||
| return item.show !== false; | ||
| } | ||
|
|
||
| export function getProjectSettingsCommandPaletteSections({ | ||
| organization, | ||
| project, | ||
| }: { | ||
| organization: Organization; | ||
| project: Project; | ||
| }): ProjectSettingsCommandPaletteSection[] { | ||
| const context = { | ||
| access: new Set(organization.access), | ||
| features: new Set(organization.features), | ||
| organization, | ||
| project, | ||
| }; | ||
| const groupedSectionIds = new Set([ | ||
| 'settings-project', | ||
| 'settings-processing', | ||
| 'settings-sdk', | ||
| 'settings-legacy-integrations', | ||
| ]); | ||
|
|
||
| const sections = getNavigationConfiguration({ | ||
| debugFilesNeedsReview: false, | ||
| organization, | ||
| project, | ||
| }) | ||
| .map(section => { | ||
| const label = | ||
| section.id === 'settings-project' | ||
| ? t('General') | ||
| : section.id === 'settings-sdk' | ||
| ? t('SDK setup') | ||
| : section.name; | ||
|
|
||
| return { | ||
| id: section.id, | ||
| icon: groupedSectionIds.has(section.id) ? ( | ||
| section.id === 'settings-project' ? ( | ||
| <IconProject /> | ||
| ) : section.id === 'settings-processing' ? ( | ||
| <IconStack /> | ||
| ) : section.id === 'settings-sdk' ? ( | ||
| <IconCode /> | ||
| ) : undefined | ||
| ) : ( | ||
| <ProjectAvatar project={project} size={16} /> | ||
| ), | ||
| label, | ||
| items: section.items | ||
| .filter(item => shouldShowItem(item, context, section)) | ||
| .map(item => ({ | ||
| display: { | ||
| label: item.title, | ||
| }, | ||
| keywords: [section.name, 'project settings', 'settings'], | ||
| to: replaceRouterParams(item.path, { | ||
| orgId: organization.slug, | ||
| projectId: project.slug, | ||
| }), | ||
| })), | ||
| }; | ||
| }) | ||
| .filter(section => section.items.length > 0); | ||
| const groupedSections = sections.filter(section => groupedSectionIds.has(section.id)); | ||
| const ungroupedSections = sections.filter( | ||
| section => !groupedSectionIds.has(section.id) | ||
| ); | ||
|
|
||
| if (groupedSections.length === 0) { | ||
| return ungroupedSections; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| icon: <ProjectAvatar project={project} size={16} />, | ||
| label: t('Project Settings'), | ||
| items: groupedSections.map(section => | ||
| section.id === 'settings-legacy-integrations' && section.items.length > 0 | ||
| ? section.items[0]! | ||
| : section | ||
| ), | ||
| }, | ||
| ...ungroupedSections, | ||
| ]; | ||
| } | ||
|
|
||
| export function ProjectSettingsCommandPaletteActions({ | ||
| organization, | ||
| project, | ||
| }: { | ||
| organization: Organization; | ||
| project: Project; | ||
| }) { | ||
| const sections = getProjectSettingsCommandPaletteSections({organization, project}); | ||
|
|
||
| return ( | ||
| <Fragment> | ||
| {sections.map(section => { | ||
| return ( | ||
| <CommandPaletteSlot key={section.label} name="page"> | ||
| <CMDKAction display={{label: section.label, icon: section.icon}}> | ||
| {section.items.map(item => { | ||
| if ('items' in item) { | ||
| return ( | ||
| <CMDKAction | ||
| key={item.label} | ||
| display={{label: item.label, icon: item.icon}} | ||
| > | ||
| {item.items.map(action => ( | ||
| <CMDKAction key={action.to} {...action} /> | ||
| ))} | ||
| </CMDKAction> | ||
| ); | ||
| } | ||
|
|
||
| return <CMDKAction key={item.to} {...item} />; | ||
| })} | ||
| </CMDKAction> | ||
| </CommandPaletteSlot> | ||
| ); | ||
| })} | ||
| </Fragment> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.