Skip to content

Commit

Permalink
fix(pci-object-storage): fix object list search
Browse files Browse the repository at this point in the history
ref: DTCORE-3008
Signed-off-by: LIDRISSI Hamid <[email protected]>
  • Loading branch information
seven-amid committed Jan 24, 2025
1 parent eb8d422 commit 71b72da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useQuery } from '@tanstack/react-query';
import { ColumnSort, PaginationState } from '@ovh-ux/manager-react-components';
import { applyFilters, Filter } from '@ovh-ux/manager-core-api';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { getServerContainer, TObject } from '@/api/data/container';
import { paginateResults, sortResults } from '@/helpers';

Expand Down Expand Up @@ -51,6 +52,8 @@ export const usePaginatedObjects = (
sorting: ColumnSort,
filters: Filter[],
) => {
const { t } = useTranslation('container');

const { data: container, error, isLoading, isPending } = useServerContainer(
projectId,
region,
Expand All @@ -64,7 +67,15 @@ export const usePaginatedObjects = (
isPending,
paginatedObjects: paginateResults<TObject | { index: string }>(
sortResults<TObject>(
applyFilters<TObject>(container?.objects || [], filters),
applyFilters<TObject>(
container?.objects?.map((object) => ({
...object,
search: `${object.key} ${t(
`pci_projects_project_storages_containers_container_storage_class_${object.storageClass}`,
)}`,
})) || [],
filters,
),
sorting,
).map((obj, index) => ({
index,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ export default function ObjectPage() {
filters,
);

const handleSearch = () => {
setPagination({
pageIndex: 0,
pageSize: pagination.pageSize,
});
addFilter({
key: 'search',
value: searchField,
comparator: FilterComparator.Includes,
label: '',
});
setSearchField('');
};

if (!container) {
return <OdsSpinner size="md" />;
}
Expand Down Expand Up @@ -471,37 +485,15 @@ export default function ObjectPage() {
}
onKeyDown={(event) => {
if (event.key === 'Enter') {
setPagination({
pageIndex: 0,
pageSize: pagination.pageSize,
});
addFilter({
key: 'key',
value: searchField,
comparator: FilterComparator.Includes,
label: '',
});
setSearchField('');
handleSearch();
}
}}
/>
<OdsButton
label=""
icon="magnifying-glass"
size="sm"
onClick={() => {
setPagination({
pageIndex: 0,
pageSize: pagination.pageSize,
});
addFilter({
key: 'key',
value: searchField,
comparator: FilterComparator.Includes,
label: '',
});
setSearchField('');
}}
onClick={handleSearch}
/>

<OdsButton
Expand Down

0 comments on commit 71b72da

Please sign in to comment.