@@ -2,4 +2,4 @@
|
||||
'@backstage/plugin-catalog-react': minor
|
||||
---
|
||||
|
||||
Added sorted prop in EntityTypePicker
|
||||
Sort EntityTypePicker by default
|
||||
|
||||
@@ -189,34 +189,4 @@ describe('<EntityTypePicker/>', () => {
|
||||
type: new EntityTypeFilter(['tool']),
|
||||
});
|
||||
});
|
||||
|
||||
it('sorts the available entity types when sorted prop is true', async () => {
|
||||
await renderInTestApp(
|
||||
<ApiProvider apis={apis}>
|
||||
<MockEntityListContextProvider
|
||||
value={{ filters: { kind: new EntityKindFilter('component') } }}
|
||||
>
|
||||
<EntityTypePicker sorted />
|
||||
</MockEntityListContextProvider>
|
||||
</ApiProvider>,
|
||||
);
|
||||
expect(screen.getByText('Type')).toBeInTheDocument();
|
||||
|
||||
const input = screen.getByTestId('select');
|
||||
fireEvent.mouseDown(within(input).getByRole('button'));
|
||||
|
||||
await waitFor(() => screen.getByText('library'));
|
||||
|
||||
const sortedEntities = entities
|
||||
.map(e => e.spec!.type as string)
|
||||
.sort((a, b) =>
|
||||
a
|
||||
.toLocaleLowerCase('en-US')
|
||||
.localeCompare(b.toLocaleLowerCase('en-US')),
|
||||
);
|
||||
|
||||
sortedEntities.forEach(entityType => {
|
||||
expect(screen.getByText(entityType)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,12 +31,11 @@ import { useTranslationRef } from '@backstage/core-plugin-api/alpha';
|
||||
export interface EntityTypePickerProps {
|
||||
initialFilter?: string;
|
||||
hidden?: boolean;
|
||||
sorted?: boolean;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export const EntityTypePicker = (props: EntityTypePickerProps) => {
|
||||
const { hidden, initialFilter, sorted } = props;
|
||||
const { hidden, initialFilter } = props;
|
||||
const alertApi = useApi(alertApiRef);
|
||||
const { error, availableTypes, selectedTypes, setSelectedTypes } =
|
||||
useEntityTypeFilter();
|
||||
@@ -55,11 +54,11 @@ export const EntityTypePicker = (props: EntityTypePickerProps) => {
|
||||
}, [error, alertApi, initialFilter, setSelectedTypes, t]);
|
||||
|
||||
if (availableTypes.length === 0 || error) return null;
|
||||
if (sorted) {
|
||||
availableTypes.sort((a, b) =>
|
||||
a.toLocaleLowerCase('en-US').localeCompare(b.toLocaleLowerCase('en-US')),
|
||||
);
|
||||
}
|
||||
|
||||
availableTypes.sort((a, b) =>
|
||||
a.toLocaleLowerCase('en-US').localeCompare(b.toLocaleLowerCase('en-US')),
|
||||
);
|
||||
|
||||
const items = [
|
||||
{ value: 'all', label: t('entityTypePicker.optionAllTitle') },
|
||||
...availableTypes.map((type: string) => ({
|
||||
|
||||
Reference in New Issue
Block a user