2025-02-12 21:36:03 +03:00
|
|
|
import { BadgeHelp, HelpTopic } from '@/features/help';
|
|
|
|
import { useRoleStore, UserRole } from '@/features/users';
|
|
|
|
|
2025-02-10 01:32:16 +03:00
|
|
|
import { Overlay } from '@/components/Container';
|
|
|
|
import { MiniButton } from '@/components/Control';
|
2024-06-07 20:17:03 +03:00
|
|
|
import { VisibilityIcon } from '@/components/DomainIcons';
|
|
|
|
import { IconImmutable, IconMutable } from '@/components/Icons';
|
2025-02-10 01:32:16 +03:00
|
|
|
import { Label } from '@/components/Input';
|
2024-06-09 20:40:41 +03:00
|
|
|
import { PARAMETER } from '@/utils/constants';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2025-02-20 14:45:12 +03:00
|
|
|
import { AccessPolicy, ILibraryItem } from '../backend/types';
|
2025-02-12 15:12:59 +03:00
|
|
|
import { useMutatingLibrary } from '../backend/useMutatingLibrary';
|
|
|
|
import { useSetAccessPolicy } from '../backend/useSetAccessPolicy';
|
2025-02-12 21:36:03 +03:00
|
|
|
|
2025-02-12 15:12:59 +03:00
|
|
|
import { SelectAccessPolicy } from './SelectAccessPolicy';
|
|
|
|
|
2024-06-26 19:47:05 +03:00
|
|
|
interface ToolbarItemAccessProps {
|
2024-06-07 20:17:03 +03:00
|
|
|
visible: boolean;
|
|
|
|
toggleVisible: () => void;
|
|
|
|
readOnly: boolean;
|
|
|
|
toggleReadOnly: () => void;
|
2025-02-20 14:45:12 +03:00
|
|
|
schema: ILibraryItem;
|
|
|
|
isAttachedToOSS: boolean;
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
|
|
|
|
2025-02-12 15:12:59 +03:00
|
|
|
export function ToolbarItemAccess({
|
|
|
|
visible,
|
|
|
|
toggleVisible,
|
|
|
|
readOnly,
|
|
|
|
toggleReadOnly,
|
2025-02-20 14:45:12 +03:00
|
|
|
schema,
|
|
|
|
isAttachedToOSS
|
2025-02-12 15:12:59 +03:00
|
|
|
}: ToolbarItemAccessProps) {
|
2025-01-15 23:03:23 +03:00
|
|
|
const role = useRoleStore(state => state.role);
|
2025-01-29 14:51:34 +03:00
|
|
|
const isProcessing = useMutatingLibrary();
|
2025-02-20 14:45:12 +03:00
|
|
|
const policy = schema.access_policy;
|
2025-01-26 22:24:34 +03:00
|
|
|
const { setAccessPolicy } = useSetAccessPolicy();
|
|
|
|
|
|
|
|
function handleSetAccessPolicy(newPolicy: AccessPolicy) {
|
2025-02-20 14:45:12 +03:00
|
|
|
void setAccessPolicy({ itemID: schema.id, policy: newPolicy });
|
2025-01-26 22:24:34 +03:00
|
|
|
}
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
return (
|
2024-08-01 20:10:58 +03:00
|
|
|
<Overlay position='top-[4.5rem] right-0 w-[12rem] pr-2' className='flex' layer='z-bottom'>
|
2024-06-07 20:17:03 +03:00
|
|
|
<Label text='Доступ' className='self-center select-none' />
|
|
|
|
<div className='ml-auto cc-icons'>
|
|
|
|
<SelectAccessPolicy
|
2025-02-20 14:45:12 +03:00
|
|
|
disabled={role <= UserRole.EDITOR || isProcessing || isAttachedToOSS}
|
2024-06-07 20:17:03 +03:00
|
|
|
value={policy}
|
2025-01-26 22:24:34 +03:00
|
|
|
onChange={handleSetAccessPolicy}
|
2024-06-07 20:17:03 +03:00
|
|
|
/>
|
|
|
|
|
|
|
|
<MiniButton
|
|
|
|
title={visible ? 'Библиотека: отображать' : 'Библиотека: скрывать'}
|
|
|
|
icon={<VisibilityIcon value={visible} />}
|
|
|
|
onClick={toggleVisible}
|
2025-01-26 22:24:34 +03:00
|
|
|
disabled={role === UserRole.READER || isProcessing}
|
2024-06-07 20:17:03 +03:00
|
|
|
/>
|
|
|
|
|
|
|
|
<MiniButton
|
|
|
|
title={readOnly ? 'Изменение: запрещено' : 'Изменение: разрешено'}
|
|
|
|
icon={
|
|
|
|
readOnly ? (
|
2024-12-17 10:52:36 +03:00
|
|
|
<IconImmutable size='1.25rem' className='text-sec-600' />
|
2024-06-07 20:17:03 +03:00
|
|
|
) : (
|
2024-12-16 23:51:31 +03:00
|
|
|
<IconMutable size='1.25rem' className='text-ok-600' />
|
2024-06-07 20:17:03 +03:00
|
|
|
)
|
|
|
|
}
|
|
|
|
onClick={toggleReadOnly}
|
2025-01-26 22:24:34 +03:00
|
|
|
disabled={role === UserRole.READER || isProcessing}
|
2024-06-07 20:17:03 +03:00
|
|
|
/>
|
|
|
|
|
2024-06-09 20:40:41 +03:00
|
|
|
<BadgeHelp topic={HelpTopic.ACCESS} className={PARAMETER.TOOLTIP_WIDTH} offset={4} />
|
2024-06-07 20:17:03 +03:00
|
|
|
</div>
|
|
|
|
</Overlay>
|
|
|
|
);
|
|
|
|
}
|