From 298953b12a429dbab1fd5728eb56311aaf639d58 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Sat, 10 Feb 2024 15:51:50 -0600 Subject: [PATCH 1/6] Added `initiallySelectedNamspaces` Signed-off-by: Andre Wanlin --- .changeset/tricky-flies-destroy.md | 6 ++++++ packages/app/src/App.tsx | 5 ++++- .../components/different-namespace.yaml | 10 +++++++++ plugins/catalog-react/api-report.md | 10 ++++++++- .../EntityNamespacePicker.test.tsx | 21 +++++++++++++++++++ .../EntityNamespacePicker.tsx | 13 +++++++++++- .../components/EntityNamespacePicker/index.ts | 2 +- plugins/catalog/api-report.md | 2 ++ .../CatalogPage/DefaultCatalogPage.tsx | 2 ++ 9 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 .changeset/tricky-flies-destroy.md create mode 100644 packages/catalog-model/examples/components/different-namespace.yaml diff --git a/.changeset/tricky-flies-destroy.md b/.changeset/tricky-flies-destroy.md new file mode 100644 index 0000000000..c79a4e771c --- /dev/null +++ b/.changeset/tricky-flies-destroy.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-catalog-react': patch +'@backstage/plugin-catalog': patch +--- + +Added support for providing an `initiallySelectedNamspaces` which accepts an array of Namespaces to have selected by default diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 3d8bd45e5a..04ce831d6a 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -161,7 +161,10 @@ const routes = ( }> {homePage} - } /> + } + /> } diff --git a/packages/catalog-model/examples/components/different-namespace.yaml b/packages/catalog-model/examples/components/different-namespace.yaml new file mode 100644 index 0000000000..accc5518de --- /dev/null +++ b/packages/catalog-model/examples/components/different-namespace.yaml @@ -0,0 +1,10 @@ +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: different-namespace + namespace: alternative + description: Example of a Component in a different namespace +spec: + type: service + lifecycle: experimental + owner: default/team-a \ No newline at end of file diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 39db26df74..11f35fc56d 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -342,7 +342,15 @@ export class EntityNamespaceFilter implements EntityFilter { } // @public (undocumented) -export const EntityNamespacePicker: () => React_2.JSX.Element; +export const EntityNamespacePicker: ( + props: EntityNamespacePickerProps, +) => React_2.JSX.Element; + +// @public +export interface EntityNamespacePickerProps { + // (undocumented) + initiallySelectedNamespaces?: string[]; +} // @public export class EntityOrphanFilter implements EntityFilter { diff --git a/plugins/catalog-react/src/components/EntityNamespacePicker/EntityNamespacePicker.test.tsx b/plugins/catalog-react/src/components/EntityNamespacePicker/EntityNamespacePicker.test.tsx index c4b5e64c9d..762cbd2a2a 100644 --- a/plugins/catalog-react/src/components/EntityNamespacePicker/EntityNamespacePicker.test.tsx +++ b/plugins/catalog-react/src/components/EntityNamespacePicker/EntityNamespacePicker.test.tsx @@ -240,4 +240,25 @@ describe('', () => { expect(screen.queryByText('Namespace')).not.toBeInTheDocument(), ); }); + it('renders initially selected namespaces', async () => { + render( + + + + + , + ); + await waitFor(() => + expect(screen.getByText('Namespace')).toBeInTheDocument(), + ); + + const buttons = screen + .getAllByRole('button') + .map(o => o.textContent) + .filter(b => b); + + expect(buttons).toEqual(['namespace-2', 'namespace-3']); + }); }); diff --git a/plugins/catalog-react/src/components/EntityNamespacePicker/EntityNamespacePicker.tsx b/plugins/catalog-react/src/components/EntityNamespacePicker/EntityNamespacePicker.tsx index c6b59f9275..80ed42dfa3 100644 --- a/plugins/catalog-react/src/components/EntityNamespacePicker/EntityNamespacePicker.tsx +++ b/plugins/catalog-react/src/components/EntityNamespacePicker/EntityNamespacePicker.tsx @@ -32,8 +32,18 @@ const useStyles = makeStyles( }, ); +/** + * Props for {@link EntityNamespacePicker}. + * + * @public + */ +export interface EntityNamespacePickerProps { + initiallySelectedNamespaces?: string[]; +} + /** @public */ -export const EntityNamespacePicker = () => { +export const EntityNamespacePicker = (props: EntityNamespacePickerProps) => { + const { initiallySelectedNamespaces } = props; const classes = useStyles(); return ( { path="metadata.namespace" Filter={EntityNamespaceFilter} InputProps={{ className: classes.input }} + initialSelectedOptions={initiallySelectedNamespaces} /> ); }; diff --git a/plugins/catalog-react/src/components/EntityNamespacePicker/index.ts b/plugins/catalog-react/src/components/EntityNamespacePicker/index.ts index d08536ea2c..f0ec645e32 100644 --- a/plugins/catalog-react/src/components/EntityNamespacePicker/index.ts +++ b/plugins/catalog-react/src/components/EntityNamespacePicker/index.ts @@ -13,6 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - export { EntityNamespacePicker } from './EntityNamespacePicker'; +export type { EntityNamespacePickerProps } from './EntityNamespacePicker'; export type { CatalogReactEntityNamespacePickerClassKey } from './EntityNamespacePicker'; diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index 40d90abe40..6da30f6f84 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -239,6 +239,8 @@ export interface DefaultCatalogPageProps { // (undocumented) initiallySelectedFilter?: UserListFilterKind; // (undocumented) + initiallySelectedNamespaces?: string[]; + // (undocumented) ownerPickerMode?: EntityOwnerPickerProps['mode']; // (undocumented) pagination?: diff --git a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx index d002552311..1b91bddf2a 100644 --- a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx +++ b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx @@ -97,6 +97,7 @@ export interface DefaultCatalogPageProps { ownerPickerMode?: EntityOwnerPickerProps['mode']; pagination?: boolean | { limit?: number }; filters?: ReactNode; + initiallySelectedNamespaces?: string[]; } export function DefaultCatalogPage(props: DefaultCatalogPageProps) { @@ -110,6 +111,7 @@ export function DefaultCatalogPage(props: DefaultCatalogPageProps) { pagination, ownerPickerMode, filters, + initiallySelectedNamespaces, } = props; return ( From cadf4c18525e1cca5f89096accaf4b9cea125acc Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Sat, 10 Feb 2024 17:57:29 -0600 Subject: [PATCH 2/6] Fixed prettier error Signed-off-by: Andre Wanlin --- .../catalog-model/examples/components/different-namespace.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/catalog-model/examples/components/different-namespace.yaml b/packages/catalog-model/examples/components/different-namespace.yaml index accc5518de..80cae9c1fe 100644 --- a/packages/catalog-model/examples/components/different-namespace.yaml +++ b/packages/catalog-model/examples/components/different-namespace.yaml @@ -7,4 +7,4 @@ metadata: spec: type: service lifecycle: experimental - owner: default/team-a \ No newline at end of file + owner: default/team-a From 5f47cc5abf9266639541822f50780928972c14ed Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Thu, 15 Feb 2024 08:15:58 -0600 Subject: [PATCH 3/6] Changes based on feedback Signed-off-by: Andre Wanlin --- packages/app/src/App.tsx | 5 +---- .../examples/components/different-namespace.yaml | 10 ---------- 2 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 packages/catalog-model/examples/components/different-namespace.yaml diff --git a/packages/app/src/App.tsx b/packages/app/src/App.tsx index 04ce831d6a..3d8bd45e5a 100644 --- a/packages/app/src/App.tsx +++ b/packages/app/src/App.tsx @@ -161,10 +161,7 @@ const routes = ( }> {homePage} - } - /> + } /> } diff --git a/packages/catalog-model/examples/components/different-namespace.yaml b/packages/catalog-model/examples/components/different-namespace.yaml deleted file mode 100644 index 80cae9c1fe..0000000000 --- a/packages/catalog-model/examples/components/different-namespace.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: backstage.io/v1alpha1 -kind: Component -metadata: - name: different-namespace - namespace: alternative - description: Example of a Component in a different namespace -spec: - type: service - lifecycle: experimental - owner: default/team-a From 5612a1ab8fd905f06d36f3dd1faeec3b6f024ee0 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Mon, 4 Mar 2024 11:12:55 +0100 Subject: [PATCH 4/6] Fixed typo Signed-off-by: Andre Wanlin --- .changeset/tricky-flies-destroy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tricky-flies-destroy.md b/.changeset/tricky-flies-destroy.md index c79a4e771c..67f09987f3 100644 --- a/.changeset/tricky-flies-destroy.md +++ b/.changeset/tricky-flies-destroy.md @@ -3,4 +3,4 @@ '@backstage/plugin-catalog': patch --- -Added support for providing an `initiallySelectedNamspaces` which accepts an array of Namespaces to have selected by default +Added support for providing an `initiallySelectedNamespaces` which accepts an array of Namespaces to have selected by default From 29b094820c2fd2efa35c4f5667e51244b8ab3477 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Mon, 4 Mar 2024 16:20:24 +0100 Subject: [PATCH 5/6] Updated DefaultFilters Signed-off-by: Andre Wanlin --- .../src/components/DefaultFilters/DefaultFilters.tsx | 12 ++++++++++-- .../components/CatalogPage/DefaultCatalogPage.tsx | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-react/src/components/DefaultFilters/DefaultFilters.tsx b/plugins/catalog-react/src/components/DefaultFilters/DefaultFilters.tsx index 45625c716f..9992c8d1d2 100644 --- a/plugins/catalog-react/src/components/DefaultFilters/DefaultFilters.tsx +++ b/plugins/catalog-react/src/components/DefaultFilters/DefaultFilters.tsx @@ -37,11 +37,17 @@ export type DefaultFiltersProps = { initialKind?: string; initiallySelectedFilter?: UserListFilterKind; ownerPickerMode?: EntityOwnerPickerProps['mode']; + initiallySelectedNamespaces?: string[]; }; /** @public */ export const DefaultFilters = (props: DefaultFiltersProps) => { - const { initialKind, initiallySelectedFilter, ownerPickerMode } = props; + const { + initialKind, + initiallySelectedFilter, + ownerPickerMode, + initiallySelectedNamespaces, + } = props; return ( <> @@ -51,7 +57,9 @@ export const DefaultFilters = (props: DefaultFiltersProps) => { - + ); }; diff --git a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx index 1b91bddf2a..44e1022042 100644 --- a/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx +++ b/plugins/catalog/src/components/CatalogPage/DefaultCatalogPage.tsx @@ -122,6 +122,7 @@ export function DefaultCatalogPage(props: DefaultCatalogPageProps) { initialKind={initialKind} initiallySelectedFilter={initiallySelectedFilter} ownerPickerMode={ownerPickerMode} + initiallySelectedNamespaces={initiallySelectedNamespaces} /> ) } From 8526fb9d9547f4995b8f1dec7f38d922778b2c76 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Mon, 4 Mar 2024 16:53:17 +0100 Subject: [PATCH 6/6] Updated API Report Signed-off-by: Andre Wanlin --- plugins/catalog-react/api-report.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 11f35fc56d..62a241bda9 100644 --- a/plugins/catalog-react/api-report.md +++ b/plugins/catalog-react/api-report.md @@ -182,6 +182,7 @@ export type DefaultFiltersProps = { initialKind?: string; initiallySelectedFilter?: UserListFilterKind; ownerPickerMode?: EntityOwnerPickerProps['mode']; + initiallySelectedNamespaces?: string[]; }; // @public (undocumented)