2024-06-19 22:10:15 +03:00
|
|
|
import clsx from 'clsx';
|
2024-06-20 21:11:40 +03:00
|
|
|
import { toast } from 'react-toastify';
|
2024-06-19 22:10:15 +03:00
|
|
|
|
2024-08-21 16:49:17 +03:00
|
|
|
import { SubfoldersIcon } from '@/components/DomainIcons';
|
|
|
|
import { IconFolderEdit, IconFolderTree } from '@/components/Icons';
|
2024-06-20 11:28:35 +03:00
|
|
|
import BadgeHelp from '@/components/info/BadgeHelp';
|
2024-06-19 22:10:15 +03:00
|
|
|
import { CProps } from '@/components/props';
|
2024-06-26 19:00:29 +03:00
|
|
|
import SelectLocation from '@/components/select/SelectLocation';
|
2024-06-19 22:10:15 +03:00
|
|
|
import MiniButton from '@/components/ui/MiniButton';
|
2024-08-21 16:49:17 +03:00
|
|
|
import { useAuth } from '@/context/AuthContext';
|
2024-09-19 20:52:37 +03:00
|
|
|
import { useConceptOptions } from '@/context/ConceptOptionsContext';
|
2024-08-21 16:49:17 +03:00
|
|
|
import { useLibrary } from '@/context/LibraryContext';
|
2024-07-25 23:32:24 +03:00
|
|
|
import useWindowSize from '@/hooks/useWindowSize';
|
2024-06-19 22:10:15 +03:00
|
|
|
import { FolderNode, FolderTree } from '@/models/FolderTree';
|
2024-06-20 11:28:35 +03:00
|
|
|
import { HelpTopic } from '@/models/miscellaneous';
|
2024-06-20 22:06:35 +03:00
|
|
|
import { PARAMETER, prefixes } from '@/utils/constants';
|
2024-06-26 19:00:29 +03:00
|
|
|
import { information } from '@/utils/labels';
|
2024-06-19 22:10:15 +03:00
|
|
|
|
2024-06-27 11:35:26 +03:00
|
|
|
interface ViewSideLocationProps {
|
|
|
|
folderTree: FolderTree;
|
2024-12-12 13:19:12 +03:00
|
|
|
isVisible: boolean;
|
2024-08-21 16:49:17 +03:00
|
|
|
subfolders: boolean;
|
2024-11-21 00:26:16 +03:00
|
|
|
activeLocation: string;
|
|
|
|
onChangeActiveLocation: (newValue: string) => void;
|
2024-06-19 22:10:15 +03:00
|
|
|
toggleFolderMode: () => void;
|
2024-08-21 16:49:17 +03:00
|
|
|
toggleSubfolders: () => void;
|
|
|
|
onRenameLocation: () => void;
|
2024-06-19 22:10:15 +03:00
|
|
|
}
|
|
|
|
|
2024-08-21 16:49:17 +03:00
|
|
|
function ViewSideLocation({
|
|
|
|
folderTree,
|
2024-11-21 00:26:16 +03:00
|
|
|
activeLocation,
|
2024-08-21 16:49:17 +03:00
|
|
|
subfolders,
|
2024-12-12 13:19:12 +03:00
|
|
|
isVisible,
|
2024-11-21 00:26:16 +03:00
|
|
|
onChangeActiveLocation,
|
2024-08-21 16:49:17 +03:00
|
|
|
toggleFolderMode,
|
|
|
|
toggleSubfolders,
|
|
|
|
onRenameLocation
|
|
|
|
}: ViewSideLocationProps) {
|
|
|
|
const { user } = useAuth();
|
|
|
|
const { items } = useLibrary();
|
2024-09-19 20:52:37 +03:00
|
|
|
const { calculateHeight } = useConceptOptions();
|
2024-07-25 23:32:24 +03:00
|
|
|
const windowSize = useWindowSize();
|
2024-09-12 13:27:20 +03:00
|
|
|
|
2024-12-13 21:31:09 +03:00
|
|
|
const canRename = (() => {
|
2024-11-21 00:26:16 +03:00
|
|
|
if (activeLocation.length <= 3 || !user) {
|
2024-09-12 13:27:20 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (user.is_staff) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const owned = items.filter(item => item.owner == user.id);
|
2024-11-21 00:26:16 +03:00
|
|
|
const located = owned.filter(
|
|
|
|
item => item.location == activeLocation || item.location.startsWith(`${activeLocation}/`)
|
|
|
|
);
|
2024-09-12 13:27:20 +03:00
|
|
|
return located.length !== 0;
|
2024-12-13 21:31:09 +03:00
|
|
|
})();
|
2024-09-12 13:27:20 +03:00
|
|
|
|
2024-12-13 21:31:09 +03:00
|
|
|
const maxHeight = calculateHeight('4.5rem');
|
2024-09-12 13:27:20 +03:00
|
|
|
|
2024-12-13 21:31:09 +03:00
|
|
|
function handleClickFolder(event: CProps.EventMouse, target: FolderNode) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
if (event.ctrlKey || event.metaKey) {
|
|
|
|
navigator.clipboard
|
|
|
|
.writeText(target.getPath())
|
|
|
|
.then(() => toast.success(information.pathReady))
|
|
|
|
.catch(console.error);
|
|
|
|
} else {
|
|
|
|
onChangeActiveLocation(target.getPath());
|
|
|
|
}
|
|
|
|
}
|
2024-06-19 22:10:15 +03:00
|
|
|
|
|
|
|
return (
|
2024-12-12 13:19:12 +03:00
|
|
|
<div
|
2024-07-25 23:32:24 +03:00
|
|
|
className={clsx('max-w-[10rem] sm:max-w-[15rem]', 'flex flex-col', 'text:xs sm:text-sm', 'select-none')}
|
2024-12-12 13:19:12 +03:00
|
|
|
style={{
|
|
|
|
transitionProperty: 'width, min-width, opacity',
|
|
|
|
transitionDuration: `${PARAMETER.moveDuration}ms`,
|
|
|
|
transitionTimingFunction: 'ease-out',
|
|
|
|
minWidth: isVisible ? (windowSize.isSmall ? '10rem' : '15rem') : '0',
|
|
|
|
width: isVisible ? '100%' : '0',
|
|
|
|
opacity: isVisible ? 1 : 0
|
|
|
|
}}
|
2024-06-19 22:10:15 +03:00
|
|
|
>
|
2024-07-19 20:43:09 +03:00
|
|
|
<div className='h-[2.08rem] flex justify-between items-center pr-1 pl-[0.125rem]'>
|
2024-06-20 11:28:35 +03:00
|
|
|
<BadgeHelp
|
|
|
|
topic={HelpTopic.UI_LIBRARY}
|
|
|
|
className={clsx(PARAMETER.TOOLTIP_WIDTH, 'text-sm')}
|
|
|
|
offset={5}
|
|
|
|
place='right-start'
|
|
|
|
/>
|
2024-08-21 16:49:17 +03:00
|
|
|
<div className='cc-icons'>
|
2024-09-27 12:04:10 +03:00
|
|
|
{canRename ? (
|
|
|
|
<MiniButton
|
|
|
|
icon={<IconFolderEdit size='1.25rem' className='icon-primary' />}
|
|
|
|
titleHtml='<b>Редактирование пути</b><br/>Перемещаются только Ваши схемы<br/>в указанной папке (и подпапках)'
|
|
|
|
onClick={onRenameLocation}
|
|
|
|
/>
|
|
|
|
) : null}
|
2024-12-13 13:22:21 +03:00
|
|
|
{!!activeLocation ? (
|
|
|
|
<MiniButton
|
|
|
|
title={subfolders ? 'Вложенные папки: Вкл' : 'Вложенные папки: Выкл'} // prettier: split-lines
|
|
|
|
icon={<SubfoldersIcon value={subfolders} />}
|
|
|
|
onClick={toggleSubfolders}
|
|
|
|
/>
|
|
|
|
) : null}
|
2024-08-21 16:49:17 +03:00
|
|
|
<MiniButton
|
|
|
|
icon={<IconFolderTree size='1.25rem' className='icon-green' />}
|
|
|
|
title='Переключение в режим Поиск'
|
|
|
|
onClick={toggleFolderMode}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-06-19 22:10:15 +03:00
|
|
|
</div>
|
2024-06-26 19:00:29 +03:00
|
|
|
<SelectLocation
|
2024-11-21 00:26:16 +03:00
|
|
|
value={activeLocation}
|
2024-06-27 11:35:26 +03:00
|
|
|
folderTree={folderTree}
|
2024-06-26 19:00:29 +03:00
|
|
|
prefix={prefixes.folders_list}
|
|
|
|
onClick={handleClickFolder}
|
2024-09-19 20:52:37 +03:00
|
|
|
style={{ maxHeight: maxHeight }}
|
2024-06-26 19:00:29 +03:00
|
|
|
/>
|
2024-12-12 13:19:12 +03:00
|
|
|
</div>
|
2024-06-19 22:10:15 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-06-27 11:35:26 +03:00
|
|
|
export default ViewSideLocation;
|