import React, { Fragment, useCallback, useState } from 'react'; import PropTypes from 'prop-types'; import { Modal, ModalHeader, ModalBody, TabContent, TabPane, Nav, NavItem, NavLink } from 'reactstrap'; import { gettext, enableRepoAutoDel } from '../../utils/constants'; import LibHistorySettingPanel from './lib-settings/lib-history-setting-panel'; import LibAutoDelSettingPanel from './lib-settings/lib-old-files-auto-del-setting-panel'; import { MetadataStatusManagementDialog as LibExtendedPropertiesSettingPanel, MetadataFaceRecognitionDialog as LibFaceRecognitionSettingPanel, MetadataTagsStatusDialog as LibMetadataTagsStatusSettingPanel, MetadataOCRStatusManagementDialog as LibMetadataOCRStatusSettingPanel, useMetadata } from '../../metadata'; import { useMetadataStatus } from '../../hooks'; import '../../css/lib-settings.css'; const TAB = { HISTORY_SETTING: 'history_setting', AUTO_DEL_SETTING: 'auto_delete_setting', EXTENDED_PROPERTIES_SETTING: 'extended_properties_setting', FACE_RECOGNITION_SETTING: 'face_recognition_setting', TAGS_SETTING: 'tags_setting', OCR_SETTING: 'ocr_setting', }; const propTypes = { toggleDialog: PropTypes.func.isRequired, repoID: PropTypes.string.isRequired, currentRepoInfo: PropTypes.object.isRequired }; const LibSettingsDialog = ({ repoID, currentRepoInfo, toggleDialog, tab }) => { const [activeTab, setActiveTab] = useState(tab || TAB.HISTORY_SETTING); const toggleTab = useCallback((tab) => { setActiveTab(tab); }, []); const onTabKeyDown = useCallback((e) => { if (e.key == 'Enter' || e.key == 'Space') { e.target.click(); } }, []); const { encrypted, is_admin } = currentRepoInfo; const { enableMetadataManagement } = window.app.pageOptions; const { enableFaceRecognition, updateEnableFaceRecognition } = useMetadata(); const { enableMetadata, updateEnableMetadata, enableTags, tagsLang, updateEnableTags, enableOCR, updateEnableOCR } = useMetadataStatus(); const enableHistorySetting = is_admin; // repo owner, admin of the department which the repo belongs to, and ... const enableAutoDelSetting = is_admin && enableRepoAutoDel; const enableExtendedPropertiesSetting = !encrypted && is_admin && enableMetadataManagement; const enableMetadataOtherSettings = enableExtendedPropertiesSetting && enableMetadata; return (