Skip to content

Commit

Permalink
feat(custom): remove searchFields prop from OnDropdownInputChangeProps
Browse files Browse the repository at this point in the history
J=BACK-2765
TEST=manual
  • Loading branch information
Jeffrey-Rhoads17 committed Jan 24, 2024
1 parent f2c2b8f commit d177678
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 24 deletions.
1 change: 0 additions & 1 deletion docs/search-ui-react.ondropdowninputchangeprops.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ interface OnDropdownInputChangeProps
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [executeFilterSearch](./search-ui-react.ondropdowninputchangeprops.executefiltersearch.md) | | (query?: string) => Promise<FilterSearchResponse \| undefined> | A function that executes a filter search and updates the input and dropdown options with the response. |
| [searchFields](./search-ui-react.ondropdowninputchangeprops.searchfields.md) | | Omit<SearchParameterField, 'fetchEntities'>\[\] | |
| [value](./search-ui-react.ondropdowninputchangeprops.value.md) | | string | The input element's new value after the change |

11 changes: 0 additions & 11 deletions docs/search-ui-react.ondropdowninputchangeprops.searchfields.md

This file was deleted.

2 changes: 0 additions & 2 deletions etc/search-ui-react.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,6 @@ export type OnDragHandler = (center: mapboxgl_2.LngLat, bounds: mapboxgl_2.LngLa
// @public
export interface OnDropdownInputChangeProps {
executeFilterSearch: (query?: string) => Promise<FilterSearchResponse | undefined>;
// (undocumented)
searchFields: Omit<SearchParameterField, 'fetchEntities'>[];
value: string;
}

Expand Down
2 changes: 0 additions & 2 deletions src/components/FilterSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export interface OnSelectParams {
export interface OnDropdownInputChangeProps {
/** The input element's new value after the change */
value: string,
searchFields: Omit<SearchParameterField, 'fetchEntities'>[],
/**
* A function that executes a filter search and updates the input and dropdown options
* with the response.
Expand Down Expand Up @@ -246,7 +245,6 @@ export function FilterSearch({
const handleInputChange = useCallback((value) => {
onDropdownInputChange ? onDropdownInputChange({
value,
searchFields,
executeFilterSearch
}) : executeFilterSearch(value);
}, [
Expand Down
8 changes: 4 additions & 4 deletions test-site/src/pages/PeoplePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export function PeoplePage() {
* This is especially useful for implementations that have multiple FilterSearch components.
* Ex. a user can search using both inputs initially, but then wants to clear one of the FilterSearch inputs and re-run a search.
*/
const removeAssociatedFilterWhenInputIsEmpty = (params: OnDropdownInputChangeProps) => {
const { value, searchFields, executeFilterSearch } = params;
const removeAssociatedFilterWhenInputIsEmpty = (searchFields: { fieldApiName: string; entityType: string; }[]) => (params: OnDropdownInputChangeProps) => {
const { value, executeFilterSearch } = params;
// If there is still an input value, execute the filter search as normal
if (value !== "") {
executeFilterSearch(value);
Expand Down Expand Up @@ -79,13 +79,13 @@ export function PeoplePage() {
searchFields={filterSearchFields}
searchOnSelect={true}
label='FilterSearch Name Filter'
onDropdownInputChange={removeAssociatedFilterWhenInputIsEmpty}
onDropdownInputChange={removeAssociatedFilterWhenInputIsEmpty(filterSearchFields)}
/>
<FilterSearch
searchFields={employeeFilterSearchFields}
searchOnSelect={true}
label='FilterSearch Department Filter'
onDropdownInputChange={removeAssociatedFilterWhenInputIsEmpty}
onDropdownInputChange={removeAssociatedFilterWhenInputIsEmpty(employeeFilterSearchFields)}
/>
<FilterDivider />
<StaticFilters
Expand Down
2 changes: 1 addition & 1 deletion tests/components/FilterSearch.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default meta;
export const Primary: StoryFn<FilterSearchProps> = (args) => {
return (
<SearchHeadlessContext.Provider value={generateMockedHeadless(mockedHeadlessState)}>
<FilterSearch {...args} searchFields={searchFields} />
<FilterSearch {...args} searchFields={searchFields} onDropdownInputChange={undefined} />
</SearchHeadlessContext.Provider>
);
};
Expand Down
5 changes: 2 additions & 3 deletions tests/components/FilterSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -672,12 +672,11 @@ describe('search without section labels', () => {
it('when an onDropdownInputChange prop is specified, it gets called each time after the input changes and executeFilterSearch does not', async () => {
const mockedOnDropdownInputChange = jest.fn();
const executeFilterSearch = jest
.spyOn(SearchHeadless.prototype, 'executeFilterSearch')
.mockResolvedValue(unlabeledFilterSearchResponse);
.spyOn(SearchHeadless.prototype, 'executeFilterSearch');
renderFilterSearch({ searchFields: searchFieldsProp, onDropdownInputChange: mockedOnDropdownInputChange});
userEvent.type(screen.getByRole('textbox'), 'a');
await waitFor(() => expect(mockedOnDropdownInputChange).toHaveBeenCalledTimes(1));
await waitFor(() => expect(executeFilterSearch).toHaveBeenCalledTimes(0));
() => expect(executeFilterSearch).toHaveBeenCalledTimes(0);
})
});

Expand Down

0 comments on commit d177678

Please sign in to comment.