1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 05:49:40 +02:00
portainer/app/react/kubernetes/applications/components/PlacementFormSection/PlacementItem.tsx
Ali d38085a560
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux version:]) (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:arm platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:ppc64le platform:linux version:]) (push) Waiting to run
ci / build_images (map[arch:s390x platform:linux version:]) (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
chore(data-cy): require data-cy attributes [EE-6880] (#11453)
2024-04-11 12:11:38 +12:00

76 lines
2.4 KiB
TypeScript

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="grow basis-1/2">
<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="grow basis-1/2">
<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>
);
}