(props: EnvironmentSelectProps)
| 29 | }; |
| 30 | |
| 31 | export function EnvironmentSelect(props: EnvironmentSelectProps) { |
| 32 | const { t } = useTranslation(); |
| 33 | const environments = useEnvironmentList(); |
| 34 | const renderSuffix = !props.multiple ? props.renderSuffix : undefined; |
| 35 | |
| 36 | const options = useMemo( |
| 37 | () => |
| 38 | environments.map((env) => ({ |
| 39 | value: formatEnvironmentName(env.id), |
| 40 | label: env.title, |
| 41 | render: () => ( |
| 42 | <div className="flex flex-col gap-0.5"> |
| 43 | <div className="flex items-center gap-x-1"> |
| 44 | <EnvironmentLabel environment={env} /> |
| 45 | {renderSuffix?.(env)} |
| 46 | </div> |
| 47 | <span className="text-xs text-control-placeholder"> |
| 48 | {formatEnvironmentName(env.id)} |
| 49 | </span> |
| 50 | </div> |
| 51 | ), |
| 52 | })), |
| 53 | [environments, renderSuffix] |
| 54 | ); |
| 55 | |
| 56 | const placeholder = props.placeholder ?? t("environment.select"); |
| 57 | const clearable = props.clearable ?? true; |
| 58 | |
| 59 | if (props.multiple) { |
| 60 | return ( |
| 61 | <Combobox |
| 62 | multiple |
| 63 | value={props.value} |
| 64 | onChange={props.onChange} |
| 65 | placeholder={placeholder} |
| 66 | noResultsText={t("common.no-data")} |
| 67 | disabled={props.disabled} |
| 68 | className={props.className} |
| 69 | portal={props.portal} |
| 70 | clearable={clearable} |
| 71 | options={options} |
| 72 | /> |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | return ( |
| 77 | <Combobox |
| 78 | value={props.value} |
| 79 | onChange={props.onChange} |
| 80 | placeholder={placeholder} |
| 81 | noResultsText={t("common.no-data")} |
| 82 | disabled={props.disabled} |
| 83 | className={props.className} |
| 84 | portal={props.portal} |
| 85 | clearable={clearable} |
| 86 | renderValue={(opt) => { |
| 87 | const env = environments.find( |
| 88 | (e) => formatEnvironmentName(e.id) === opt.value |
nothing calls this directly
no test coverage detected