Autocomplete picker: add argument for which filters should be applied when fetching/counting available values
Signed-off-by: Patrik Ivarsson <patrik.ivarsson@avanza.se>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-react': patch
|
||||
---
|
||||
|
||||
Adds an argument for which filters should be applied when fetching/counting available values
|
||||
@@ -204,6 +204,7 @@ export type EntityAutocompletePickerProps<
|
||||
};
|
||||
InputProps?: TextFieldProps;
|
||||
initialSelectedOptions?: string[];
|
||||
filtersForAvailableValues?: Array<keyof T>;
|
||||
};
|
||||
|
||||
// @public
|
||||
|
||||
+13
-2
@@ -50,6 +50,7 @@ export type EntityAutocompletePickerProps<
|
||||
Filter: { new (values: string[]): NonNullable<T[Name]> };
|
||||
InputProps?: TextFieldProps;
|
||||
initialSelectedOptions?: string[];
|
||||
filtersForAvailableValues?: Array<keyof T>;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
@@ -76,6 +77,7 @@ export function EntityAutocompletePicker<
|
||||
Filter,
|
||||
InputProps,
|
||||
initialSelectedOptions = [],
|
||||
filtersForAvailableValues = ['kind'],
|
||||
} = props;
|
||||
|
||||
const classes = useStyles();
|
||||
@@ -87,17 +89,26 @@ export function EntityAutocompletePicker<
|
||||
} = useEntityList<T>();
|
||||
|
||||
const catalogApi = useApi(catalogApiRef);
|
||||
const availableValuesFilters = filtersForAvailableValues.map(
|
||||
f => filters[f] as EntityFilter | undefined,
|
||||
);
|
||||
const { value: availableValues } = useAsync(async () => {
|
||||
const facet = path;
|
||||
const { facets } = await catalogApi.getEntityFacets({
|
||||
facets: [facet],
|
||||
filter: filters.kind?.getCatalogFilters(),
|
||||
filter: availableValuesFilters
|
||||
.map(f =>
|
||||
f && typeof f.getCatalogFilters === 'function'
|
||||
? f.getCatalogFilters()
|
||||
: {},
|
||||
)
|
||||
.reduce((a, b) => ({ ...a, ...b }), {}),
|
||||
});
|
||||
|
||||
return Object.fromEntries(
|
||||
facets[facet].map(({ value, count }) => [value, count]),
|
||||
);
|
||||
}, [filters.kind]);
|
||||
}, [...availableValuesFilters]);
|
||||
|
||||
const queryParameters = useMemo(
|
||||
() => [queryParameter].flat().filter(Boolean) as string[],
|
||||
|
||||
Reference in New Issue
Block a user