Added initiallySelectedNamspaces

Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
Andre Wanlin
2024-02-10 15:51:50 -06:00
parent 7fd1b75fce
commit 298953b12a
9 changed files with 67 additions and 4 deletions
+6
View File
@@ -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
+4 -1
View File
@@ -161,7 +161,10 @@ const routes = (
<Route path="/home" element={<HomepageCompositionRoot />}>
{homePage}
</Route>
<Route path="/catalog" element={<CatalogIndexPage />} />
<Route
path="/catalog"
element={<CatalogIndexPage initiallySelectedNamespaces={['default']} />}
/>
<Route
path="/catalog/:namespace/:kind/:name"
element={<CatalogEntityPage />}
@@ -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
+9 -1
View File
@@ -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 {
@@ -240,4 +240,25 @@ describe('<EntityNamespacePicker/>', () => {
expect(screen.queryByText('Namespace')).not.toBeInTheDocument(),
);
});
it('renders initially selected namespaces', async () => {
render(
<TestApiProvider apis={[[catalogApiRef, mockCatalogApiRef]]}>
<MockEntityListContextProvider value={{}}>
<EntityNamespacePicker
initiallySelectedNamespaces={['namespace-2', 'namespace-3']}
/>
</MockEntityListContextProvider>
</TestApiProvider>,
);
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']);
});
});
@@ -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 (
<EntityAutocompletePicker
@@ -42,6 +52,7 @@ export const EntityNamespacePicker = () => {
path="metadata.namespace"
Filter={EntityNamespaceFilter}
InputProps={{ className: classes.input }}
initialSelectedOptions={initiallySelectedNamespaces}
/>
);
};
@@ -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';
+2
View File
@@ -239,6 +239,8 @@ export interface DefaultCatalogPageProps {
// (undocumented)
initiallySelectedFilter?: UserListFilterKind;
// (undocumented)
initiallySelectedNamespaces?: string[];
// (undocumented)
ownerPickerMode?: EntityOwnerPickerProps['mode'];
// (undocumented)
pagination?:
@@ -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 (