diff --git a/.changeset/dry-wolves-explode.md b/.changeset/dry-wolves-explode.md new file mode 100644 index 00000000000..b3f6134226a --- /dev/null +++ b/.changeset/dry-wolves-explode.md @@ -0,0 +1,26 @@ +--- +"@talend/react-faceted-search": major +--- + +### BREAKING CHANGE +fix(TMC-26027/facetedSearch): multiple callbacks for BadgeCheckbox +- getTags() was replaced with getOptions() to support multiple callbacks +--- +- Before: +```jsx + {} }} +/> +``` +--- +- After: +```jsx + {} }, + authors: { getOptions: () => {} }, + operators: { getOptions: () => {} }, + }} +/> +``` +--- diff --git a/packages/faceted-search/src/components/Badges/BadgeCheckboxes/BadgeCheckboxes.component.js b/packages/faceted-search/src/components/Badges/BadgeCheckboxes/BadgeCheckboxes.component.js index 0f340b13267..321bc696725 100644 --- a/packages/faceted-search/src/components/Badges/BadgeCheckboxes/BadgeCheckboxes.component.js +++ b/packages/faceted-search/src/components/Badges/BadgeCheckboxes/BadgeCheckboxes.component.js @@ -53,16 +53,17 @@ export const BadgeCheckboxes = ({ }) => { const [options, setOptions] = useState(values || []); const [isLoading, setIsLoading] = useState(true); + const callback = callbacks && callbacks[rest.attribute]; useEffect(() => { - if (values?.length || !callbacks || !callbacks.getTags) { + if (values?.length || !callback || !callback.getOptions) { setIsLoading(false); return; } setIsLoading(true); - callbacks - .getTags() + callback + .getOptions() .then(data => { setOptions( data.map(item => { diff --git a/packages/faceted-search/src/components/Badges/BadgeCheckboxes/BadgeCheckboxes.component.test.js b/packages/faceted-search/src/components/Badges/BadgeCheckboxes/BadgeCheckboxes.component.test.js index bb574499cda..262518cf264 100644 --- a/packages/faceted-search/src/components/Badges/BadgeCheckboxes/BadgeCheckboxes.component.test.js +++ b/packages/faceted-search/src/components/Badges/BadgeCheckboxes/BadgeCheckboxes.component.test.js @@ -108,7 +108,9 @@ describe('BadgeCheckboxes', () => { it('should mount a badge with object data from callback', async () => { // Given const callbacks = { - getTags: () => new Promise(resolve => resolve([{ id: '1234', label: 'production' }])), + id: { + getOptions: () => new Promise(resolve => resolve([{ id: '1234', label: 'production' }])), + }, }; const props = { diff --git a/packages/forms/src/UIForm/fields/Date/DateTime.component.test.js b/packages/forms/src/UIForm/fields/Date/DateTime.component.test.js index 1d666e8cdf8..2f3a356959c 100644 --- a/packages/forms/src/UIForm/fields/Date/DateTime.component.test.js +++ b/packages/forms/src/UIForm/fields/Date/DateTime.component.test.js @@ -122,7 +122,7 @@ describe('DateTime widget', () => { expect(props.onChange.mock.calls[1][1]).toMatchObject({ schema: timestampSchema, - value: new Date(2015, 8, 21, 1, 30, 0).getTime(), + value: new Date(2015, 8, 21, 0, 30, 0).getTime(), }); }); diff --git a/packages/forms/src/UIForm/fields/TimezoneList/TimezoneList.utils.test.js b/packages/forms/src/UIForm/fields/TimezoneList/TimezoneList.utils.test.js index 129e7a8e99c..0a3a49a2fd1 100644 --- a/packages/forms/src/UIForm/fields/TimezoneList/TimezoneList.utils.test.js +++ b/packages/forms/src/UIForm/fields/TimezoneList/TimezoneList.utils.test.js @@ -1,6 +1,12 @@ import { getTimezones } from './TimezoneList.utils'; describe('getTimezones', () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + afterEach(() => { + jest.useRealTimers(); + }); const cldrTimezones = { en: { main: { @@ -89,8 +95,8 @@ describe('getTimezones', () => { value: 'Africa/Freetown', }, { - name: '(UTC +01:00) Europe/Berlin', - offset: 60, + name: '(UTC +02:00) Europe/Berlin', + offset: 120, timezoneName: 'Europe/Berlin', value: 'Europe/Berlin', },