Merge pull request #22863 from awanlin/topic/entity-namespace-picker-defaults

Added `initiallySelectedNamspaces`
This commit is contained in:
Elon Jefferson
2024-03-05 14:14:41 -05:00
committed by GitHub
8 changed files with 65 additions and 5 deletions
+6
View File
@@ -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
+10 -1
View File
@@ -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 {
@@ -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 (
<>
<EntityKindPicker initialFilter={initialKind} />
@@ -51,7 +57,9 @@ export const DefaultFilters = (props: DefaultFiltersProps) => {
<EntityLifecyclePicker />
<EntityTagPicker />
<EntityProcessingStatusPicker />
<EntityNamespacePicker />
<EntityNamespacePicker
initiallySelectedNamespaces={initiallySelectedNamespaces}
/>
</>
);
};
@@ -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 (
@@ -120,6 +122,7 @@ export function DefaultCatalogPage(props: DefaultCatalogPageProps) {
initialKind={initialKind}
initiallySelectedFilter={initiallySelectedFilter}
ownerPickerMode={ownerPickerMode}
initiallySelectedNamespaces={initiallySelectedNamespaces}
/>
)
}