export function SupportedProviders()

in aws-core-ui/src/App/SupportedProviders.tsx [19:56]


export function SupportedProviders({
  reset,
}: {
  reset?: (ind: number, label: string) => void;
}) {
  const { config, isEditMode } = useApplicationContext();
  const { control } = useFormContext<FormFields>();
  const { providers, loading, error } = useSupportedProvidersContext();

  const handleSelect = React.useCallback(
    (option: SelectItem | null) => {
      let ind = 0;
      const label = option?.label ?? '';
      if (option) {
        ind = providers.findIndex((e) => e.key === option.key);
        ind = ind < 0 ? 0 : ind;
      }
      reset?.(ind + 1, label.toString()); // +1 because of the first element is the default one, and it is not visible in the list
    },
    [providers, reset]
  );

  return (
    <FormRow label="Connection type:">
      <FormSelect
        name={FormFieldsNames.PROVIDER_TYPE}
        control={control}
        loading={loading}
        data={providers}
        error={error}
        size={Size.L}
        disabled={isEditMode || config.disableTypeSelection === true}
        popupClassName={styles.dropDownPopup}
        onSelect={handleSelect}
      />
    </FormRow>
  );
}