2025-03-11 12:47:15 +03:00
|
|
|
import clsx from 'clsx';
|
|
|
|
|
2025-02-26 00:16:41 +03:00
|
|
|
import { HelpTopic } from '@/features/help';
|
|
|
|
import { BadgeHelp } from '@/features/help/components';
|
2025-02-12 21:36:25 +03:00
|
|
|
import { useRoleStore, UserRole } from '@/features/users';
|
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { MiniButton } from '@/components/Control';
|
2024-06-02 23:41:46 +03:00
|
|
|
import { IconImmutable, IconMutable } from '@/components/Icons';
|
2025-02-10 01:32:55 +03:00
|
|
|
import { Label } from '@/components/Input';
|
2024-06-02 23:41:46 +03:00
|
|
|
|
2025-02-22 14:04:01 +03:00
|
|
|
import { type AccessPolicy, type ILibraryItem } from '../backend/types';
|
2025-02-12 15:13:37 +03:00
|
|
|
import { useMutatingLibrary } from '../backend/useMutatingLibrary';
|
|
|
|
import { useSetAccessPolicy } from '../backend/useSetAccessPolicy';
|
2025-02-12 21:36:25 +03:00
|
|
|
|
2025-02-26 00:16:41 +03:00
|
|
|
import { IconItemVisibility } from './IconItemVisibility';
|
2025-02-12 15:13:37 +03:00
|
|
|
import { SelectAccessPolicy } from './SelectAccessPolicy';
|
|
|
|
|
2024-06-26 19:47:31 +03:00
|
|
|
interface ToolbarItemAccessProps {
|
2024-06-02 23:41:46 +03:00
|
|
|
visible: boolean;
|
|
|
|
toggleVisible: () => void;
|
|
|
|
readOnly: boolean;
|
|
|
|
toggleReadOnly: () => void;
|
2025-02-20 14:45:52 +03:00
|
|
|
schema: ILibraryItem;
|
|
|
|
isAttachedToOSS: boolean;
|
2025-03-11 12:47:15 +03:00
|
|
|
className?: string;
|
2024-06-02 23:41:46 +03:00
|
|
|
}
|
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
export function ToolbarItemAccess({
|
2025-03-11 12:47:15 +03:00
|
|
|
className,
|
2025-02-12 15:13:37 +03:00
|
|
|
visible,
|
|
|
|
toggleVisible,
|
|
|
|
readOnly,
|
|
|
|
toggleReadOnly,
|
2025-02-20 14:45:52 +03:00
|
|
|
schema,
|
|
|
|
isAttachedToOSS
|
2025-02-12 15:13:37 +03:00
|
|
|
}: ToolbarItemAccessProps) {
|
2025-01-15 23:03:35 +03:00
|
|
|
const role = useRoleStore(state => state.role);
|
2025-01-29 14:52:07 +03:00
|
|
|
const isProcessing = useMutatingLibrary();
|
2025-02-20 14:45:52 +03:00
|
|
|
const policy = schema.access_policy;
|
2025-01-27 15:03:48 +03:00
|
|
|
const { setAccessPolicy } = useSetAccessPolicy();
|
|
|
|
|
|
|
|
function handleSetAccessPolicy(newPolicy: AccessPolicy) {
|
2025-02-20 14:45:52 +03:00
|
|
|
void setAccessPolicy({ itemID: schema.id, policy: newPolicy });
|
2025-01-27 15:03:48 +03:00
|
|
|
}
|
2024-06-02 23:41:46 +03:00
|
|
|
|
|
|
|
return (
|
2025-03-11 12:47:15 +03:00
|
|
|
<div className={clsx('w-46 flex', className)}>
|
2024-06-02 23:41:46 +03:00
|
|
|
<Label text='Доступ' className='self-center select-none' />
|
|
|
|
<div className='ml-auto cc-icons'>
|
|
|
|
<SelectAccessPolicy
|
2025-02-20 14:45:52 +03:00
|
|
|
disabled={role <= UserRole.EDITOR || isProcessing || isAttachedToOSS}
|
2024-06-02 23:41:46 +03:00
|
|
|
value={policy}
|
2025-01-27 15:03:48 +03:00
|
|
|
onChange={handleSetAccessPolicy}
|
2024-06-02 23:41:46 +03:00
|
|
|
/>
|
|
|
|
|
|
|
|
<MiniButton
|
|
|
|
title={visible ? 'Библиотека: отображать' : 'Библиотека: скрывать'}
|
2025-02-26 00:16:41 +03:00
|
|
|
icon={<IconItemVisibility value={visible} />}
|
2024-06-02 23:41:46 +03:00
|
|
|
onClick={toggleVisible}
|
2025-01-27 15:03:48 +03:00
|
|
|
disabled={role === UserRole.READER || isProcessing}
|
2024-06-02 23:41:46 +03:00
|
|
|
/>
|
|
|
|
|
|
|
|
<MiniButton
|
|
|
|
title={readOnly ? 'Изменение: запрещено' : 'Изменение: разрешено'}
|
|
|
|
icon={
|
|
|
|
readOnly ? (
|
2024-12-17 10:53:01 +03:00
|
|
|
<IconImmutable size='1.25rem' className='text-sec-600' />
|
2024-06-02 23:41:46 +03:00
|
|
|
) : (
|
2024-12-16 23:52:11 +03:00
|
|
|
<IconMutable size='1.25rem' className='text-ok-600' />
|
2024-06-02 23:41:46 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
onClick={toggleReadOnly}
|
2025-01-27 15:03:48 +03:00
|
|
|
disabled={role === UserRole.READER || isProcessing}
|
2024-06-02 23:41:46 +03:00
|
|
|
/>
|
2025-03-10 16:02:53 +03:00
|
|
|
<BadgeHelp topic={HelpTopic.ACCESS} className='mt-0.5' offset={4} />
|
2024-06-02 23:41:46 +03:00
|
|
|
</div>
|
2025-03-07 22:05:12 +03:00
|
|
|
</div>
|
2024-06-02 23:41:46 +03:00
|
|
|
);
|
|
|
|
}
|