Skip to content

Commit

Permalink
fix(TMC-26027/facetedSearch): multiple callbacks for BadgeCheckbox (#…
Browse files Browse the repository at this point in the history
…5250)

* fix(TMC-26027/facetedSearch): multiple callbacks for BadgeCheckbox

* fix(TMC-26027/facetedSearch): fix tests

* fix(TMC-26027/facetedSearch): fix tests

* fix(TMC-26027/facetedSearch): update changeset
  • Loading branch information
ybaskaran authored Apr 2, 2024
1 parent 8729ba7 commit 27a4a5d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
26 changes: 26 additions & 0 deletions .changeset/dry-wolves-explode.md
Original file line number Diff line number Diff line change
@@ -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
<FacetedSearch.BasicSearch
callbacks={{ getTags: () => {} }}
/>
```
---
- After:
```jsx
<FacetedSearch.BasicSearch
callbacks={{
tags: { getOptions: () => {} },
authors: { getOptions: () => {} },
operators: { getOptions: () => {} },
}}
/>
```
---
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { getTimezones } from './TimezoneList.utils';

describe('getTimezones', () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
});
const cldrTimezones = {
en: {
main: {
Expand Down Expand Up @@ -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',
},
Expand Down

0 comments on commit 27a4a5d

Please sign in to comment.