From 298953b12a429dbab1fd5728eb56311aaf639d58 Mon Sep 17 00:00:00 2001 From: Andre Wanlin Date: Sat, 10 Feb 2024 15:51:50 -0600 Subject: [PATCH] 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 (