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
|
|
|
|
|
2025-02-10 01:32:16 +03:00
|
|
|
|
import { urls, useConceptNavigation } from '@/app';
|
2025-02-12 21:36:03 +03:00
|
|
|
|
|
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';
|
2025-01-14 21:57:32 +03:00
|
|
|
|
import { useFitHeight } from '@/stores/appLayout';
|
2025-01-15 16:06:18 +03:00
|
|
|
|
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';
|
2025-02-10 01:32:16 +03:00
|
|
|
|
import { useLibrarySearchStore } from '../../stores/librarySearch';
|
|
|
|
|
|
2025-03-05 00:57:03 +03:00
|
|
|
|
import { useLibraryColumns } from './useLibraryColumns';
|
|
|
|
|
|
2024-06-26 19:47:05 +03:00
|
|
|
|
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();
|
2025-01-15 16:06:18 +03:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
];
|
2025-03-09 21:57:21 +03:00
|
|
|
|
const tableHeight = useFitHeight('2.25rem');
|
2025-03-05 00:57:03 +03:00
|
|
|
|
|
2025-02-22 14:03:13 +03:00
|
|
|
|
function handleOpenItem(item: ILibraryItem, event: React.MouseEvent<Element>) {
|
2024-12-16 23:51:31 +03:00
|
|
|
|
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) {
|
2025-02-26 16:28:16 +03:00
|
|
|
|
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) {
|
2025-02-26 16:28:16 +03:00
|
|
|
|
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={
|
2025-03-07 22:04:56 +03:00
|
|
|
|
<div className='cc-column 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' />
|
2025-01-15 16:06:18 +03:00
|
|
|
|
<TextURL text='Очистить фильтр' onClick={resetFilter} />
|
2024-06-07 20:17:03 +03:00
|
|
|
|
</p>
|
2025-03-07 22:04:56 +03:00
|
|
|
|
</div>
|
2024-06-07 20:17:03 +03:00
|
|
|
|
}
|
|
|
|
|
columnVisibility={columnVisibility}
|
|
|
|
|
onRowClicked={handleOpenItem}
|
|
|
|
|
enableSorting
|
|
|
|
|
initialSorting={{
|
|
|
|
|
id: 'time_update',
|
|
|
|
|
desc: true
|
|
|
|
|
}}
|
|
|
|
|
enablePagination
|
|
|
|
|
paginationPerPage={itemsPerPage}
|
|
|
|
|
onChangePaginationOption={setItemsPerPage}
|
|
|
|
|
paginationOptions={[10, 20, 30, 50, 100]}
|
|
|
|
|
conditionalRowStyles={conditionalRowStyles}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|