Skip to content

Commit

Permalink
fixed revisions table
Browse files Browse the repository at this point in the history
  • Loading branch information
aazaliyaa committed Sep 20, 2024
1 parent cc6ba64 commit f083b55
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
4 changes: 2 additions & 2 deletions web/src/api/hooks/revisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export function revisionsFetcher(
field: keyof Revision;
direction: SortingDirection;
} = {
field: 'name',
field: 'revision',
direction: SortingDirection.ASC
},
filters: FilterWithDocumentExtraOption<keyof Revision>[] = []
): Promise<PagedResponse<Revision>> {
if (searchText) {
filters.push({
field: 'name',
field: 'revision',
operator: Operators.ILIKE,
value: `%${searchText.trim().toLowerCase()}%`
});
Expand Down
3 changes: 2 additions & 1 deletion web/src/api/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export type Dataset = {
};

export type Revision = {
name: string;
revision: string;
date: string;
id: string | number;
};

export type Preprocessor = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import React from 'react';

export const revisionsColumns: DataColumnProps<Revision>[] = [
{
key: 'name',
key: 'revision',
caption: 'REVISION ID',
render: (file) => <Text>{file.name}</Text>,
render: (file) => <Text>{file.revision}</Text>,
grow: 1,
minWidth: 100,
isSortable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { revisionPropFetcher, useRevisions } from 'api/hooks/revisions';
import styles from './revisions-table-connector.module.scss';

type RevisionsTableConnectorProps = {
onRowClick: (id: number) => void;
onRevisionSelect?: (revision: number[]) => void;
onRowClick: (id: number | string) => void;
onRevisionSelect?: (revision: number[] | string[]) => void;
checkedValues?: number[] | string[];
};
const size = pageSizes._100;
Expand All @@ -34,7 +34,7 @@ export const RevisionsTableConnector: FC<RevisionsTableConnectorProps> = ({
onRevisionSelect,
checkedValues
}) => {
const [selectedRevisions, setSelectedRevisions] = useState<number[] | []>([]);
const [selectedRevisions, setSelectedRevisions] = useState<number[] | string[] | []>([]);
const {
pageConfig,
onPageChange,
Expand Down Expand Up @@ -102,9 +102,25 @@ export const RevisionsTableConnector: FC<RevisionsTableConnectorProps> = ({
refetch();
}, [filters]);

const transformedData = useMemo(() => {
return (
data?.data &&
data.data
.map((revision) => {
return [
{
...revision,
id: revision.revision
}
];
})
.flat()
);
}, [data?.data]);

const { dataSource } = useAsyncSourceTable<Revision, number>(
isFetching,
data?.data ?? [],
transformedData ?? [],
page,
pageSize,
searchText,
Expand Down Expand Up @@ -146,34 +162,34 @@ export const RevisionsTableConnector: FC<RevisionsTableConnectorProps> = ({
const loadRevisionsNames = createPagingCachedLoader<string, string>(
namesCache,
async (pageNumber, pageSize, keyword) =>
await revisionPropFetcher('name', pageNumber, pageSize, keyword)
await revisionPropFetcher('revision', pageNumber, pageSize, keyword)
);

const revisionNames = useLazyDataSource<string, string, unknown>(
{
api: loadRevisionsNames,
getId: (name) => name
getId: (revision) => revision
},
[]
);

const renderNameFilter = useColumnPickerFilter<string, string, unknown, 'name'>(
const renderNameFilter = useColumnPickerFilter<string, string, unknown, 'revision'>(
revisionNames,
'name',
'revision',
{ showSearch: true }
);

const renderCreationDateFilter = useDateRangeFilter('date');

const columns = useMemo(() => {
const nameColumn = revisionsColumns.find(({ key }) => key === 'name');
const nameColumn = revisionsColumns.find(({ key }) => key === 'revision');
nameColumn!.renderFilter = renderNameFilter;

const createdDateColumn = revisionsColumns.find(({ key }) => key === 'date');
createdDateColumn!.renderFilter = renderCreationDateFilter;

return revisionsColumns;
}, [revisionsColumns, renderNameFilter]);
}, [revisionsColumns, renderNameFilter, renderCreationDateFilter]);

return (
<div className={styles.wrapper}>
Expand Down

0 comments on commit f083b55

Please sign in to comment.