Browse Source

fix: 实验参数修改

pull/53/head
cp3hnu 1 year ago
parent
commit
299b6635b0
6 changed files with 96 additions and 99 deletions
  1. +1
    -1
      react-ui/src/components/ParameterInput/index.tsx
  2. +72
    -0
      react-ui/src/components/ParameterSelect/config.tsx
  3. +0
    -0
      react-ui/src/components/ParameterSelect/index.less
  4. +10
    -74
      react-ui/src/components/ParameterSelect/index.tsx
  5. +10
    -17
      react-ui/src/pages/Experiment/components/ExperimentParameter/index.tsx
  6. +3
    -7
      react-ui/src/pages/Pipeline/editPipeline/props.tsx

+ 1
- 1
react-ui/src/components/ParameterInput/index.tsx View File

@@ -29,7 +29,6 @@ function ParameterInput({
onClick, onClick,
canInput = true, canInput = true,
textArea = false, textArea = false,
placeholder,
allowClear, allowClear,
className, className,
style, style,
@@ -44,6 +43,7 @@ function ParameterInput({
} }
const isSelect = valueObj?.fromSelect; const isSelect = valueObj?.fromSelect;
const InputComponent = textArea ? Input.TextArea : Input; const InputComponent = textArea ? Input.TextArea : Input;
const placeholder = valueObj?.placeholder;


return ( return (
<> <>


+ 72
- 0
react-ui/src/components/ParameterSelect/config.tsx View File

@@ -0,0 +1,72 @@
import { getDatasetList, getModelList } from '@/services/dataset/index.js';
import { getComputingResourceReq } from '@/services/pipeline';
import { ComputingResource } from '@/types';
import { type SelectProps } from 'antd';

// 过滤资源规格
const filterResourceStandard: SelectProps<string, ComputingResource>['filterOption'] = (
input: string,
option?: ComputingResource,
) => {
return (
option?.computing_resource?.toLocaleLowerCase()?.includes(input.toLocaleLowerCase()) ?? false
);
};

// id 从 number 转换为 string
const convertId = (item: any) => ({ ...item, id: String(item.id) });

export type SelectPropsConfig = {
getOptions: () => Promise<any>;
fieldNames?: SelectProps['fieldNames'];
optionFilterProp?: SelectProps['optionFilterProp'];
filterOption?: SelectProps['filterOption'];
};

export const paramSelectConfig: Record<string, SelectPropsConfig> = {
dataset: {
getOptions: async () => {
const res = await getDatasetList({
page: 0,
size: 1000,
available_range: 0,
});
return res?.data?.content?.map(convertId) ?? [];
},
fieldNames: {
label: 'name',
value: 'id',
},
optionFilterProp: 'name',
},
model: {
getOptions: async () => {
const res = await getModelList({
page: 0,
size: 1000,
available_range: 0,
});
return res?.data?.content?.map(convertId) ?? [];
},
fieldNames: {
label: 'name',
value: 'id',
},
optionFilterProp: 'name',
},
resource: {
getOptions: async () => {
const res = await getComputingResourceReq({
page: 0,
size: 1000,
resource_type: '',
});
return res?.data?.content ?? [];
},
fieldNames: {
label: 'description',
value: 'standard',
},
filterOption: filterResourceStandard as SelectProps['filterOption'],
},
};

+ 0
- 0
react-ui/src/components/ParameterSelect/index.less View File


+ 10
- 74
react-ui/src/components/ParameterSelect/index.tsx View File

@@ -1,85 +1,20 @@
import { PipelineNodeModelParameter } from '@/types';
import { to } from '@/utils/promise'; import { to } from '@/utils/promise';
import { Select } from 'antd';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
// import styles from './index.less';
import { getDatasetList, getModelList } from '@/services/dataset/index.js';
import { getComputingResourceReq } from '@/services/pipeline';
import { ComputingResource, PipelineNodeModelParameter } from '@/types';
import { Select, type SelectProps } from 'antd';

// 过滤资源规格
const filterResourceStandard: SelectProps<string, ComputingResource>['filterOption'] = (
input: string,
option?: ComputingResource,
) => {
return (
option?.computing_resource?.toLocaleLowerCase()?.includes(input.toLocaleLowerCase()) ?? false
);
};

// id 从 number 转换为 string
const convertId = (item: any) => ({ ...item, id: String(item.id) });

type SelectPropsConfig = {
getOptions: () => Promise<any>;
fieldNames?: SelectProps['fieldNames'];
filterOption?: SelectProps['filterOption'];
};

const config: Record<string, SelectPropsConfig> = {
dataset: {
getOptions: async () => {
const res = await getDatasetList({
page: 0,
size: 1000,
available_range: 0,
});
return res?.data?.content?.map(convertId) ?? [];
},
fieldNames: {
label: 'name',
value: 'id',
},
},
model: {
getOptions: async () => {
const res = await getModelList({
page: 0,
size: 1000,
available_range: 0,
});
return res?.data?.content?.map(convertId) ?? [];
},
fieldNames: {
label: 'name',
value: 'id',
},
},
resource: {
getOptions: async () => {
const res = await getComputingResourceReq({
page: 0,
size: 1000,
resource_type: '',
});
return res?.data?.content ?? [];
},
fieldNames: {
label: 'description',
value: 'standard',
},
filterOption: filterResourceStandard as SelectProps['filterOption'],
},
};
import { paramSelectConfig } from './config';


type ParameterSelectProps = { type ParameterSelectProps = {
value?: PipelineNodeModelParameter; value?: PipelineNodeModelParameter;
onChange?: (value: PipelineNodeModelParameter) => void; onChange?: (value: PipelineNodeModelParameter) => void;
disabled?: boolean;
}; };


function ParameterSelect({ value, onChange }: ParameterSelectProps) {
function ParameterSelect({ value, onChange, disabled = false }: ParameterSelectProps) {
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
const valueNonNullable = value ?? ({} as PipelineNodeModelParameter); const valueNonNullable = value ?? ({} as PipelineNodeModelParameter);
const { item_type } = valueNonNullable; const { item_type } = valueNonNullable;
const propsConfig = paramSelectConfig[item_type];


useEffect(() => { useEffect(() => {
getSelectOptions(); getSelectOptions();
@@ -94,7 +29,6 @@ function ParameterSelect({ value, onChange }: ParameterSelectProps) {


// 获取下拉数据 // 获取下拉数据
const getSelectOptions = async () => { const getSelectOptions = async () => {
const propsConfig = config[item_type];
if (!propsConfig) { if (!propsConfig) {
return; return;
} }
@@ -108,11 +42,13 @@ function ParameterSelect({ value, onChange }: ParameterSelectProps) {
return ( return (
<Select <Select
placeholder={valueNonNullable.placeholder} placeholder={valueNonNullable.placeholder}
filterOption={config[item_type]?.filterOption}
filterOption={propsConfig?.filterOption}
options={options} options={options}
fieldNames={config[item_type]?.fieldNames}
fieldNames={propsConfig?.fieldNames}
value={valueNonNullable.value} value={valueNonNullable.value}
optionFilterProp={propsConfig.optionFilterProp}
onChange={hangleChange} onChange={hangleChange}
disabled={disabled}
showSearch showSearch
allowClear allowClear
/> />


+ 10
- 17
react-ui/src/pages/Experiment/components/ExperimentParameter/index.tsx View File

@@ -1,3 +1,5 @@
import ParameterInput from '@/components/ParameterInput';
import ParameterSelect from '@/components/ParameterSelect';
import SubAreaTitle from '@/components/SubAreaTitle'; import SubAreaTitle from '@/components/SubAreaTitle';
import { useComputingResource } from '@/hooks/resource'; import { useComputingResource } from '@/hooks/resource';
import { PipelineNodeModelSerialize } from '@/types'; import { PipelineNodeModelSerialize } from '@/types';
@@ -122,15 +124,8 @@ function ExperimentParameter({ form, nodeData }: ExperimentParameterProps) {
<TextArea disabled /> <TextArea disabled />
</Form.Item> </Form.Item>
{controlStrategyList.map((item) => ( {controlStrategyList.map((item) => (
<Form.Item
key={item.key}
name={['control_strategy', item.key]}
label={item.value.label}
getValueProps={(e) => {
return { value: e.showValue || e.value };
}}
>
<Input disabled />
<Form.Item key={item.key} name={['control_strategy', item.key]} label={item.value.label}>
<ParameterInput disabled />
</Form.Item> </Form.Item>
))} ))}
<div className={styles['experiment-parameter__title']}> <div className={styles['experiment-parameter__title']}>
@@ -142,11 +137,12 @@ function ExperimentParameter({ form, nodeData }: ExperimentParameterProps) {
name={['in_parameters', item.key]} name={['in_parameters', item.key]}
label={item.value.label + '(' + item.key + ')'} label={item.value.label + '(' + item.key + ')'}
rules={[{ required: item.value.require ? true : false }]} rules={[{ required: item.value.require ? true : false }]}
getValueProps={(e) => {
return { value: e.showValue || e.value };
}}
> >
<Input disabled />
{item.value.type === 'select' ? (
<ParameterSelect disabled />
) : (
<ParameterInput disabled />
)}
</Form.Item> </Form.Item>
))} ))}
<div className={styles['experiment-parameter__title']}> <div className={styles['experiment-parameter__title']}>
@@ -158,11 +154,8 @@ function ExperimentParameter({ form, nodeData }: ExperimentParameterProps) {
name={['out_parameters', item.key]} name={['out_parameters', item.key]}
label={item.value.label + '(' + item.key + ')'} label={item.value.label + '(' + item.key + ')'}
rules={[{ required: item.value.require ? true : false }]} rules={[{ required: item.value.require ? true : false }]}
getValueProps={(e) => {
return { value: e.showValue || e.value };
}}
> >
<Input disabled />
<ParameterInput disabled />
</Form.Item> </Form.Item>
))} ))}
</Form> </Form>


+ 3
- 7
react-ui/src/pages/Pipeline/editPipeline/props.tsx View File

@@ -388,7 +388,7 @@ const PipelineNodeParameter = forwardRef(({ onParentChange }: PipelineNodeParame
name={['control_strategy', item.key]} name={['control_strategy', item.key]}
label={getLabel(item, 'control_strategy')} label={getLabel(item, 'control_strategy')}
> >
<ParameterInput placeholder={item.value.placeholder} allowClear></ParameterInput>
<ParameterInput allowClear></ParameterInput>
</Form.Item> </Form.Item>
))} ))}
<div className={styles['pipeline-drawer__title']}> <div className={styles['pipeline-drawer__title']}>
@@ -409,11 +409,7 @@ const PipelineNodeParameter = forwardRef(({ onParentChange }: PipelineNodeParame
{item.value.type === 'select' ? ( {item.value.type === 'select' ? (
<ParameterSelect /> <ParameterSelect />
) : ( ) : (
<ParameterInput
placeholder={item.value.placeholder}
canInput={canInput(item.value)}
allowClear
></ParameterInput>
<ParameterInput canInput={canInput(item.value)} allowClear></ParameterInput>
)} )}
</Form.Item> </Form.Item>
{item.value.type === 'ref' && ( {item.value.type === 'ref' && (
@@ -442,7 +438,7 @@ const PipelineNodeParameter = forwardRef(({ onParentChange }: PipelineNodeParame
label={getLabel(item, 'out_parameters')} label={getLabel(item, 'out_parameters')}
rules={[{ required: item.value.require ? true : false }]} rules={[{ required: item.value.require ? true : false }]}
> >
<ParameterInput placeholder={item.value.placeholder} allowClear></ParameterInput>
<ParameterInput allowClear></ParameterInput>
</Form.Item> </Form.Item>
))} ))}
</Form> </Form>


Loading…
Cancel
Save