2025-02-12 21:36:25 +03:00
|
|
|
import { BadgeHelp, HelpTopic } from '@/features/help';
|
|
|
|
import { useRoleStore, UserRole } from '@/features/users';
|
|
|
|
|
2025-02-10 01:32:55 +03:00
|
|
|
import { Overlay } from '@/components/Container';
|
|
|
|
import { MiniButton } from '@/components/Control';
|
2024-06-02 23:41:46 +03:00
|
|
|
import { VisibilityIcon } from '@/components/DomainIcons';
|
|
|
|
import { IconImmutable, IconMutable } from '@/components/Icons';
|
2025-02-10 01:32:55 +03:00
|
|
|
import { Label } from '@/components/Input';
|
2024-06-09 20:41:33 +03:00
|
|
|
import { PARAMETER } from '@/utils/constants';
|
2024-06-02 23:41:46 +03:00
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
import { useMutatingLibrary } from '../backend/useMutatingLibrary';
|
|
|
|
import { useSetAccessPolicy } from '../backend/useSetAccessPolicy';
|
|
|
|
import { AccessPolicy } from '../models/library';
|
2025-02-12 21:36:25 +03:00
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
import { ILibraryItemEditor } from './EditorLibraryItem';
|
|
|
|
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;
|
2024-06-04 23:00:22 +03:00
|
|
|
controller: ILibraryItemEditor;
|
2024-06-02 23:41:46 +03:00
|
|
|
}
|
|
|
|
|
2025-02-12 15:13:37 +03:00
|
|
|
export function ToolbarItemAccess({
|
|
|
|
visible,
|
|
|
|
toggleVisible,
|
|
|
|
readOnly,
|
|
|
|
toggleReadOnly,
|
|
|
|
controller
|
|
|
|
}: 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-01-27 15:03:48 +03:00
|
|
|
const policy = controller.schema.access_policy;
|
|
|
|
const { setAccessPolicy } = useSetAccessPolicy();
|
|
|
|
|
|
|
|
function handleSetAccessPolicy(newPolicy: AccessPolicy) {
|
2025-02-11 20:56:24 +03:00
|
|
|
void setAccessPolicy({ itemID: controller.schema.id, policy: newPolicy });
|
2025-01-27 15:03:48 +03:00
|
|
|
}
|
2024-06-02 23:41:46 +03:00
|
|
|
|
|
|
|
return (
|
2024-08-01 20:11:32 +03:00
|
|
|
<Overlay position='top-[4.5rem] right-0 w-[12rem] pr-2' className='flex' layer='z-bottom'>
|
2024-06-02 23:41:46 +03:00
|
|
|
<Label text='Доступ' className='self-center select-none' />
|
|
|
|
<div className='ml-auto cc-icons'>
|
|
|
|
<SelectAccessPolicy
|
2025-01-27 15:03:48 +03:00
|
|
|
disabled={role <= UserRole.EDITOR || isProcessing || controller.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 ? 'Библиотека: отображать' : 'Библиотека: скрывать'}
|
|
|
|
icon={<VisibilityIcon value={visible} />}
|
|
|
|
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
|
|
|
/>
|
|
|
|
|
2024-06-09 20:41:33 +03:00
|
|
|
<BadgeHelp topic={HelpTopic.ACCESS} className={PARAMETER.TOOLTIP_WIDTH} offset={4} />
|
2024-06-02 23:41:46 +03:00
|
|
|
</div>
|
|
|
|
</Overlay>
|
|
|
|
);
|
|
|
|
}
|