fix(Scaffolder): filter MultiEntityPicker options based on rendered option values
Signed-off-by: Adam Letizia <LetiziaAdam@JohnDeere.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': patch
|
||||
---
|
||||
|
||||
Filter MultiEntityPicker options based on rendered option value
|
||||
@@ -947,4 +947,81 @@ describe('<MultiEntityPicker />', () => {
|
||||
expect(getByText(description.fromUiSchema)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('entity presentation', () => {
|
||||
beforeEach(() => {
|
||||
uiSchema = {
|
||||
'ui:options': {
|
||||
defaultKind: 'Group',
|
||||
},
|
||||
};
|
||||
props = {
|
||||
onChange,
|
||||
schema,
|
||||
required,
|
||||
uiSchema,
|
||||
rawErrors,
|
||||
formData,
|
||||
} as unknown as FieldProps<any>;
|
||||
});
|
||||
|
||||
it('renders and filters selection displayName', async () => {
|
||||
catalogApi.getEntities.mockResolvedValue({
|
||||
items: entities.map(item => ({
|
||||
...item,
|
||||
spec: {
|
||||
profile: { displayName: item.metadata.name.replace('-', ' ') },
|
||||
},
|
||||
})),
|
||||
});
|
||||
|
||||
const { getByRole, getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<MultiEntityPicker {...props} />
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
const input = getByRole('textbox');
|
||||
|
||||
fireEvent.change(input, { target: { value: 'team a' } });
|
||||
|
||||
expect(getByText('team a')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(input, { target: { value: 'squad b' } });
|
||||
|
||||
expect(getByText('squad b')).toBeInTheDocument();
|
||||
|
||||
fireEvent.blur(input);
|
||||
});
|
||||
|
||||
it('renders and filters selection title', async () => {
|
||||
catalogApi.getEntities.mockResolvedValue({
|
||||
items: entities.map(item => ({
|
||||
...item,
|
||||
metadata: {
|
||||
...item.metadata,
|
||||
title: item.metadata.name.replace('-', ' ').toUpperCase(),
|
||||
},
|
||||
})),
|
||||
});
|
||||
|
||||
const { getByRole, getByText } = await renderInTestApp(
|
||||
<Wrapper>
|
||||
<MultiEntityPicker {...props} />
|
||||
</Wrapper>,
|
||||
);
|
||||
|
||||
const input = getByRole('textbox');
|
||||
|
||||
fireEvent.change(input, { target: { value: 'team a' } });
|
||||
|
||||
expect(getByText('TEAM A')).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(input, { target: { value: 'squad b' } });
|
||||
|
||||
expect(getByText('SQUAD B')).toBeInTheDocument();
|
||||
|
||||
fireEvent.blur(input);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
import TextField from '@material-ui/core/TextField';
|
||||
import Autocomplete, {
|
||||
AutocompleteChangeReason,
|
||||
createFilterOptions,
|
||||
} from '@material-ui/lab/Autocomplete';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import useAsync from 'react-use/esm/useAsync';
|
||||
@@ -203,6 +204,11 @@ export const MultiEntityPicker = (props: MultiEntityPickerProps) => {
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
filterOptions={createFilterOptions<Entity>({
|
||||
stringify: option =>
|
||||
entities?.entityRefToPresentation.get(stringifyEntityRef(option))
|
||||
?.primaryTitle!,
|
||||
})}
|
||||
ListboxComponent={VirtualizedListbox}
|
||||
/>
|
||||
</ScaffolderField>
|
||||
|
||||
Reference in New Issue
Block a user