fix: select a useable instance type for initial
This commit is contained in:
@@ -200,9 +200,13 @@ const AddModal: React.FC<AddModalProps> = ({
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!instanceTypes.length) return;
|
||||
|
||||
const first = instanceTypes[0];
|
||||
const first = instanceTypes.find((item) => !item.disabled);
|
||||
|
||||
if (!first) return;
|
||||
|
||||
// On create, auto-select the first instance type in the list
|
||||
|
||||
const template = findTemplateByManufacturer(
|
||||
first.spec?.manufacturer,
|
||||
templates
|
||||
|
||||
@@ -33,11 +33,21 @@ const InstanceTypeList: React.FC<InstanceTypeListProps> = ({
|
||||
dataList = [],
|
||||
loading
|
||||
}) => {
|
||||
const handleSelect = (item: InstanceTypeItemModel) => {
|
||||
if (!isAvailable(item) || value === item.name) return;
|
||||
const handleSelect = (
|
||||
item: InstanceTypeItemModel & { disabled?: boolean }
|
||||
) => {
|
||||
if (item.disabled || value === item.name) return;
|
||||
onChange?.(item);
|
||||
};
|
||||
|
||||
const filterList = dataList.map((item) => {
|
||||
const available = isAvailable(item);
|
||||
return {
|
||||
...item,
|
||||
disabled: !available
|
||||
};
|
||||
});
|
||||
|
||||
if (!dataList.length) {
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -55,8 +65,7 @@ const InstanceTypeList: React.FC<InstanceTypeListProps> = ({
|
||||
|
||||
return (
|
||||
<TypeGrid>
|
||||
{dataList.map((item) => {
|
||||
const disabled = !isAvailable(item);
|
||||
{filterList.map((item) => {
|
||||
const name = item.name;
|
||||
return (
|
||||
<TemplateCard
|
||||
@@ -66,7 +75,7 @@ const InstanceTypeList: React.FC<InstanceTypeListProps> = ({
|
||||
hoverable
|
||||
height={106}
|
||||
active={value === name}
|
||||
disabled={disabled}
|
||||
disabled={item.disabled}
|
||||
onClick={() => handleSelect(item)}
|
||||
>
|
||||
<InstanceTypeItem item={item} />
|
||||
|
||||
@@ -131,6 +131,7 @@ export interface InstanceTypeStatus {
|
||||
export interface InstanceTypeItem {
|
||||
name: string;
|
||||
spec: InstanceTypeSpec;
|
||||
disabled?: boolean;
|
||||
status: InstanceTypeStatus;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user