/* * @Author: ZhaoYing * @Date: 2026-02-03 16:27:52 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-04-17 14:53:21 */ import { type FC, useRef, useMemo } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { Tabs, Dropdown, Flex, Popover } from 'antd'; import type { MenuProps } from 'antd'; import { useTranslation } from 'react-i18next'; import clsx from 'clsx'; import styles from '../index.module.css' import type { Application, ApplicationModalRef, UploadWorkflowModalRef } from '@/views/ApplicationManagement/types'; import ApplicationModal from '@/views/ApplicationManagement/components/ApplicationModal' import type { CopyModalRef, AgentRef, ClusterRef, WorkflowRef, FeaturesConfigForm } from '../types' import { deleteApplication, appExport } from '@/api/application' import CopyModal from './CopyModal' import PageHeader from '@/components/Layout/PageHeader' import CheckList from '@/views/Workflow/components/CheckList' import UploadModal from '@/views/ApplicationManagement/components/UploadModal' /** * Tab keys for application configuration */ const tabKeys = ['arrangement', 'api', 'release', 'log', 'statistics'] const sharingTabKeys = [ 'test', 'log', 'api' ] /** * Menu icon mapping */ const menuIcons: Record = { edit: "rb:bg-[url('@/assets/images/common/edit_bold.svg')]", copy: "rb:bg-[url('@/assets/images/copy_hover.svg')]", export: "rb:bg-[url('@/assets/images/application/export.svg')]", uploadCover: "rb:bg-[url('@/assets/images/application/import.svg')]", delete: "rb:bg-[url('@/assets/images/common/delete_red_big.svg')]" } /** * Props for ConfigHeader component */ interface ConfigHeaderProps { /** Application data */ application?: Application; /** Active tab key */ activeTab: string; /** Tab change handler */ handleChangeTab: (key: string) => void; /** Refresh application data */ refresh: () => void; /** Workflow component ref */ workflowRef: React.RefObject /** App component ref (Agent/Cluster/Workflow) */ appRef?: React.RefObject /** Features config from parent state */ features?: FeaturesConfigForm; /** Callback to update features in parent */ onFeaturesChange?: (value: FeaturesConfigForm) => void; } /** * Configuration header component * Displays application name, tabs, and action buttons */ const ConfigHeader: FC = ({ application, activeTab, handleChangeTab, refresh, workflowRef, appRef, onFeaturesChange, }) => { const { t } = useTranslation(); const navigate = useNavigate(); const { id, source } = useParams(); const applicationModalRef = useRef(null); const copyModalRef = useRef(null); const uploadModalRef = useRef(null); /** * Format tab items for display */ const formatTabItems = useMemo(() => { return (source === 'sharing' ? sharingTabKeys : tabKeys).map(key => ({ key, label: t(`application.${key}`), })) }, [source, sharingTabKeys, tabKeys]) /** * Handle menu item click */ const handleClick: MenuProps['onClick'] = ({ key }) => { if (!application) return switch (key) { case 'edit': applicationModalRef.current?.handleOpen(application) break; case 'copy': appRef?.current?.handleSave(false) .then(() => { copyModalRef.current?.handleOpen() }) break; case 'export': appRef?.current?.handleSave(false) .then(() => { appExport(application.id, application.name) }) break; case 'delete': handleDelete() break; case 'uploadCover': uploadModalRef.current?.handleOpen() break } } /** * Delete application with confirmation */ const handleDelete = () => { if (!id) { return } deleteApplication(id as string) .then(() => { goToApplication() }) .catch(() => { console.error('Failed to delete application'); }); } /** * Navigate to application list */ const goToApplication = () => { navigate('/application', { replace: true }) } /** * Save workflow configuration */ const save = () => { workflowRef.current?.handleSave() } /** * Run workflow */ const run = () => { workflowRef.current?.handleSave(false) .then(() => { workflowRef.current?.handleRun() }) } /** * Clear workflow canvas */ const clear = () => { workflowRef?.current?.graphRef?.current?.clearCells() } /** * Add variable to workflow */ const addvariable = () => { workflowRef?.current?.addVariable() } /** * Format dropdown menu items */ const formatMenuItems = useMemo(() => { const items = (application?.type !== 'multi_agent' ? ['edit', 'copy', 'export', 'uploadCover', 'delete'] : ['edit', 'copy', 'delete']).map(key => ({ key, icon:
, danger: key === 'delete', label: key === 'uploadCover' ? t('application.uploadCover') : t(`common.${key}`), })) return items }, [t, handleClick, application]) const handleFeaturesConfig = () => { workflowRef.current?.handleFeaturesConfig?.() } return ( <>
} centerContent={ } extra={application?.type === 'workflow' && source !== 'sharing' && activeTab === 'arrangement' ?
:
{t('common.return')}
} >
); }; export default ConfigHeader;