Portal/rsconcept/frontend/src/features/library/pages/LibraryPage/TableLibraryItems.tsx

90 lines
3.1 KiB
TypeScript
Raw Normal View History

2024-06-07 20:17:03 +03:00
'use client';
2025-02-12 21:36:03 +03:00
import clsx from 'clsx';
2024-06-07 20:17:03 +03:00
import { urls, useConceptNavigation } from '@/app';
2025-02-12 21:36:03 +03:00
import { FlexColumn } from '@/components/Container';
2025-03-05 00:57:03 +03:00
import { TextURL } from '@/components/Control';
import { DataTable, type IConditionalStyle, type VisibilityState } from '@/components/DataTable';
2025-02-19 23:29:45 +03:00
import { useWindowSize } from '@/hooks/useWindowSize';
import { useFitHeight } from '@/stores/appLayout';
import { usePreferencesStore } from '@/stores/preferences';
2025-02-11 21:07:06 +03:00
import { APP_COLORS } from '@/styling/colors';
2024-06-07 20:17:03 +03:00
2025-02-20 20:22:05 +03:00
import { type ILibraryItem, LibraryItemType } from '../../backend/types';
import { useLibrarySearchStore } from '../../stores/librarySearch';
2025-03-05 00:57:03 +03:00
import { useLibraryColumns } from './useLibraryColumns';
interface TableLibraryItemsProps {
2024-06-07 20:17:03 +03:00
items: ILibraryItem[];
}
2025-02-19 23:29:45 +03:00
export function TableLibraryItems({ items }: TableLibraryItemsProps) {
2024-06-07 20:17:03 +03:00
const router = useConceptNavigation();
2025-03-05 00:57:03 +03:00
const { isSmall } = useWindowSize();
const folderMode = useLibrarySearchStore(state => state.folderMode);
const resetFilter = useLibrarySearchStore(state => state.resetFilter);
const itemsPerPage = usePreferencesStore(state => state.libraryPagination);
const setItemsPerPage = usePreferencesStore(state => state.setLibraryPagination);
2024-06-07 20:17:03 +03:00
2025-03-05 00:57:03 +03:00
const columns = useLibraryColumns();
const columnVisibility: VisibilityState = { owner: !isSmall };
const conditionalRowStyles: IConditionalStyle<ILibraryItem>[] = [
{
when: (item: ILibraryItem) => item.item_type === LibraryItemType.OSS,
style: {
color: APP_COLORS.fgGreen
}
}
];
const tableHeight = useFitHeight('2.2rem');
2025-02-22 14:03:13 +03:00
function handleOpenItem(item: ILibraryItem, event: React.MouseEvent<Element>) {
const selection = window.getSelection();
if (!!selection && selection.toString().length > 0) {
return;
}
2024-06-07 20:17:03 +03:00
if (item.item_type === LibraryItemType.RSFORM) {
router.push({ path: urls.schema(item.id), newTab: event.ctrlKey || event.metaKey });
2024-06-07 20:17:03 +03:00
} else if (item.item_type === LibraryItemType.OSS) {
router.push({ path: urls.oss(item.id), newTab: event.ctrlKey || event.metaKey });
2024-06-07 20:17:03 +03:00
}
}
return (
<DataTable
id='library_data'
columns={columns}
data={items}
headPosition='0'
2024-12-04 20:07:01 +03:00
className={clsx('text-xs sm:text-sm cc-scroll-y h-fit border-b', { 'border-l': folderMode })}
2024-06-07 20:17:03 +03:00
style={{ maxHeight: tableHeight }}
noDataComponent={
2024-06-21 19:16:41 +03:00
<FlexColumn className='dense p-3 items-center min-h-[6rem]'>
2024-06-07 20:17:03 +03:00
<p>Список схем пуст</p>
<p className='flex gap-6'>
<TextURL text='Создать схему' href='/library/create' />
<TextURL text='Очистить фильтр' onClick={resetFilter} />
2024-06-07 20:17:03 +03:00
</p>
</FlexColumn>
}
columnVisibility={columnVisibility}
onRowClicked={handleOpenItem}
enableSorting
initialSorting={{
id: 'time_update',
desc: true
}}
enablePagination
paginationPerPage={itemsPerPage}
onChangePaginationOption={setItemsPerPage}
paginationOptions={[10, 20, 30, 50, 100]}
conditionalRowStyles={conditionalRowStyles}
/>
);
}