fix: use image label in inputbox
This commit is contained in:
@@ -29,6 +29,7 @@ export const regionOSImageListAtom = atom<
|
|||||||
{
|
{
|
||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
os_image: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
vendor: string;
|
vendor: string;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import React, {
|
|||||||
} from 'react';
|
} from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { ProviderType, instanceTypeFieldMap, vendorIconMap } from '../config';
|
import { ProviderType, instanceTypeFieldMap, vendorIconMap } from '../config';
|
||||||
import { useStepsContext } from '../config/steps-context';
|
|
||||||
import { NodePoolFormData as FormData } from '../config/types';
|
import { NodePoolFormData as FormData } from '../config/types';
|
||||||
import VolumesConfig from './volumes-config';
|
import VolumesConfig from './volumes-config';
|
||||||
|
|
||||||
@@ -172,7 +171,6 @@ const PoolForm: React.FC<AddModalProps> = forwardRef((props, ref) => {
|
|||||||
currentData,
|
currentData,
|
||||||
collapseProps
|
collapseProps
|
||||||
} = props;
|
} = props;
|
||||||
const { formValues } = useStepsContext();
|
|
||||||
const [instanceTypeList] = useAtom(regionInstanceTypeListAtom);
|
const [instanceTypeList] = useAtom(regionInstanceTypeListAtom);
|
||||||
const [osImageList] = useAtom(regionOSImageListAtom);
|
const [osImageList] = useAtom(regionOSImageListAtom);
|
||||||
const { collapsible, onToggle, ...restCollapseProps } = collapseProps || {};
|
const { collapsible, onToggle, ...restCollapseProps } = collapseProps || {};
|
||||||
@@ -185,45 +183,42 @@ const PoolForm: React.FC<AddModalProps> = forwardRef((props, ref) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentData) {
|
if (currentData) {
|
||||||
|
// when change the region, shoudle check the instance type and the os Image.
|
||||||
|
const selectOSImage = osImageList.find(
|
||||||
|
(item) => item.os_image === currentData.os_image
|
||||||
|
);
|
||||||
|
const selectInstanceType = instanceTypeList.find(
|
||||||
|
(item) => item.value === currentData.instance_type
|
||||||
|
);
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
...currentData
|
...currentData,
|
||||||
|
instance_type: selectInstanceType?.value || '',
|
||||||
|
os_image: selectOSImage?.os_image || '',
|
||||||
|
image_name: selectOSImage?.value || ''
|
||||||
});
|
});
|
||||||
setInstanceSpec({
|
|
||||||
...currentData.instance_spec
|
setInstanceSpec(() => {
|
||||||
|
return selectInstanceType ? currentData.instance_spec : {};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [currentData]);
|
}, [currentData, instanceTypeList, osImageList]);
|
||||||
|
|
||||||
const imageList = useMemo(() => {
|
const imageList = useMemo(() => {
|
||||||
if (instanceSpec.count === 8) {
|
if (instanceSpec.count === 8) {
|
||||||
return osImageList.filter((item) => item.value === 'gpu-h100x8-base');
|
return osImageList.filter((item) => item.os_image === 'gpu-h100x8-base');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (instanceSpec.count === 1 && instanceSpec.vendor === 'amd') {
|
||||||
|
return osImageList.filter((item) => item.os_image === 'gpu-amd-base');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instanceSpec.count === 1 && instanceSpec.vendor === 'nvidia') {
|
||||||
|
return osImageList.filter((item) => item.os_image === 'gpu-h100x1-base');
|
||||||
|
}
|
||||||
|
|
||||||
return osImageList;
|
return osImageList;
|
||||||
}, [osImageList, instanceSpec]);
|
}, [osImageList, instanceSpec]);
|
||||||
|
|
||||||
const imageLabelRender = (data: {
|
|
||||||
label: React.ReactNode;
|
|
||||||
value: string | number;
|
|
||||||
}) => {
|
|
||||||
if (action === PageAction.EDIT) {
|
|
||||||
const vendor = _.split(currentData?.image_name || '', ' ')[0];
|
|
||||||
const iconType = _.get(vendorIconMap, vendor.toLowerCase());
|
|
||||||
return (
|
|
||||||
<div className="flex-center gap-8">
|
|
||||||
{iconType && <IconFont type={iconType}></IconFont>}
|
|
||||||
{currentData?.image_name || currentData?.os_image}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const selectImage = osImageList.find((item) => item.value === data.value);
|
|
||||||
if (selectImage) {
|
|
||||||
return (
|
|
||||||
<RenderLabel label={data.label} vendor={selectImage.vendor || ''} />
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return data.value;
|
|
||||||
};
|
|
||||||
|
|
||||||
const instanceLabelRender = (data: {
|
const instanceLabelRender = (data: {
|
||||||
label: React.ReactNode;
|
label: React.ReactNode;
|
||||||
value: string | number;
|
value: string | number;
|
||||||
@@ -231,6 +226,10 @@ const PoolForm: React.FC<AddModalProps> = forwardRef((props, ref) => {
|
|||||||
const currentInstanceSpec =
|
const currentInstanceSpec =
|
||||||
instanceTypeList.find((item) => item.value === data.value) ||
|
instanceTypeList.find((item) => item.value === data.value) ||
|
||||||
instanceSpec;
|
instanceSpec;
|
||||||
|
|
||||||
|
if (!currentInstanceSpec || _.isEmpty(currentInstanceSpec)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<RenderLabel
|
<RenderLabel
|
||||||
label={data.label || currentInstanceSpec?.label || data.value}
|
label={data.label || currentInstanceSpec?.label || data.value}
|
||||||
@@ -239,10 +238,9 @@ const PoolForm: React.FC<AddModalProps> = forwardRef((props, ref) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOsImageChange = (value: string) => {
|
const handleOsImageChange = (value: string, option: any) => {
|
||||||
form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
image_name:
|
os_image: option.os_image || value
|
||||||
osImageList.find((item) => item.value === value)?.label || value
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -405,7 +403,7 @@ const PoolForm: React.FC<AddModalProps> = forwardRef((props, ref) => {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<Form.Item<FormData>
|
<Form.Item<FormData>
|
||||||
name="os_image"
|
name="image_name"
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
@@ -423,8 +421,6 @@ const PoolForm: React.FC<AddModalProps> = forwardRef((props, ref) => {
|
|||||||
styles: { header: { marginBlock: 5 } }
|
styles: { header: { marginBlock: 5 } }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
labelRender={imageLabelRender}
|
|
||||||
placeholder={currentData?.image_name}
|
|
||||||
options={imageList}
|
options={imageList}
|
||||||
disabled={action === PageAction.EDIT}
|
disabled={action === PageAction.EDIT}
|
||||||
label={intl.formatMessage({
|
label={intl.formatMessage({
|
||||||
@@ -465,7 +461,7 @@ const PoolForm: React.FC<AddModalProps> = forwardRef((props, ref) => {
|
|||||||
></LabelSelector>
|
></LabelSelector>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<VolumesConfig disabled={action === PageAction.EDIT}></VolumesConfig>
|
<VolumesConfig disabled={action === PageAction.EDIT}></VolumesConfig>
|
||||||
<Form.Item<FormData> name="image_name" hidden>
|
<Form.Item<FormData> name="os_image" hidden>
|
||||||
<SealInput.Input></SealInput.Input>
|
<SealInput.Input></SealInput.Input>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<InstanceSpecData instanceSpec={instanceSpec} />
|
<InstanceSpecData instanceSpec={instanceSpec} />
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { createContext, useContext } from 'react';
|
||||||
|
|
||||||
|
export interface StepsContextProps {
|
||||||
|
formValues: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const StepsContext = createContext<StepsContextProps>({
|
||||||
|
formValues: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
export const useStepsContext = () => useContext(StepsContext);
|
||||||
@@ -151,7 +151,8 @@ export const useProviderRegions = () => {
|
|||||||
.map((item: any) => {
|
.map((item: any) => {
|
||||||
return {
|
return {
|
||||||
label: item.description,
|
label: item.description,
|
||||||
value: item.slug,
|
value: item.description,
|
||||||
|
os_image: item.slug,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
vendor: _.camelCase(item.distribution),
|
vendor: _.camelCase(item.distribution),
|
||||||
|
|||||||
Reference in New Issue
Block a user