import { Select } from '@/ui/input/components/Select'; import { SelectControl } from '@/ui/input/components/SelectControl'; import { TextArea } from '@/ui/input/components/TextArea'; import { TextInput } from '@/ui/input/components/TextInput'; import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown'; import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent'; import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer'; import { styled } from '@linaria/react'; import { t } from '@lingui/core/macro'; import { type ConfigVariableValue } from 'twenty-shared/types'; import { CustomError } from 'twenty-shared/utils'; import { CodeEditor } from 'twenty-ui/input'; import { MenuItemMultiSelect } from 'twenty-ui/navigation'; import { themeCssVariables } from 'twenty-ui/theme-constants'; import { ConfigVariableType } from '~/generated-metadata/graphql'; import { type ConfigVariableOptions } from '@/settings/admin-panel/config-variables/types/ConfigVariableOptions'; const StyledJsonEditorContainer = styled.div` display: flex; flex-direction: column; width: 100%; `; const StyledJsonEditorLabel = styled.span` color: ${themeCssVariables.font.color.light}; display: block; font-size: ${themeCssVariables.font.size.xs}; font-weight: ${themeCssVariables.font.weight.semiBold}; margin-bottom: ${themeCssVariables.spacing[1]}; `; type ConfigVariableDatabaseInputProps = { label: string; value: ConfigVariableValue; onChange: (value: ConfigVariableValue) => void; type: ConfigVariableType; options?: ConfigVariableOptions; disabled?: boolean; placeholder?: string; }; export const ConfigVariableDatabaseInput = ({ label, value, onChange, type, options, disabled, placeholder, }: ConfigVariableDatabaseInputProps) => { const selectOptions = options && Array.isArray(options) ? options.map((option) => ({ value: String(option), label: String(option), })) : []; const booleanOptions = [ { value: 'true', label: 'true' }, { value: 'false', label: 'false' }, ]; const isValueSelected = (optionValue: string) => { if (!Array.isArray(value)) return false; return value.includes(optionValue); }; const handleMultiSelectChange = (optionValue: string) => { if (!Array.isArray(value)) return; let newValues = [...value]; if (isValueSelected(optionValue)) { newValues = newValues.filter((val) => val !== optionValue); } else { newValues.push(optionValue); } onChange(newValues); }; const jsonArrayTextAreaId = `${label}-json-array`; switch (type) { case ConfigVariableType.BOOLEAN: return (