Handle empty values for boolean form field (#14884)
This PR uses a select component instead of `BooleanInput` for boolean form fields. This makes it clear that the default value is `undefined`. ## Before https://github.com/user-attachments/assets/84061638-0ba0-4f79-965e-90517d45aa3e ## After https://github.com/user-attachments/assets/cdbcf935-5c5b-46d1-a1cc-110670b460ee Fixes https://github.com/twentyhq/twenty/issues/14851
This commit is contained in:
committed by
GitHub
parent
f6240fabd0
commit
6b463736cc
@@ -6665,6 +6665,11 @@ msgstr "Kies 'n veld uit 'n vorige stap"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Kies 'n doelagent"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "اختر حقلًا من خطوة سابقة"
|
||||
msgid "Select a target agent"
|
||||
msgstr "اختر وكيل مستهدف"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Seleccioneu un camp d'un pas anterior"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Selecciona un agent objectiu"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Vyberte pole z předchozího kroku"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Vyberte cílového agenta"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Vælg et felt fra et tidligere trin"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Vælg en målagent"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Wählen Sie ein Feld aus einem vorherigen Schritt aus"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Zielagenten auswählen"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Επιλέξτε ένα πεδίο από το προηγούμενο β
|
||||
msgid "Select a target agent"
|
||||
msgstr "Επιλέξτε έναν στόχο πράκτορα"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6660,6 +6660,11 @@ msgstr "Select a field from a previous step"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Select a target agent"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr "Select a value"
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Seleccione un campo de un paso anterior"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Seleccionar un agente objetivo"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Valitse kenttä aiemmasta vaiheesta"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Valitse kohdeagentti"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Sélectionner un champ à partir d'une étape précédente"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Sélectionner un agent cible"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -6665,6 +6665,11 @@ msgstr "בחר שדה משלב קודם"
|
||||
msgid "Select a target agent"
|
||||
msgstr "בחר סוכן יעד"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Válasszon ki egy mezőt egy előző lépésből"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Célügynök kiválasztása"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Seleziona un campo da un passaggio precedente"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Seleziona un agente di destinazione"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "前のステップからフィールドを選択してください"
|
||||
msgid "Select a target agent"
|
||||
msgstr "ターゲットエージェントを選択"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "이전 단계에서 필드를 선택하십시오"
|
||||
msgid "Select a target agent"
|
||||
msgstr "대상 에이전트 선택"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Selecteer een veld uit een vorige stap"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Selecteer een doelsysteem"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Velg et felt fra et tidligere trinn"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Velg en målagent"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Wybierz pole z poprzedniego kroku"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Wybierz docelowego agenta"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6660,6 +6660,11 @@ msgstr ""
|
||||
msgid "Select a target agent"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Selecione um campo de uma etapa anterior"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Selecione um agente alvo"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Selecione um campo de uma etapa anterior"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Selecionar um agente alvo"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Selectați un câmp dintr-un pas anterior"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Selectați un agent țintă"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
Binary file not shown.
@@ -6665,6 +6665,11 @@ msgstr "Изаберите поље из претходног корака"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Изаберите циљног агента"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6669,6 +6669,11 @@ msgstr "Välj ett fält från ett tidigare steg"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Välj en målagent"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Önceki adımda bir alan seçin"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Hedef Temsilciyi Seç"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Виберіть поле з попереднього кроку"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Виберіть цільового агента"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "Chọn một trường từ một bước trước đó"
|
||||
msgid "Select a target agent"
|
||||
msgstr "Chọn một tác nhân mục tiêu"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "从上一步选择一个字段"
|
||||
msgid "Select a target agent"
|
||||
msgstr "选择目标代理"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
@@ -6665,6 +6665,11 @@ msgstr "從之前的步驟中選擇一個字段"
|
||||
msgid "Select a target agent"
|
||||
msgstr "選擇目標代理"
|
||||
|
||||
#. js-lingui-id: jL3gox
|
||||
#: src/modules/object-record/record-field/ui/form-types/components/FormBooleanFieldInput.tsx
|
||||
msgid "Select a value"
|
||||
msgstr ""
|
||||
|
||||
#. js-lingui-id: YcJS1T
|
||||
#: src/modules/command-menu/hooks/useWorkflowCommandMenu.ts
|
||||
#: src/modules/command-menu/hooks/__tests__/useWorkflowCommandMenu.test.tsx
|
||||
|
||||
+72
-28
@@ -3,16 +3,16 @@ import { FormFieldInputInnerContainer } from '@/object-record/record-field/ui/fo
|
||||
import { FormFieldInputRowContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputRowContainer';
|
||||
import { VariableChipStandalone } from '@/object-record/record-field/ui/form-types/components/VariableChipStandalone';
|
||||
import { type VariablePickerComponent } from '@/object-record/record-field/ui/form-types/types/VariablePickerComponent';
|
||||
import { BooleanInput } from '@/ui/field/input/components/BooleanInput';
|
||||
import { InputLabel } from '@/ui/input/components/InputLabel';
|
||||
import { Select } from '@/ui/input/components/Select';
|
||||
import { GenericDropdownContentWidth } from '@/ui/layout/dropdown/constants/GenericDropdownContentWidth';
|
||||
import { useRemoveFocusItemFromFocusStackById } from '@/ui/utilities/focus/hooks/useRemoveFocusItemFromFocusStackById';
|
||||
import { isStandaloneVariableString } from '@/workflow/utils/isStandaloneVariableString';
|
||||
import styled from '@emotion/styled';
|
||||
import { useTheme } from '@emotion/react';
|
||||
import { useLingui } from '@lingui/react/macro';
|
||||
import { useId, useState } from 'react';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
const StyledBooleanInputContainer = styled.div`
|
||||
padding-inline: ${({ theme }) => theme.spacing(2)};
|
||||
`;
|
||||
import { IconCheck, IconCircleOff, IconX } from 'twenty-ui/display';
|
||||
|
||||
type FormBooleanFieldInputProps = {
|
||||
label?: string;
|
||||
@@ -22,6 +22,22 @@ type FormBooleanFieldInputProps = {
|
||||
readonly?: boolean;
|
||||
};
|
||||
|
||||
const parseStringifiedBooleanToBoolean = (value: string) => {
|
||||
if (value === 'true') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
const castBooleanToStringifiedBoolean = (value: boolean | undefined) => {
|
||||
if (value === undefined) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return value ? 'true' : 'false';
|
||||
};
|
||||
|
||||
export const FormBooleanFieldInput = ({
|
||||
label,
|
||||
defaultValue,
|
||||
@@ -29,12 +45,19 @@ export const FormBooleanFieldInput = ({
|
||||
readonly,
|
||||
VariablePicker,
|
||||
}: FormBooleanFieldInputProps) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useLingui();
|
||||
|
||||
const instanceId = useId();
|
||||
|
||||
const { removeFocusItemFromFocusStackById } =
|
||||
useRemoveFocusItemFromFocusStackById();
|
||||
|
||||
const [draftValue, setDraftValue] = useState<
|
||||
| {
|
||||
type: 'static';
|
||||
value: boolean;
|
||||
value: boolean | undefined;
|
||||
editingMode: 'view' | 'edit';
|
||||
}
|
||||
| {
|
||||
type: 'variable';
|
||||
@@ -48,17 +71,29 @@ export const FormBooleanFieldInput = ({
|
||||
}
|
||||
: {
|
||||
type: 'static',
|
||||
value: Boolean(defaultValue),
|
||||
value: defaultValue,
|
||||
editingMode: 'view',
|
||||
},
|
||||
);
|
||||
|
||||
const handleChange = (newValue: boolean) => {
|
||||
const defaultEmptyOption = {
|
||||
label: t`Select a value`,
|
||||
value: '',
|
||||
icon: IconCircleOff,
|
||||
};
|
||||
|
||||
const onSelect = (option: string) => {
|
||||
const optionAsBoolean = parseStringifiedBooleanToBoolean(option);
|
||||
|
||||
setDraftValue({
|
||||
type: 'static',
|
||||
value: newValue,
|
||||
value: optionAsBoolean,
|
||||
editingMode: 'view',
|
||||
});
|
||||
|
||||
onChange(newValue);
|
||||
removeFocusItemFromFocusStackById({ focusId: instanceId });
|
||||
|
||||
onChange(optionAsBoolean);
|
||||
};
|
||||
|
||||
const handleVariableTagInsert = (variableName: string) => {
|
||||
@@ -74,6 +109,7 @@ export const FormBooleanFieldInput = ({
|
||||
setDraftValue({
|
||||
type: 'static',
|
||||
value: false,
|
||||
editingMode: 'view',
|
||||
});
|
||||
|
||||
onChange(false);
|
||||
@@ -84,32 +120,40 @@ export const FormBooleanFieldInput = ({
|
||||
{label ? <InputLabel>{label}</InputLabel> : null}
|
||||
|
||||
<FormFieldInputRowContainer>
|
||||
<FormFieldInputInnerContainer
|
||||
formFieldInputInstanceId={instanceId}
|
||||
hasRightElement={isDefined(VariablePicker) && !readonly}
|
||||
>
|
||||
{draftValue.type === 'static' ? (
|
||||
<StyledBooleanInputContainer>
|
||||
<BooleanInput
|
||||
value={draftValue.value}
|
||||
readonly={readonly}
|
||||
onToggle={handleChange}
|
||||
/>
|
||||
</StyledBooleanInputContainer>
|
||||
) : (
|
||||
{draftValue.type === 'static' ? (
|
||||
<Select
|
||||
dropdownId={`${instanceId}-select-display`}
|
||||
options={[
|
||||
{ label: 'True', value: 'true', Icon: IconCheck },
|
||||
{ label: 'False', value: 'false', Icon: IconX },
|
||||
]}
|
||||
value={castBooleanToStringifiedBoolean(draftValue.value)}
|
||||
onChange={onSelect}
|
||||
emptyOption={defaultEmptyOption}
|
||||
fullWidth
|
||||
hasRightElement={isDefined(VariablePicker) && !readonly}
|
||||
disabled={readonly}
|
||||
dropdownWidth={GenericDropdownContentWidth.ExtraLarge}
|
||||
dropdownOffset={{ y: parseInt(theme.spacing(1), 10) }}
|
||||
/>
|
||||
) : (
|
||||
<FormFieldInputInnerContainer
|
||||
formFieldInputInstanceId={instanceId}
|
||||
hasRightElement={isDefined(VariablePicker) && !readonly}
|
||||
>
|
||||
<VariableChipStandalone
|
||||
rawVariableName={draftValue.value}
|
||||
onRemove={readonly ? undefined : handleUnlinkVariable}
|
||||
/>
|
||||
)}
|
||||
</FormFieldInputInnerContainer>
|
||||
</FormFieldInputInnerContainer>
|
||||
)}
|
||||
|
||||
{VariablePicker && !readonly ? (
|
||||
{isDefined(VariablePicker) && !readonly && (
|
||||
<VariablePicker
|
||||
instanceId={instanceId}
|
||||
onVariableSelect={handleVariableTagInsert}
|
||||
/>
|
||||
) : null}
|
||||
)}
|
||||
</FormFieldInputRowContainer>
|
||||
</FormFieldInputContainer>
|
||||
);
|
||||
|
||||
+100
-2
@@ -1,5 +1,9 @@
|
||||
import { type Meta, type StoryObj } from '@storybook/react';
|
||||
import { expect, userEvent, within } from '@storybook/test';
|
||||
import { expect, fn, userEvent, waitFor, within } from '@storybook/test';
|
||||
import { getCanvasElementForDropdownTesting } from 'twenty-ui/testing';
|
||||
import { I18nFrontDecorator } from '~/testing/decorators/I18nFrontDecorator';
|
||||
import { WorkflowStepDecorator } from '~/testing/decorators/WorkflowStepDecorator';
|
||||
import { MOCKED_STEP_ID } from '~/testing/mock-data/workflow';
|
||||
import { FormBooleanFieldInput } from '../FormBooleanFieldInput';
|
||||
|
||||
const meta: Meta<typeof FormBooleanFieldInput> = {
|
||||
@@ -7,6 +11,7 @@ const meta: Meta<typeof FormBooleanFieldInput> = {
|
||||
component: FormBooleanFieldInput,
|
||||
args: {},
|
||||
argTypes: {},
|
||||
decorators: [WorkflowStepDecorator, I18nFrontDecorator],
|
||||
};
|
||||
|
||||
export default meta;
|
||||
@@ -18,7 +23,7 @@ export const Default: Story = {
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
await canvas.findByText('False');
|
||||
await canvas.findByText('Select a value');
|
||||
},
|
||||
};
|
||||
|
||||
@@ -33,6 +38,17 @@ export const WithLabel: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
export const EmptyByDefault: Story = {
|
||||
args: {
|
||||
defaultValue: undefined,
|
||||
},
|
||||
play: async ({ canvasElement }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
await canvas.findByText('Select a value');
|
||||
},
|
||||
};
|
||||
|
||||
export const TrueByDefault: Story = {
|
||||
args: {
|
||||
defaultValue: true,
|
||||
@@ -88,3 +104,85 @@ export const Disabled: Story = {
|
||||
expect(variablePicker).not.toBeInTheDocument();
|
||||
},
|
||||
};
|
||||
|
||||
export const ChangesValueToTrue: Story = {
|
||||
args: {
|
||||
defaultValue: undefined,
|
||||
label: 'Boolean',
|
||||
onChange: fn(),
|
||||
},
|
||||
play: async ({ canvasElement, args }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
const select = await canvas.findByText('Select a value');
|
||||
|
||||
await userEvent.click(select);
|
||||
|
||||
const trueOption = await within(
|
||||
getCanvasElementForDropdownTesting(),
|
||||
).findByText('True');
|
||||
|
||||
await userEvent.click(trueOption);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(args.onChange).toHaveBeenCalledWith(true);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export const ChangesValueToFalse: Story = {
|
||||
args: {
|
||||
defaultValue: undefined,
|
||||
label: 'Boolean',
|
||||
onChange: fn(),
|
||||
},
|
||||
play: async ({ canvasElement, args }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
const select = await canvas.findByText('Select a value');
|
||||
|
||||
await userEvent.click(select);
|
||||
|
||||
const falseOption = await within(
|
||||
getCanvasElementForDropdownTesting(),
|
||||
).findByText('False');
|
||||
|
||||
await userEvent.click(falseOption);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(args.onChange).toHaveBeenCalledWith(false);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export const ChangesValueToVariable: Story = {
|
||||
args: {
|
||||
defaultValue: undefined,
|
||||
label: 'Boolean',
|
||||
VariablePicker: ({ onVariableSelect }) => {
|
||||
return (
|
||||
<button
|
||||
onClick={() => {
|
||||
onVariableSelect(`{{${MOCKED_STEP_ID}.name}}`);
|
||||
}}
|
||||
>
|
||||
Add variable
|
||||
</button>
|
||||
);
|
||||
},
|
||||
onChange: fn(),
|
||||
},
|
||||
play: async ({ canvasElement, args }) => {
|
||||
const canvas = within(canvasElement);
|
||||
|
||||
const addVariableButton = await canvas.findByRole('button', {
|
||||
name: 'Add variable',
|
||||
});
|
||||
|
||||
await userEvent.click(addVariableButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(args.onChange).toHaveBeenCalledWith(`{{${MOCKED_STEP_ID}.name}}`);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user