/* * @Author: ZhaoYing * @Date: 2026-02-03 16:27:52 * @Last Modified by: ZhaoYing * @Last Modified time: 2026-03-19 17:13:54 */ import { type FC, useRef, useMemo, useCallback } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { Layout, Tabs, Dropdown, Button, Flex } from 'antd'; import type { MenuProps } from 'antd'; import { useTranslation } from 'react-i18next'; import styles from '../index.module.css' import logoutIcon from '@/assets/images/logout.svg' import editIcon from '@/assets/images/edit_hover.svg' import copyIcon from '@/assets/images/copy_hover.svg' import exportIcon from '@/assets/images/export_hover.svg' import deleteIcon from '@/assets/images/delete_hover.svg' import type { Application, ApplicationModalRef } 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 FeaturesConfig from './FeaturesConfig' const { Header } = Layout; /** * Tab keys for application configuration */ const tabKeys = ['arrangement', 'api', 'release', 'statistics'] const sharingTabKeys = [ 'test', // 'log', 'api' ] /** * Menu icon mapping */ const menuIcons: Record = { edit: editIcon, copy: copyIcon, export: exportIcon, delete: deleteIcon } /** * 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, features, onFeaturesChange, }) => { const { t } = useTranslation(); const navigate = useNavigate(); const { id, source } = useParams(); const applicationModalRef = useRef(null); const copyModalRef = 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; } } /** * 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', 'delete'] : ['edit', 'copy', 'delete']).map(key => ({ key, icon: , label: t(`common.${key}`), })) return items }, [t, handleClick, application]) const handleSaveFeaturesConfig = useCallback((value: FeaturesConfigForm) => { appRef?.current?.handleSaveFeaturesConfig?.(value) onFeaturesChange?.(value) }, [appRef, onFeaturesChange]) return ( <>
{application?.name[0]}
{application?.name}
{source !== 'sharing' &&
}
{application?.type === 'workflow' && source !== 'sharing' && activeTab === 'arrangement' ?
{/* */}
:
{t('application.returnToApplicationList')}
}
); }; export default ConfigHeader;