Skip to content

The open alternative to Salesforce, designed for AI.

Validation rule form (4/5): condition in one preview card (#27093)

Thomas Trompette7e1431c84adb
diff --git a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx
index 042c514d126..b515e10a175 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx
@@ -13,6 +13,7 @@ import {
compileValidationRuleExpression,
isDefined,
} from 'twenty-shared/utils';
+import { Card } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables } from 'twenty-ui/theme';
import { FORM_FIELD_PLACEHOLDER_STYLES } from '@/ui/input/constants/FormFieldPlaceholderStyles';
@@ -35,7 +36,7 @@ import { insertValidationRuleHelperItem } from '@/validation-rules/utils/insertV
const SingleParagraphDocument = Document.extend({ content: 'paragraph' });
-const StyledContainer = styled.div`
+const StyledEditorContent = styled.div`
display: flex;
flex-direction: column;
gap: ${themeCssVariables.spacing[2]};
@@ -277,13 +278,17 @@ export const SettingsValidationRuleExpressionEditor = ({
: null;
return (
- <StyledContainer>
- <StyledEditor hasError={isDefined(errorMessage)}>
- <EditorContent editor={editor} />
- </StyledEditor>
- {isDefined(errorMessage) && (
- <StyledError role="alert">{errorMessage}</StyledError>
- )}
+ <>
+ <Card.Content divider>
+ <StyledEditorContent>
+ <StyledEditor hasError={isDefined(errorMessage)}>
+ <EditorContent editor={editor} />
+ </StyledEditor>
+ {isDefined(errorMessage) && (
+ <StyledError role="alert">{errorMessage}</StyledError>
+ )}
+ </StyledEditorContent>
+ </Card.Content>
<SettingsValidationRuleHelperPanel
items={helperContext.items}
highlightedIndex={highlightedIndex}
@@ -292,6 +297,6 @@ export const SettingsValidationRuleExpressionEditor = ({
onHighlight={setHighlightedIndex}
onSelect={insertHelperItem}
/>
- </StyledContainer>
+ </>
);
};
diff --git a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleForm.tsx b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleForm.tsx
index 83283273d48..05468713737 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleForm.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleForm.tsx
@@ -5,6 +5,7 @@ import { Section } from 'twenty-ui/components';
import { themeCssVariables } from 'twenty-ui/theme';
import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem';
+import { SettingsDataModelPreviewFormCard } from '@/settings/data-model/components/SettingsDataModelPreviewFormCard';
import { Select } from '@/ui/input/components/Select';
import { SettingsTextInput } from '@/ui/input/components/SettingsTextInput';
import { SettingsValidationRuleExpressionEditor } from '@/validation-rules/components/SettingsValidationRuleExpressionEditor';
@@ -15,12 +16,6 @@ import { type ValidationRuleFormValues } from '@/validation-rules/types/Validati
const RECORD_LEVEL_OPTION_VALUE = 'record-level';
-const StyledConditionContent = styled.div`
- display: flex;
- flex-direction: column;
- gap: ${themeCssVariables.spacing[3]};
-`;
-
const StyledRow = styled.div`
align-items: flex-end;
display: grid;
@@ -66,21 +61,25 @@ export const SettingsValidationRuleForm = ({
title={t`Condition`}
description={t`Must be true to save. A write that makes it false is rejected.`}
/>
- <StyledConditionContent>
- <SettingsValidationRulePreview
- objectMetadataItem={objectMetadataItem}
- fields={fields}
- editorFields={editorFields}
- expression={values.expression}
- message={values.message}
- />
- <SettingsValidationRuleExpressionEditor
- value={values.expression}
- fields={fields}
- editorFields={editorFields}
- onChange={(expression) => onChange({ ...values, expression })}
- />
- </StyledConditionContent>
+ <SettingsDataModelPreviewFormCard
+ preview={
+ <SettingsValidationRulePreview
+ objectMetadataItem={objectMetadataItem}
+ fields={fields}
+ editorFields={editorFields}
+ expression={values.expression}
+ message={values.message}
+ />
+ }
+ form={
+ <SettingsValidationRuleExpressionEditor
+ value={values.expression}
+ fields={fields}
+ editorFields={editorFields}
+ onChange={(expression) => onChange({ ...values, expression })}
+ />
+ }
+ />
</Section.Root>
<Section.Root>
<Section.Header
diff --git a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleHelperPanel.tsx b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleHelperPanel.tsx
index 3664c9027fe..cbf6dad23e8 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleHelperPanel.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleHelperPanel.tsx
@@ -12,8 +12,6 @@ import { type ValidationRuleHelperItem } from '@/validation-rules/types/Validati
import { getValidationRuleHelperItemIcon } from '@/validation-rules/utils/getValidationRuleHelperItemIcon';
const StyledPanel = styled.div`
- border: 1px solid ${themeCssVariables.border.color.medium};
- border-radius: ${themeCssVariables.border.radius.md};
display: grid;
font-size: ${themeCssVariables.font.size.md};
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
@@ -26,7 +24,7 @@ const StyledList = styled.div`
display: flex;
flex-direction: column;
overflow-y: auto;
- padding: ${themeCssVariables.spacing[1]};
+ padding: ${themeCssVariables.spacing[1]} ${themeCssVariables.spacing[4]};
`;
const StyledEmpty = styled.div`
diff --git a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRulePreview.tsx b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRulePreview.tsx
index d2b1b48fc5f..109199fac1d 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRulePreview.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRulePreview.tsx
@@ -18,6 +18,7 @@ import {
IconChevronUp,
IconX,
} from 'twenty-ui/icon';
+import { Card } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables, useTheme } from 'twenty-ui/theme';
import { useObjectMetadataItems } from '@/object-metadata/hooks/useObjectMetadataItems';
@@ -34,13 +35,10 @@ import { getValidationRulePreviewValue } from '@/validation-rules/utils/getValid
const PREVIEW_RECORD_COUNT = 3;
const StyledPreview = styled.div`
- border: 1px solid ${themeCssVariables.border.color.medium};
- border-radius: ${themeCssVariables.border.radius.md};
display: flex;
flex-direction: column;
font-size: ${themeCssVariables.font.size.md};
gap: ${themeCssVariables.spacing[3]};
- padding: ${themeCssVariables.spacing[3]};
`;
const StyledHeader = styled.div`
@@ -143,11 +141,13 @@ export const SettingsValidationRulePreview = ({
if (!isDefined(record)) {
return (
- <StyledPreview>
- <StyledMuted>
- {t`Create a few ${objectMetadataItem.labelPlural} to preview this rule on real records.`}
- </StyledMuted>
- </StyledPreview>
+ <Card.Root fullWidth>
+ <Card.Content>
+ <StyledMuted>
+ {t`Create a few ${objectMetadataItem.labelPlural} to preview this rule on real records.`}
+ </StyledMuted>
+ </Card.Content>
+ </Card.Root>
);
}
@@ -206,58 +206,62 @@ export const SettingsValidationRulePreview = ({
const recordCount = records.length;
return (
- <StyledPreview>
- <StyledHeader>
- <RecordChip
- objectNameSingular={objectMetadataItem.nameSingular}
- record={record}
- forceDisableClick
- />
- <StyledNavigation>
- {t`Record ${displayedRecordNumber} of ${recordCount}`}
- <LightIconButton
- aria-label={t`Previous record`}
- disabled={displayedRecordNumber === 1}
- onClick={() => setRecordIndex(displayedRecordNumber - 2)}
- >
- <IconChevronUp />
- </LightIconButton>
- <LightIconButton
- aria-label={t`Next record`}
- disabled={displayedRecordNumber === recordCount}
- onClick={() => setRecordIndex(displayedRecordNumber)}
- >
- <IconChevronDown />
- </LightIconButton>
- </StyledNavigation>
- </StyledHeader>
- {referencedPaths.length > 0 && (
- <StyledValues>
- {referencedPaths.map((path) => {
- const editorField = editorFields.find(
- (candidate) => candidate.path === path,
- );
- const formattedValue = formatValidationRulePreviewValue(
- getValidationRulePreviewValue(record, path),
- );
-
- return [
- <StyledValueLabel key={`${path}-label`}>
- {isDefined(editorField)
- ? getValidationRuleEditorFieldChipLabel(editorField)
- : path}
- </StyledValueLabel>,
- <StyledValue
- key={`${path}-value`}
- isEmpty={formattedValue.length === 0}
+ <Card.Root fullWidth>
+ <Card.Content>
+ <StyledPreview>
+ <StyledHeader>
+ <RecordChip
+ objectNameSingular={objectMetadataItem.nameSingular}
+ record={record}
+ forceDisableClick
+ />
+ <StyledNavigation>
+ {t`Record ${displayedRecordNumber} of ${recordCount}`}
+ <LightIconButton
+ aria-label={t`Previous record`}
+ disabled={displayedRecordNumber === 1}
+ onClick={() => setRecordIndex(displayedRecordNumber - 2)}
+ >
+ <IconChevronUp />
+ </LightIconButton>
+ <LightIconButton
+ aria-label={t`Next record`}
+ disabled={displayedRecordNumber === recordCount}
+ onClick={() => setRecordIndex(displayedRecordNumber)}
>
- {formattedValue.length > 0 ? formattedValue : t`Empty`}
- </StyledValue>,
- ];
- })}
- </StyledValues>
- )}
- {renderResult()}
- </StyledPreview>
+ <IconChevronDown />
+ </LightIconButton>
+ </StyledNavigation>
+ </StyledHeader>
+ {referencedPaths.length > 0 && (
+ <StyledValues>
+ {referencedPaths.map((path) => {
+ const editorField = editorFields.find(
+ (candidate) => candidate.path === path,
+ );
+ const formattedValue = formatValidationRulePreviewValue(
+ getValidationRulePreviewValue(record, path),
+ );
+
+ return [
+ <StyledValueLabel key={`${path}-label`}>
+ {isDefined(editorField)
+ ? getValidationRuleEditorFieldChipLabel(editorField)
+ : path}
+ </StyledValueLabel>,
+ <StyledValue
+ key={`${path}-value`}
+ isEmpty={formattedValue.length === 0}
+ >
+ {formattedValue.length > 0 ? formattedValue : t`Empty`}
+ </StyledValue>,
+ ];
+ })}
+ </StyledValues>
+ )}
+ {renderResult()}
+ </StyledPreview>
+ </Card.Content>
+ </Card.Root>
);
};