Portal/rsconcept/frontend/src/features/library/components/ToolbarItemAccess.tsx

78 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-02-12 21:36:03 +03:00
import { BadgeHelp, HelpTopic } from '@/features/help';
import { useRoleStore, UserRole } from '@/features/users';
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';
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-22 14:03:13 +03:00
import { type AccessPolicy, type 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';
interface ToolbarItemAccessProps {
2024-06-07 20:17:03 +03:00
visible: boolean;
toggleVisible: () => void;
readOnly: boolean;
toggleReadOnly: () => void;
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,
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);
const isProcessing = useMutatingLibrary();
const policy = schema.access_policy;
2025-01-26 22:24:34 +03:00
const { setAccessPolicy } = useSetAccessPolicy();
function handleSetAccessPolicy(newPolicy: AccessPolicy) {
void setAccessPolicy({ itemID: schema.id, policy: newPolicy });
2025-01-26 22:24:34 +03:00
}
2024-06-07 20:17:03 +03:00
return (
<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
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
) : (
<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>
);
}