Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { EnvironmentLabel } from "@/components/EnvironmentLabel";
import { HighlightLabelText } from "@/components/HighlightLabelText";
import { Combobox } from "@/components/ui/combobox";
import { useEnvironmentList } from "@/hooks/useAppState";
import { formatEnvironmentName } from "@/types";
import type { Environment } from "@/types/v1/environment";
interface SingleProps {
multiple?: false;
value: string;
onChange: (value: string) => void;
}
interface MultiProps {
multiple: true;
value: string[];
onChange: (values: string[]) => void;
}
export type EnvironmentSelectProps = (SingleProps | MultiProps) & {
placeholder?: string;
disabled?: boolean;
className?: string;
portal?: boolean;
clearable?: boolean;
/**
* Extra content rendered next to the environment in every option row, and
* in the single-select trigger beside the selected value.
*/
renderSuffix?: (environment: Environment) => React.ReactNode;
};
export function EnvironmentSelect(props: EnvironmentSelectProps) {
const { t } = useTranslation();
const environments = useEnvironmentList();
const renderSuffix = props.renderSuffix;
const options = useMemo(
() =>
environments.map((env) => ({
value: formatEnvironmentName(env.id),
label: env.title,
render: (keyword: string) => (
<div className="flex flex-col gap-1">
<div className="flex items-center gap-x-1">
<EnvironmentLabel environment={env} keyword={keyword} />
{renderSuffix?.(env)}
</div>
<HighlightLabelText
text={formatEnvironmentName(env.id)}
keyword={keyword}
className="text-xs text-control-placeholder"
/>
</div>
),
})),
[environments, renderSuffix]
);
const placeholder = props.placeholder ?? t("environment.select");
const clearable = props.clearable ?? true;
if (props.multiple) {
return (
<Combobox
multiple
value={props.value}
onChange={props.onChange}
placeholder={placeholder}
noResultsText={t("common.no-data")}
disabled={props.disabled}
className={props.className}
portal={props.portal}
clearable={clearable}
options={options}
/>
);
}
return (
<Combobox
value={props.value}
onChange={props.onChange}
placeholder={placeholder}
noResultsText={t("common.no-data")}
disabled={props.disabled}
className={props.className}
portal={props.portal}
clearable={clearable}
renderValue={(opt) => {
const env = environments.find(
(e) => formatEnvironmentName(e.id) === opt.value
);
if (!env) return opt.label;
return (
<div className="flex items-center gap-x-1">
<EnvironmentLabel environment={env} />
{renderSuffix?.(env)}
</div>
);
}}
options={options}
/>
);
}