mirror of
https://github.com/portainer/portainer.git
synced 2025-07-22 23:09:41 +02:00
refactor(app): placement form section [EE-6386] (#10818)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Co-authored-by: testa113 <testa113>
This commit is contained in:
parent
2d77e71085
commit
9fc7187e24
16 changed files with 349 additions and 220 deletions
|
@ -0,0 +1,76 @@
|
|||
import clsx from 'clsx';
|
||||
|
||||
import { ItemProps } from '@@/form-components/InputList';
|
||||
import { Select } from '@@/form-components/ReactSelect';
|
||||
import { isErrorType } from '@@/form-components/formikUtils';
|
||||
import { FormError } from '@@/form-components/FormError';
|
||||
|
||||
import { NodeLabels, Placement } from './types';
|
||||
|
||||
interface PlacementItemProps extends ItemProps<Placement> {
|
||||
nodesLabels: NodeLabels;
|
||||
availableNodeLabels: NodeLabels;
|
||||
}
|
||||
|
||||
export function PlacementItem({
|
||||
onChange,
|
||||
item,
|
||||
error,
|
||||
index,
|
||||
nodesLabels,
|
||||
availableNodeLabels,
|
||||
}: PlacementItemProps) {
|
||||
const labelOptions = Object.keys(availableNodeLabels).map((label) => ({
|
||||
label,
|
||||
value: label,
|
||||
}));
|
||||
const valueOptions = nodesLabels[item.label]?.map((value) => ({
|
||||
label: value,
|
||||
value,
|
||||
}));
|
||||
const placementError = isErrorType(error) ? error : undefined;
|
||||
return (
|
||||
<div className="w-full">
|
||||
<div className="flex w-full gap-2">
|
||||
<div className="basis-1/2 grow">
|
||||
<Select
|
||||
options={labelOptions}
|
||||
value={{ label: item.label, value: item.label }}
|
||||
noOptionsMessage={() => 'No available node labels.'}
|
||||
onChange={(labelOption) => {
|
||||
const newValues = nodesLabels[labelOption?.value || ''];
|
||||
onChange({
|
||||
...item,
|
||||
value: newValues?.[0] || '',
|
||||
label: labelOption?.value || '',
|
||||
});
|
||||
}}
|
||||
size="sm"
|
||||
className={clsx({ striked: !!item.needsDeletion })}
|
||||
isDisabled={!!item.needsDeletion}
|
||||
data-cy={`k8sAppCreate-placementLabel_${index}`}
|
||||
/>
|
||||
{placementError?.label && (
|
||||
<FormError>{placementError.label}</FormError>
|
||||
)}
|
||||
</div>
|
||||
<div className="basis-1/2 grow">
|
||||
<Select
|
||||
options={valueOptions}
|
||||
value={valueOptions?.find((option) => option.value === item.value)}
|
||||
onChange={(valueOption) =>
|
||||
onChange({ ...item, value: valueOption?.value || '' })
|
||||
}
|
||||
size="sm"
|
||||
className={clsx({ striked: !!item.needsDeletion })}
|
||||
isDisabled={!!item.needsDeletion}
|
||||
data-cy={`k8sAppCreate-placementName_${index}`}
|
||||
/>
|
||||
{placementError?.value && (
|
||||
<FormError>{placementError.value}</FormError>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue