Added initiallySelectedNamspaces
Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
|
||||
+21
@@ -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']);
|
||||
});
|
||||
});
|
||||
|
||||
+12
-1
@@ -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';
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user