| @@ -1,21 +1,22 @@ | |||||
| /* | /* | ||||
| * @Author: 赵伟 | * @Author: 赵伟 | ||||
| * @Date: 2024-04-16 08:42:57 | * @Date: 2024-04-16 08:42:57 | ||||
| * @Description: 参数输入组件 | |||||
| * @Description: 参数输入组件,支持手动输入,选择全局参数,选择数据集/模型/镜像 | |||||
| */ | */ | ||||
| import { CommonTabKeys } from '@/enums'; | |||||
| import { CloseOutlined } from '@ant-design/icons'; | import { CloseOutlined } from '@ant-design/icons'; | ||||
| import { Form, Input } from 'antd'; | import { Form, Input } from 'antd'; | ||||
| import { RuleObject } from 'antd/es/form'; | import { RuleObject } from 'antd/es/form'; | ||||
| import classNames from 'classnames'; | import classNames from 'classnames'; | ||||
| import './index.less'; | import './index.less'; | ||||
| // 对象 | |||||
| // 如果值是对象时的类型 | |||||
| export type ParameterInputObject = { | export type ParameterInputObject = { | ||||
| value?: any; // 值 | value?: any; // 值 | ||||
| showValue?: any; // 显示值 | showValue?: any; // 显示值 | ||||
| fromSelect?: boolean; // 是否来自选择 | fromSelect?: boolean; // 是否来自选择 | ||||
| activeTab?: string; // 选择镜像、数据集、模型时,保存当前激活的tab | |||||
| activeTab?: CommonTabKeys; // 选择镜像、数据集、模型时,保存当前激活的tab | |||||
| expandedKeys?: string[]; // 选择镜像、数据集、模型时,保存展开的keys | expandedKeys?: string[]; // 选择镜像、数据集、模型时,保存展开的keys | ||||
| checkedKeys?: string[]; // 选择镜像、数据集、模型时,保存选中的keys | checkedKeys?: string[]; // 选择镜像、数据集、模型时,保存选中的keys | ||||
| [key: string]: any; | [key: string]: any; | ||||
| @@ -1,7 +1,7 @@ | |||||
| /* | /* | ||||
| * @Author: 赵伟 | * @Author: 赵伟 | ||||
| * @Date: 2024-04-16 08:42:57 | * @Date: 2024-04-16 08:42:57 | ||||
| * @Description: 参数选择组件 | |||||
| * @Description: 参数下拉选择组件,支持资源规格、数据集、模型、服务 | |||||
| */ | */ | ||||
| import { PipelineNodeModelParameter } from '@/types'; | import { PipelineNodeModelParameter } from '@/types'; | ||||
| @@ -12,7 +12,8 @@ import ResourceSelectorModal, { | |||||
| } from '@/pages/Pipeline/components/ResourceSelectorModal'; | } from '@/pages/Pipeline/components/ResourceSelectorModal'; | ||||
| import { openAntdModal } from '@/utils/modal'; | import { openAntdModal } from '@/utils/modal'; | ||||
| import { Button } from 'antd'; | import { Button } from 'antd'; | ||||
| import { useState } from 'react'; | |||||
| import { pick } from 'lodash'; | |||||
| import { useEffect, useState } from 'react'; | |||||
| import ParameterInput, { type ParameterInputProps } from '../ParameterInput'; | import ParameterInput, { type ParameterInputProps } from '../ParameterInput'; | ||||
| import './index.less'; | import './index.less'; | ||||
| @@ -33,6 +34,31 @@ function ResourceSelect({ type, value, onChange, disabled, ...rest }: ResourceSe | |||||
| undefined, | undefined, | ||||
| ); | ); | ||||
| useEffect(() => { | |||||
| if ( | |||||
| value && | |||||
| typeof value === 'object' && | |||||
| value.activeTab && | |||||
| value.id && | |||||
| value.name && | |||||
| value.version && | |||||
| value.path && | |||||
| (type === ResourceSelectorType.Mirror || value.identifier) && | |||||
| (type === ResourceSelectorType.Mirror || value.owner) | |||||
| ) { | |||||
| const originResource = pick(value, [ | |||||
| 'activeTab', | |||||
| 'id', | |||||
| 'identifier', | |||||
| 'name', | |||||
| 'owner', | |||||
| 'version', | |||||
| 'path', | |||||
| ]) as ResourceSelectorResponse; | |||||
| setSelectedResource(originResource); | |||||
| } | |||||
| }, [value]); | |||||
| const selectResource = () => { | const selectResource = () => { | ||||
| const resource = selectedResource; | const resource = selectedResource; | ||||
| const { close } = openAntdModal(ResourceSelectorModal, { | const { close } = openAntdModal(ResourceSelectorModal, { | ||||
| @@ -50,8 +76,10 @@ function ResourceSelect({ type, value, onChange, disabled, ...rest }: ResourceSe | |||||
| showValue: path, | showValue: path, | ||||
| fromSelect: true, | fromSelect: true, | ||||
| activeTab, | activeTab, | ||||
| expandedKeys: [`${id}`], | |||||
| checkedKeys: [`${id}-${version}`], | |||||
| id, | |||||
| name, | |||||
| version, | |||||
| path, | |||||
| }); | }); | ||||
| } else { | } else { | ||||
| const jsonObj = { | const jsonObj = { | ||||
| @@ -69,8 +97,6 @@ function ResourceSelect({ type, value, onChange, disabled, ...rest }: ResourceSe | |||||
| showValue, | showValue, | ||||
| fromSelect: true, | fromSelect: true, | ||||
| activeTab, | activeTab, | ||||
| expandedKeys: [`${id}`], | |||||
| checkedKeys: [`${id}-${version}`], | |||||
| ...jsonObj, | ...jsonObj, | ||||
| }); | }); | ||||
| } | } | ||||
| @@ -80,8 +106,6 @@ function ResourceSelect({ type, value, onChange, disabled, ...rest }: ResourceSe | |||||
| showValue: undefined, | showValue: undefined, | ||||
| fromSelect: false, | fromSelect: false, | ||||
| activeTab: undefined, | activeTab: undefined, | ||||
| expandedKeys: [], | |||||
| checkedKeys: [], | |||||
| }); | }); | ||||
| } | } | ||||
| close(); | close(); | ||||
| @@ -3,6 +3,7 @@ | |||||
| .title(@color, @background) { | .title(@color, @background) { | ||||
| width: 100%; | width: 100%; | ||||
| margin-bottom: 20px; | margin-bottom: 20px; | ||||
| padding: 0 15px; | |||||
| color: @color; | color: @color; | ||||
| font-weight: 500; | font-weight: 500; | ||||
| font-size: @font-size; | font-size: @font-size; | ||||
| @@ -3,6 +3,7 @@ | |||||
| .title(@color, @background) { | .title(@color, @background) { | ||||
| width: 100%; | width: 100%; | ||||
| margin-bottom: 20px; | margin-bottom: 20px; | ||||
| padding: 0 15px; | |||||
| color: @color; | color: @color; | ||||
| font-weight: 500; | font-weight: 500; | ||||
| font-size: @font-size; | font-size: @font-size; | ||||
| @@ -18,13 +18,13 @@ export { ResourceSelectorType, selectorTypeConfig }; | |||||
| // 选择数据集\模型\镜像的返回类型 | // 选择数据集\模型\镜像的返回类型 | ||||
| export type ResourceSelectorResponse = { | export type ResourceSelectorResponse = { | ||||
| activeTab: CommonTabKeys; // 是我的还是公开的 | |||||
| id: string; // 数据集\模型\镜像 id | id: string; // 数据集\模型\镜像 id | ||||
| name: string; // 数据集\模型\镜像 name | name: string; // 数据集\模型\镜像 name | ||||
| version: string; // 数据集\模型\镜像版本 | version: string; // 数据集\模型\镜像版本 | ||||
| path: string; // 数据集\模型\镜像版本路径 | path: string; // 数据集\模型\镜像版本路径 | ||||
| identifier: string; // 数据集\模型 identifier | |||||
| owner: string; // 数据集\模型 owner | |||||
| activeTab: CommonTabKeys; // 是我的还是公开的 | |||||
| identifier: string; // 数据集\模型 identifier,镜像没有这个字段 | |||||
| owner: string; // 数据集\模型 owner,镜像没有这个字段 | |||||
| }; | }; | ||||
| export interface ResourceSelectorModalProps extends Omit<ModalProps, 'onOk'> { | export interface ResourceSelectorModalProps extends Omit<ModalProps, 'onOk'> { | ||||
| @@ -69,7 +69,7 @@ function ResourceSelectorModal({ | |||||
| onOk, | onOk, | ||||
| ...rest | ...rest | ||||
| }: ResourceSelectorModalProps) { | }: ResourceSelectorModalProps) { | ||||
| const [activeTab, setActiveTab] = useState<string>(defaultActiveTab); | |||||
| const [activeTab, setActiveTab] = useState<CommonTabKeys>(defaultActiveTab); | |||||
| const [expandedKeys, setExpandedKeys] = useState<React.Key[]>([]); | const [expandedKeys, setExpandedKeys] = useState<React.Key[]>([]); | ||||
| const [checkedKeys, setCheckedKeys] = useState<React.Key[]>([]); | const [checkedKeys, setCheckedKeys] = useState<React.Key[]>([]); | ||||
| const [loadedKeys, setLoadedKeys] = useState<React.Key[]>([]); | const [loadedKeys, setLoadedKeys] = useState<React.Key[]>([]); | ||||
| @@ -234,7 +234,7 @@ function ResourceSelectorModal({ | |||||
| version, | version, | ||||
| identifier, | identifier, | ||||
| owner, | owner, | ||||
| activeTab: activeTab as CommonTabKeys, | |||||
| activeTab: activeTab, | |||||
| }; | }; | ||||
| onOk?.(res); | onOk?.(res); | ||||
| } else { | } else { | ||||
| @@ -255,7 +255,7 @@ function ResourceSelectorModal({ | |||||
| <Tabs | <Tabs | ||||
| activeKey={activeTab} | activeKey={activeTab} | ||||
| items={tabItems} | items={tabItems} | ||||
| onChange={setActiveTab} | |||||
| onChange={(e) => setActiveTab(e as CommonTabKeys)} | |||||
| className={styles['model-tabs']} | className={styles['model-tabs']} | ||||
| /> | /> | ||||
| <div className={styles['model-selector']}> | <div className={styles['model-selector']}> | ||||