import { Suspense } from 'react'; import { useIntl } from 'react-intl'; import { urls, useConceptNavigation } from '@/app'; import { useLabelUser, useRoleStore, UserRole } from '@/features/users'; import { InfoUsers, SelectUser } from '@/features/users/components'; import { Overlay, Tooltip } from '@/components/Container'; import { MiniButton } from '@/components/Control'; import { useDropdown } from '@/components/Dropdown'; import { IconDateCreate, IconDateUpdate, IconEditor, IconFolderEdit, IconFolderOpened, IconOwner } from '@/components/Icons'; import { Loader } from '@/components/Loader'; import { ValueIcon } from '@/components/View'; import { useDialogsStore } from '@/stores/dialogs'; import { useModificationStore } from '@/stores/modification'; import { prefixes } from '@/utils/constants'; import { promptText } from '@/utils/labels'; import { type ILibraryItemData } from '../backend/types'; import { useMutatingLibrary } from '../backend/useMutatingLibrary'; import { useSetLocation } from '../backend/useSetLocation'; import { useSetOwner } from '../backend/useSetOwner'; import { useLibrarySearchStore } from '../stores/librarySearch'; interface EditorLibraryItemProps { schema: ILibraryItemData; isAttachedToOSS: boolean; } export function EditorLibraryItem({ schema, isAttachedToOSS }: EditorLibraryItemProps) { const getUserLabel = useLabelUser(); const role = useRoleStore(state => state.role); const intl = useIntl(); const router = useConceptNavigation(); const setGlobalLocation = useLibrarySearchStore(state => state.setLocation); const isProcessing = useMutatingLibrary(); const { isModified } = useModificationStore(); const { setOwner } = useSetOwner(); const { setLocation } = useSetLocation(); const showEditEditors = useDialogsStore(state => state.showEditEditors); const showEditLocation = useDialogsStore(state => state.showChangeLocation); const ownerSelector = useDropdown(); const onSelectUser = function (newValue: number) { ownerSelector.hide(); if (newValue === schema.owner) { return; } if (!window.confirm(promptText.ownerChange)) { return; } void setOwner({ itemID: schema.id, owner: newValue }); }; function handleOpenLibrary(event: React.MouseEvent) { setGlobalLocation(schema.location); router.push({ path: urls.library, newTab: event.ctrlKey || event.metaKey }); } function handleEditLocation() { showEditLocation({ initial: schema.location, onChangeLocation: newLocation => void setLocation({ itemID: schema.id, location: newLocation }) }); } function handleEditEditors() { showEditEditors({ itemID: schema.id, initialEditors: schema.editors }); } return (
} onClick={handleOpenLibrary} /> } value={schema.location} title={isAttachedToOSS ? 'Путь наследуется от ОСС' : 'Путь'} onClick={handleEditLocation} disabled={isModified || isProcessing || isAttachedToOSS || role < UserRole.OWNER} />
{ownerSelector.isOpen ? ( {ownerSelector.isOpen ? ( ) : null} ) : null} } value={getUserLabel(schema.owner)} title={isAttachedToOSS ? 'Владелец наследуется от ОСС' : 'Владелец'} onClick={ownerSelector.toggle} disabled={isModified || isProcessing || isAttachedToOSS || role < UserRole.OWNER} />
} value={schema.editors.length} onClick={handleEditEditors} disabled={isModified || isProcessing || role < UserRole.OWNER} /> }> } value={new Date(schema.time_update).toLocaleString(intl.locale)} title='Дата обновления' /> } value={new Date(schema.time_create).toLocaleString(intl.locale, { year: '2-digit', month: '2-digit', day: '2-digit' })} title='Дата создания' />
); }