Skip to content

Commit 9a9bcbc

Browse files
committed
Align filter param names with existing
1 parent 5155a57 commit 9a9bcbc

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

frontend/public/components/data-view-poc/DataViewPodList.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ import { ColumnsIcon } from '@patternfly/react-icons';
6868
import { createColumnManagementModal } from '../modals';
6969
import { useActiveColumns } from '../factory/Table/active-columns-hook';
7070
import { PodModel } from '../../models';
71+
import { useExactSearch } from '@console/app/src/components/user-preferences/search/useExactSearch';
72+
import { exactMatch, fuzzyCaseInsensitive } from '../factory/table-filters';
7173

7274
/**
7375
* Copy paste section
@@ -665,9 +667,10 @@ const DataViewPodList = ({
665667
const { t } = useTranslation();
666668

667669
const [searchParams, setSearchParams] = useSearchParams();
670+
const [isExactSearch] = useExactSearch();
668671

669672
const { filters, onSetFilters, clearAllFilters } = useDataViewFilters({
670-
initialFilters: { status: [], name: '', label: '' },
673+
initialFilters: { status: [], name: '', labels: '' },
671674
searchParams,
672675
setSearchParams,
673676
});
@@ -687,11 +690,12 @@ const DataViewPodList = ({
687690
[],
688691
);
689692

690-
// TODO: account for filter user preference in name filter
691693
const filteredData = React.useMemo(
692694
() =>
693695
data.filter((item) => {
694-
const filterLabelArray = filters.label !== '' ? filters.label.split(',') : [];
696+
const nameFilter = filters.name;
697+
const podName = item.metadata.name;
698+
const filterLabelArray = filters.labels !== '' ? filters.labels.split(',') : [];
695699
const itemLabels = getLabelsAsString(item);
696700

697701
return (
@@ -702,12 +706,13 @@ const DataViewPodList = ({
702706
filterOptions.find((option) => option.value === podPhaseFilterReducer(item))?.value,
703707
),
704708
)) &&
705-
(!filters.name ||
706-
item.metadata.name?.toLocaleLowerCase().includes(filters.name?.toLocaleLowerCase())) &&
707-
(!filters.label || filterLabelArray.every((label) => itemLabels.includes(label)))
709+
(!filters.name || isExactSearch
710+
? exactMatch(nameFilter, podName)
711+
: fuzzyCaseInsensitive(nameFilter, podName)) &&
712+
(!filters.labels || filterLabelArray.every((label) => itemLabels.includes(label)))
708713
);
709714
}),
710-
[data, filters.label, filters.name, filters.status, filterOptions],
715+
[data, filters.name, filters.labels, filters.status, filterOptions, isExactSearch],
711716
);
712717

713718
const { dataViewColumns, dataViewRows, pagination } = useDataViewData({
@@ -747,13 +752,13 @@ const DataViewPodList = ({
747752
return [
748753
<DataViewCheckboxFilter
749754
key="status"
750-
filterId="status"
755+
filterId="status" // is `rowFilter-pod-status`in <FilterToolbar> as a single param, not multiple
751756
title={t('public~Status')}
752757
placeholder={t('public~Filter by status')}
753758
options={filterOptions}
754759
/>,
755760
<DataViewTextFilter key="name" filterId="name" title={t('public~Name')} />,
756-
<DataViewLabelFilter key="label" filterId="label" title={t('public~Label')} data={data} />,
761+
<DataViewLabelFilter key="labels" filterId="label" title={t('public~Label')} data={data} />,
757762
];
758763
// can't use data in the deps array is will re-compute the filters and will cause the selected category to reset
759764
// eslint-disable-next-line react-hooks/exhaustive-deps

0 commit comments

Comments
 (0)