diff --git a/.changeset/tricky-flies-destroy.md b/.changeset/tricky-flies-destroy.md new file mode 100644 index 0000000000..67f09987f3 --- /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 `initiallySelectedNamespaces` which accepts an array of Namespaces to have selected by default diff --git a/plugins/catalog-react/api-report.md b/plugins/catalog-react/api-report.md index 20831da43f..dfb5780a2c 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) @@ -343,7 +344,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/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-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..44e1022042 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 ( @@ -120,6 +122,7 @@ export function DefaultCatalogPage(props: DefaultCatalogPageProps) { initialKind={initialKind} initiallySelectedFilter={initiallySelectedFilter} ownerPickerMode={ownerPickerMode} + initiallySelectedNamespaces={initiallySelectedNamespaces} /> ) }