adding fields limitation for EntityPicker
Signed-off-by: Ladislav Vitásek <vity@vity.cz>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': minor
|
||||
---
|
||||
|
||||
Scaffolding - EntityPicker component - now it does not load full entity data, only a specified set - defaults to `['metadata.name', 'metadata.namespace', 'metadata.title', 'kind']`. It can significantly reduce loaded time bigger data set. It's possible to set fields to ignore configure via `fieldsToIgnore` in UI options of the EntityPicker component.
|
||||
@@ -61,14 +61,24 @@ export const EntityPicker = (props: EntityPickerProps) => {
|
||||
} = props;
|
||||
const catalogFilter = buildCatalogFilter(uiSchema);
|
||||
const defaultKind = uiSchema['ui:options']?.defaultKind;
|
||||
const fieldsToIgnore = uiSchema['ui:options']?.fieldsToIgnore;
|
||||
const defaultNamespace =
|
||||
uiSchema['ui:options']?.defaultNamespace || undefined;
|
||||
|
||||
const catalogApi = useApi(catalogApiRef);
|
||||
|
||||
const { value: entities, loading } = useAsync(async () => {
|
||||
const defaultFieldsToIgnore = [
|
||||
'metadata.name',
|
||||
'metadata.namespace',
|
||||
'metadata.title',
|
||||
'kind',
|
||||
];
|
||||
const fields = fieldsToIgnore || defaultFieldsToIgnore;
|
||||
const { items } = await catalogApi.getEntities(
|
||||
catalogFilter ? { filter: catalogFilter } : undefined,
|
||||
catalogFilter
|
||||
? { filter: catalogFilter, fields: fields }
|
||||
: { filter: undefined, fields: fields },
|
||||
);
|
||||
return items;
|
||||
});
|
||||
|
||||
@@ -41,6 +41,13 @@ export const EntityPickerFieldSchema = makeFieldSchemaFromZod(
|
||||
.describe(
|
||||
'DEPRECATED: Use `catalogFilter` instead. List of kinds of entities to derive options from',
|
||||
),
|
||||
fieldsToIgnore: z
|
||||
.array(z.string())
|
||||
.optional()
|
||||
.describe(
|
||||
'Fields to ignore from loading - download only the parts of each entity that match the field declarations.' +
|
||||
" Defaults to: fields: ['metadata.name', 'metadata.namespace', 'metadata.title', 'kind']",
|
||||
),
|
||||
defaultKind: z
|
||||
.string()
|
||||
.optional()
|
||||
|
||||
Reference in New Issue
Block a user