Skip to content

Commit

Permalink
Merge pull request #1648 from SanjalKatiyar/clients_list_name_filter
Browse files Browse the repository at this point in the history
Bug 2317212: Fix Clients' list page filtering
  • Loading branch information
openshift-merge-bot[bot] authored Nov 6, 2024
2 parents fef4a2f + 1ca1ecf commit cec4962
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/odf/components/storage-consumers/client-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
clientHeartBeatFilter,
getMajorMinorVersion,
versionMismatchFilter,
storageConsumerNameFilter,
} from './list-filter';
import { ClientOnBoardingModal } from './onboarding-modal';
import { RotateKeysModal } from './rotate-keys-modal';
Expand Down Expand Up @@ -424,14 +425,23 @@ export const ClientListPage: React.FC<ClientListPageProps> = () => {
});
const serviceVersion = getOprVersionFromCSV(csv);

const rowFilters = React.useMemo(
() => [clientHeartBeatFilter(t), versionMismatchFilter(t, serviceVersion)],
[t, serviceVersion]
);
// "rowFilters":
// - custom filters (new) that we are introducing to the list page
// - passing to both "useListPageFilter" hook & "ListPageFilter" component
// "rowFiltersWithNameOverride":
// - needed for overriding the filtering (default) on the CR's "name" (need to read the name from the CR's status instead)
// - only passing to "useListPageFilter" hook & not "ListPageFilter" component
const [rowFilters, rowFiltersWithNameOverride] = React.useMemo(() => {
const customFilters = [
clientHeartBeatFilter(t),
versionMismatchFilter(t, serviceVersion),
];
return [customFilters, [storageConsumerNameFilter(), ...customFilters]];
}, [t, serviceVersion]);

const [data, filteredData, onFilterChange] = useListPageFilter(
storageClients,
rowFilters
rowFiltersWithNameOverride
);

const launchModalOnClick = (modalComponent: ModalComponent) => () => {
Expand Down
15 changes: 15 additions & 0 deletions packages/odf/components/storage-consumers/list-filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getTimeDifferenceInSeconds } from '@odf/shared/details-page/datetime';
import { StorageConsumerKind } from '@odf/shared/types';
import { fuzzyCaseInsensitive } from '@odf/shared/utils';
import { RowFilter } from '@openshift-console/dynamic-plugin-sdk';
import * as _ from 'lodash-es';

Expand Down Expand Up @@ -75,3 +76,17 @@ export const versionMismatchFilter = (
);
},
});

// overrides default "name" search filter
export const storageConsumerNameFilter =
(): RowFilter<StorageConsumerKind> => ({
type: 'name',
filterGroupName: '',
reducer: () => undefined,
items: [],
filter: (filterValue, storageConsumer) =>
fuzzyCaseInsensitive(
filterValue.selected?.[0],
storageConsumer?.status?.client?.name || ''
),
});
4 changes: 4 additions & 0 deletions packages/shared/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '@openshift-console/dynamic-plugin-sdk';
import { K8sResourceCommon } from '@openshift-console/dynamic-plugin-sdk-internal/lib/extensions/console-types';
import { K8sKind } from '@openshift-console/dynamic-plugin-sdk/lib/api/common-types';
import * as fuzzy from 'fuzzysearch';
import * as _ from 'lodash-es';
import { GetAPIVersionForModel } from '../types';

Expand Down Expand Up @@ -184,3 +185,6 @@ export const numberInputOnChange =
else if (!!max && inputValue > max) onChange(max);
else onChange(inputValue);
};

export const fuzzyCaseInsensitive = (a: string, b: string): boolean =>
fuzzy(_.toLower(a), _.toLower(b));

0 comments on commit cec4962

Please sign in to comment.