Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FilterBar): correct callback values for onFiltersDialogSelectionChange #6724

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions packages/main/src/components/FilterBar/FilterBar.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,65 @@ describe('FilterBar.cy.tsx', () => {
});
});

it('select-all without required', () => {
const TestComp = (props) => {
const [selectedFilters, setSelectedFilters] = useState('');
const [savedVisibleFilters, setSavedVisibleFilters] = useState('');

const handleSelectionChange: FilterBarPropTypes['onFiltersDialogSelectionChange'] = (e) => {
setSelectedFilters(Array.from(e.selectedFilterKeys).join(' '));
};
const handleSave: FilterBarPropTypes['onFiltersDialogSave'] = (e) => {
setSavedVisibleFilters(e.detail.selectedFilterKeys.join(' '));
};
return (
<>
<FilterBar {...props} onFiltersDialogSelectionChange={handleSelectionChange} onFiltersDialogSave={handleSave}>
<FilterGroupItem label="INPUT" filterKey="0">
<Input placeholder="Placeholder" value="123123" data-testid="INPUT" />
</FilterGroupItem>
<FilterGroupItem label="SWITCH" filterKey="1">
<Switch checked={true} data-testid="SWITCH" />
</FilterGroupItem>
<FilterGroupItem label="SELECT" filterKey="2">
<Select data-testid="SELECT">
<Option selected={true}>Option 1</Option>
<Option>Option 2</Option>
<Option>Option 3</Option>
<Option>Option 4</Option>
</Select>
</FilterGroupItem>
</FilterBar>
<hr />
<span>Selected: </span>
<span data-testid="selected">{selectedFilters}</span>
<br />
<span>Saved: </span>
<span data-testid="saved">{savedVisibleFilters}</span>
</>
);
};

cy.mount(<TestComp />);

cy.findByTestId('selected', '0 1 2');
cy.get('[text="Filters"]').click({ force: true });
cy.get('[ui5-checkbox]').first().click();
cy.findByTestId('selected', '');
cy.get('[ui5-checkbox]').eq(1).click();
cy.findByTestId('selected', '0');
cy.get('[ui5-checkbox]').first().click();
cy.get('[ui5-checkbox]').first().click();

cy.findByText('OK').click();
cy.findByTestId('saved', '');

cy.get('[text="Filters"]').click({ force: true });
cy.get('[ui5-checkbox]').first().click();
cy.findByText('OK').click();
cy.findByTestId('saved', '0 1 2');
});

// todo selection, group + list view
it('Dialog search', () => {
cy.mount(
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/components/FilterBar/FilterDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
};

useEffect(() => {
if (selectedFilters?.length) {
if (selectedFilters) {
selectionChangePayloadRef.current = { selectedFilterKeys: selectedFilters };
}
}, [selectedFilters]);
Expand Down
Loading