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

[BD-46] fix: replace filter names with header names #2757

Merged
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
8 changes: 6 additions & 2 deletions src/DataTable/FilterStatus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import Button from '../Button';
function FilterStatus({
className, variant, size, clearFiltersText, buttonClassName, showFilteredFields,
}) {
const { state, setAllFilters } = useContext(DataTableContext);
const { state, setAllFilters, headers } = useContext(DataTableContext);
if (!setAllFilters) {
return null;
}

const filterNames = state.filters ? state.filters.map((filter) => filter.id) : [];
const headersMap = headers.reduce((cur, acc) => {
cur[acc.id] = acc.Header;
return cur;
}, {});
const filterNames = state.filters ? state.filters.map((filter) => headersMap[filter.id]) : [];
const filterTexts = <p>Filtered by {filterNames.join(', ')}</p>;

return (
Expand Down
3 changes: 2 additions & 1 deletion src/DataTable/tests/FilterStatus.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import FilterStatus from '../FilterStatus';
import DataTableContext from '../DataTableContext';

const filterNames = ['color', 'breed', 'discipline'];
const headers = [{ id: 'color', Header: 'color' }, { id: 'breed', Header: 'breed' }, { id: 'discipline', Header: 'discipline' }];
const filters = filterNames.map((name) => ({ id: name }));
const instance = { state: { filters }, setAllFilters: () => {} };
const instance = { state: { filters }, setAllFilters: () => {}, headers };
const filterProps = {
buttonClassName: 'buttonClass',
variant: 'variant',
Expand Down
2 changes: 2 additions & 0 deletions src/DataTable/tests/SmartStatus.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import RowStatus from '../RowStatus';
import SelectionStatus from '../selection/SelectionStatus';

const filters = [{ id: 'name' }, { id: 'age' }];
const headers = [{ id: 'name', Header: 'name' }, { id: 'age', Header: 'age' }];
const filterNames = ['name', 'age'];
const itemCount = 101;
const instance = {
Expand All @@ -22,6 +23,7 @@ const instance = {
SelectionStatusComponent: SelectionStatus,
FilterStatusComponent: FilterStatus,
RowStatusComponent: RowStatus,
headers,
};

// eslint-disable-next-line react/prop-types
Expand Down
Loading