Skip to content

The open alternative to Salesforce, designed for AI.

Validation rule form: design fixes and picker key ownership (#27546)

Thomas Trompetteefe58684dccc
diff --git a/packages/twenty-front/src/modules/settings/data-model/components/SettingsDataModelPreviewFormCard.tsx b/packages/twenty-front/src/modules/settings/data-model/components/SettingsDataModelPreviewFormCard.tsx
index 619e7b6ef9b..fa505f8f0b6 100644
--- a/packages/twenty-front/src/modules/settings/data-model/components/SettingsDataModelPreviewFormCard.tsx
+++ b/packages/twenty-front/src/modules/settings/data-model/components/SettingsDataModelPreviewFormCard.tsx
@@ -12,6 +12,7 @@ type SettingsDataModelPreviewFormCardProps = {
preview: ReactNode;
form?: ReactNode;
disabled?: boolean;
+ isPreviewTitleVisible?: boolean;
};
const StyledPreviewContainerWrapper = styled.div`
@@ -30,13 +31,16 @@ export const SettingsDataModelPreviewFormCard = ({
className,
preview,
form,
+ isPreviewTitleVisible = true,
}: SettingsDataModelPreviewFormCardProps) => (
<Card.Root className={className} fullWidth rounded>
<StyledPreviewContainerWrapper>
<Card.Content divider={isDefined(form)}>
- <StyledFormCardTitle>
- <Trans>Preview</Trans>
- </StyledFormCardTitle>
+ {isPreviewTitleVisible && (
+ <StyledFormCardTitle>
+ <Trans>Preview</Trans>
+ </StyledFormCardTitle>
+ )}
{preview}
</Card.Content>
</StyledPreviewContainerWrapper>
diff --git a/packages/twenty-front/src/modules/settings/data-model/object-details/components/tabs/SettingsObjectValidationRulesSection.tsx b/packages/twenty-front/src/modules/settings/data-model/object-details/components/tabs/SettingsObjectValidationRulesSection.tsx
index 397cd5e782d..185c0b873fe 100644
--- a/packages/twenty-front/src/modules/settings/data-model/object-details/components/tabs/SettingsObjectValidationRulesSection.tsx
+++ b/packages/twenty-front/src/modules/settings/data-model/object-details/components/tabs/SettingsObjectValidationRulesSection.tsx
@@ -2,7 +2,8 @@ import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath } from 'twenty-shared/utils';
-import { IconPlus, useIcons } from 'twenty-ui/icon';
+import { IconChevronRight, IconPlus, useIcons } from 'twenty-ui/icon';
+import { Status } from 'twenty-ui/primitives/data-display';
import { themeCssVariables, useTheme } from 'twenty-ui/theme';
import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem';
@@ -12,11 +13,10 @@ import { TableBody } from '@/ui/layout/table/components/TableBody';
import { TableCell } from '@/ui/layout/table/components/TableCell';
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
import { TableRow } from '@/ui/layout/table/components/TableRow';
-import { SettingsValidationRuleExpressionText } from '@/validation-rules/components/SettingsValidationRuleExpressionText';
import { VALIDATION_RULE_DEFAULT_ICON } from '@/validation-rules/constants/ValidationRuleDefaultIcon';
import { useValidationRules } from '@/validation-rules/hooks/useValidationRules';
-const VALIDATION_RULE_TABLE_GRID_TEMPLATE_COLUMNS = '1fr 1fr 80px';
+const VALIDATION_RULE_TABLE_GRID_TEMPLATE_COLUMNS = '1fr 1fr 28px';
const StyledContent = styled.div`
display: flex;
@@ -41,17 +41,16 @@ const StyledName = styled.span`
white-space: nowrap;
`;
-const StyledExpression = styled.span`
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
+const StyledIconChevronRightContainer = styled.span`
+ align-items: center;
+ color: ${themeCssVariables.font.color.tertiary};
+ display: flex;
`;
const StyledEmpty = styled.div`
- color: ${themeCssVariables.font.color.light};
+ color: ${themeCssVariables.font.color.tertiary};
font-size: ${themeCssVariables.font.size.md};
- padding: ${themeCssVariables.spacing[3]};
- text-align: center;
+ padding: ${themeCssVariables.spacing[3]} ${themeCssVariables.spacing[2]};
`;
const StyledButtonContainer = styled.div`
@@ -86,12 +85,12 @@ export const SettingsObjectValidationRulesSection = ({
gridTemplateColumns={VALIDATION_RULE_TABLE_GRID_TEMPLATE_COLUMNS}
>
<TableHeader>{t`Name`}</TableHeader>
- <TableHeader>{t`Condition`}</TableHeader>
- <TableHeader align="right">{t`Status`}</TableHeader>
+ <TableHeader>{t`Status`}</TableHeader>
+ <TableHeader />
</TableRow>
<TableBody>
{validationRules.length === 0 ? (
- <StyledEmpty>{t`No rules yet.`}</StyledEmpty>
+ <StyledEmpty>{t`No rules yet`}</StyledEmpty>
) : (
validationRules.map((validationRule) => {
const RuleIcon = getIcon(
@@ -119,15 +118,23 @@ export const SettingsObjectValidationRulesSection = ({
<StyledName>{validationRule.name}</StyledName>
</StyledNameCell>
</TableCell>
- <TableCell minWidth="0" overflow="hidden">
- <StyledExpression>
- <SettingsValidationRuleExpressionText
- expression={validationRule.expression}
- />
- </StyledExpression>
+ <TableCell>
+ {validationRule.isActive ? (
+ <Status color="green">{t`Active`}</Status>
+ ) : (
+ <Status color="gray">{t`Inactive`}</Status>
+ )}
</TableCell>
- <TableCell align="right">
- {validationRule.isActive ? t`Active` : t`Inactive`}
+ <TableCell
+ align="center"
+ padding={`0 ${themeCssVariables.spacing[1]} 0 0`}
+ >
+ <StyledIconChevronRightContainer>
+ <IconChevronRight
+ size={theme.icon.size.md}
+ stroke={theme.icon.stroke.sm}
+ />
+ </StyledIconChevronRightContainer>
</TableCell>
</TableRow>
);
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 b515e10a175..d98ecebc6e8 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleExpressionEditor.tsx
@@ -129,7 +129,7 @@ export const SettingsValidationRuleExpressionEditor = ({
}),
);
const [highlightedIndex, setHighlightedIndex] = useState(0);
- const [hasNavigatedHelper, setHasNavigatedHelper] = useState(false);
+ const [isHelperFocused, setIsHelperFocused] = useState(false);
const getFieldNodeAttributes = (
path: string,
@@ -153,7 +153,7 @@ export const SettingsValidationRuleExpressionEditor = ({
}),
);
setHighlightedIndex(0);
- setHasNavigatedHelper(false);
+ setIsHelperFocused(false);
};
const initialContent: JSONContent = {
@@ -223,17 +223,6 @@ export const SettingsValidationRuleExpressionEditor = ({
});
};
- const getIsWordBeingTyped = () => {
- return (
- isDefined(editor) &&
- helperContext.replaceFromOffset <
- getValidationRuleEditorText(
- editor.state.doc,
- editor.state.selection.from,
- ).length
- );
- };
-
const handleEditorKeyDown = (event: KeyboardEvent): boolean => {
const { items } = helperContext;
@@ -244,10 +233,14 @@ export const SettingsValidationRuleExpressionEditor = ({
const step = event.key === 'ArrowDown' ? 1 : -1;
- setHighlightedIndex(
- (index) => (index + step + items.length) % items.length,
- );
- setHasNavigatedHelper(true);
+ if (isHelperFocused) {
+ setHighlightedIndex(
+ (index) => (index + step + items.length) % items.length,
+ );
+ } else {
+ setHighlightedIndex(step === 1 ? 0 : items.length - 1);
+ setIsHelperFocused(true);
+ }
return true;
}
@@ -258,10 +251,7 @@ export const SettingsValidationRuleExpressionEditor = ({
const highlightedItem = items[highlightedIndex];
- if (
- isDefined(highlightedItem) &&
- (hasNavigatedHelper || getIsWordBeingTyped())
- ) {
+ if (isHelperFocused && isDefined(highlightedItem)) {
insertHelperItem(highlightedItem);
}
@@ -292,7 +282,7 @@ export const SettingsValidationRuleExpressionEditor = ({
<SettingsValidationRuleHelperPanel
items={helperContext.items}
highlightedIndex={highlightedIndex}
- isEnterHintVisible={hasNavigatedHelper || getIsWordBeingTyped()}
+ isFocused={isHelperFocused}
editorFields={editorFields}
onHighlight={setHighlightedIndex}
onSelect={insertHelperItem}
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 2428f448e1e..224df4d3e67 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleForm.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleForm.tsx
@@ -2,6 +2,7 @@ import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { type ValidationRuleFieldDescriptor } from 'twenty-shared/types';
import { Section } from 'twenty-ui/components/layout';
+import { IconAddressBook, useIcons } from 'twenty-ui/icon';
import { themeCssVariables } from 'twenty-ui/theme';
import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem';
@@ -39,9 +40,14 @@ export const SettingsValidationRuleForm = ({
onChange,
}: SettingsValidationRuleFormProps) => {
const { t } = useLingui();
+ const { getIcon } = useIcons();
const errorFieldOptions = [
- { label: t`Whole record`, value: RECORD_LEVEL_OPTION_VALUE },
+ {
+ label: t`Whole record`,
+ value: RECORD_LEVEL_OPTION_VALUE,
+ Icon: IconAddressBook,
+ },
...objectMetadataItem.fields
.filter(
(field) =>
@@ -51,6 +57,7 @@ export const SettingsValidationRuleForm = ({
.map((field) => ({
label: field.label,
value: field.id,
+ Icon: getIcon(field.icon),
contextualText: field.isActive ? undefined : t`Deactivated`,
})),
];
@@ -70,12 +77,14 @@ export const SettingsValidationRuleForm = ({
description={t`Must be true to save. A write that makes it false is rejected.`}
/>
<SettingsDataModelPreviewFormCard
+ isPreviewTitleVisible={false}
preview={
<SettingsValidationRulePreview
objectMetadataItem={objectMetadataItem}
fields={fields}
editorFields={editorFields}
expression={values.expression}
+ message={values.message}
/>
}
form={
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 dd9528851e0..d11f0763708 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleHelperPanel.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRuleHelperPanel.tsx
@@ -3,7 +3,6 @@ import { useLingui } from '@lingui/react/macro';
import { isDefined } from 'twenty-shared/utils';
import { MenuItem } from 'twenty-ui/components/navigation';
import { useIcons } from 'twenty-ui/icon';
-import { Shortcut } from 'twenty-ui/primitives/typography';
import { themeCssVariables } from 'twenty-ui/theme';
import { SettingsValidationRuleHelperDetails } from '@/validation-rules/components/SettingsValidationRuleHelperDetails';
@@ -40,7 +39,7 @@ const getItemKey = (item: ValidationRuleHelperItem) =>
type SettingsValidationRuleHelperPanelProps = {
items: ValidationRuleHelperItem[];
highlightedIndex: number;
- isEnterHintVisible: boolean;
+ isFocused: boolean;
editorFields: ValidationRuleEditorField[];
onHighlight: (index: number) => void;
onSelect: (item: ValidationRuleHelperItem) => void;
@@ -49,7 +48,7 @@ type SettingsValidationRuleHelperPanelProps = {
export const SettingsValidationRuleHelperPanel = ({
items,
highlightedIndex,
- isEnterHintVisible,
+ isFocused,
editorFields,
onHighlight,
onSelect,
@@ -58,6 +57,7 @@ export const SettingsValidationRuleHelperPanel = ({
const { getIcon } = useIcons();
const highlightedItem = items[highlightedIndex];
+ const EnterHintIcon = getIcon('IconArrowBack');
return (
<StyledPanel>
@@ -67,12 +67,13 @@ export const SettingsValidationRuleHelperPanel = ({
)}
{items.map((item, index) => {
const isHighlighted = index === highlightedIndex;
+ const isFocusedItem = isFocused && isHighlighted;
return (
<div
key={getItemKey(item)}
role="option"
- aria-selected={isHighlighted}
+ aria-selected={isFocusedItem}
ref={
isHighlighted
? (element: HTMLDivElement | null) =>
@@ -88,13 +89,8 @@ export const SettingsValidationRuleHelperPanel = ({
? item.field.label
: item.definition.name
}
- RightComponent={
- isHighlighted &&
- isEnterHintVisible && (
- <Shortcut shortcut={['Enter']} variant="text" />
- )
- }
- focused={isHighlighted}
+ RightIcon={isFocusedItem ? EnterHintIcon : undefined}
+ focused={isFocusedItem}
onMouseEnter={() => onHighlight(index)}
onClick={() => onSelect(item)}
/>
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 450dc4e9ce0..c90a38f37d8 100644
--- a/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRulePreview.tsx
+++ b/packages/twenty-front/src/modules/validation-rules/components/SettingsValidationRulePreview.tsx
@@ -1,6 +1,7 @@
import { styled } from '@linaria/react';
-import { useLingui } from '@lingui/react/macro';
-import { useState } from 'react';
+import { Trans, useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { Fragment, useState } from 'react';
import { VALIDATION_RULE_NOW_VARIABLE_NAME } from 'twenty-shared/constants';
import { type ValidationRuleFieldDescriptor } from 'twenty-shared/types';
import {
@@ -9,6 +10,7 @@ import {
isDefined,
parseValidationRuleExpression,
} from 'twenty-shared/utils';
+import { InlineBanner } from 'twenty-ui/components/feedback';
import { LightIconButton } from 'twenty-ui/components/input';
import { IconChevronDown, IconChevronUp, useIcons } from 'twenty-ui/icon';
import { Status } from 'twenty-ui/primitives/data-display';
@@ -20,6 +22,7 @@ import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/Enriche
import { RecordChip } from '@/object-record/components/RecordChip';
import { generateDepthRecordGqlFieldsFromObject } from '@/object-record/graphql/record-gql-fields/utils/generateDepthRecordGqlFieldsFromObject';
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords';
+import { StyledFormCardTitle } from '@/settings/data-model/fields/components/StyledFormCardTitle';
import { TooltipDelay } from '@/ui/layout/tooltip/constants/TooltipDelay';
import { type ValidationRuleEditorField } from '@/validation-rules/types/ValidationRuleEditorField';
import { buildValidationRulePreviewRelationGqlFields } from '@/validation-rules/utils/buildValidationRulePreviewRelationGqlFields';
@@ -29,18 +32,24 @@ import { getValidationRulePreviewValue } from '@/validation-rules/utils/getValid
const PREVIEW_RECORD_COUNT = 3;
-const StyledHeader = styled.div`
+const StyledPreviewHeader = styled.div`
align-items: center;
display: flex;
gap: ${themeCssVariables.spacing[2]};
justify-content: space-between;
- min-width: 0;
+ margin-bottom: ${themeCssVariables.spacing[4]};
+ min-height: 24px;
+`;
+
+const StyledPreviewTitle = styled(StyledFormCardTitle)`
+ margin-bottom: 0;
`;
-const StyledTitle = styled.div`
+const StyledRecordHeader = styled.div`
align-items: center;
display: flex;
gap: ${themeCssVariables.spacing[2]};
+ justify-content: space-between;
min-width: 0;
`;
@@ -59,36 +68,31 @@ const StyledNavigation = styled.div`
color: ${themeCssVariables.font.color.tertiary};
display: flex;
flex-shrink: 0;
+ font-size: ${themeCssVariables.font.size.sm};
gap: ${themeCssVariables.spacing[1]};
`;
const StyledFieldValues = styled.div`
- background-color: ${themeCssVariables.background.primary};
- border: 1px solid ${themeCssVariables.border.color.medium};
- border-radius: ${themeCssVariables.border.radius.sm};
- display: flex;
- flex-direction: column;
+ column-gap: ${themeCssVariables.spacing[2]};
+ display: grid;
font-size: ${themeCssVariables.font.size.md};
- margin-top: ${themeCssVariables.spacing[2]};
- padding: ${themeCssVariables.spacing[2]};
-`;
-
-const StyledFieldValue = styled.div`
- align-items: center;
- display: flex;
- gap: ${themeCssVariables.spacing[2]};
+ grid-template-columns: fit-content(50%) minmax(0, 1fr);
line-height: 24px;
- min-width: 0;
+ margin-top: ${themeCssVariables.spacing[2]};
+ row-gap: ${themeCssVariables.spacing[1]};
`;
const StyledFieldLabel = styled.div`
align-items: center;
color: ${themeCssVariables.font.color.tertiary};
display: flex;
- flex-shrink: 0;
gap: ${themeCssVariables.spacing[1]};
- max-width: 50%;
+ min-width: 0;
overflow-wrap: anywhere;
+
+ > svg {
+ flex-shrink: 0;
+ }
`;
const StyledValue = styled.span<{ isEmpty: boolean }>`
@@ -104,11 +108,22 @@ const StyledMuted = styled.div`
color: ${themeCssVariables.font.color.light};
`;
+const StyledFieldValuesPlaceholder = styled(StyledMuted)`
+ font-size: ${themeCssVariables.font.size.md};
+ line-height: 24px;
+ margin-top: ${themeCssVariables.spacing[2]};
+`;
+
+const StyledErrorMessage = styled.div`
+ margin-top: ${themeCssVariables.spacing[3]};
+`;
+
type SettingsValidationRulePreviewProps = {
objectMetadataItem: EnrichedObjectMetadataItem;
fields: ValidationRuleFieldDescriptor[];
editorFields: ValidationRuleEditorField[];
expression: string;
+ message: string;
};
export const SettingsValidationRulePreview = ({
@@ -116,6 +131,7 @@ export const SettingsValidationRulePreview = ({
fields,
editorFields,
expression,
+ message,
}: SettingsValidationRulePreviewProps) => {
const { t } = useLingui();
const theme = useTheme();
@@ -147,21 +163,30 @@ export const SettingsValidationRulePreview = ({
},
});
+ const previewTitle = (
+ <StyledPreviewTitle>
+ <Trans>Preview</Trans>
+ </StyledPreviewTitle>
+ );
+
if (loading) {
- return null;
+ return <StyledPreviewHeader>{previewTitle}</StyledPreviewHeader>;
}
const record = records[Math.min(recordIndex, records.length - 1)];
if (!isDefined(record)) {
return (
- <Card.Root fullWidth>
- <Card.Content>
- <StyledMuted>
- {t`Create a few ${objectMetadataItem.labelPlural} to preview this rule on real records.`}
- </StyledMuted>
- </Card.Content>
- </Card.Root>
+ <>
+ <StyledPreviewHeader>{previewTitle}</StyledPreviewHeader>
+ <Card.Root fullWidth>
+ <Card.Content>
+ <StyledMuted>
+ {t`Create a few ${objectMetadataItem.labelPlural} to preview this rule on real records.`}
+ </StyledMuted>
+ </Card.Content>
+ </Card.Root>
+ </>
);
}
@@ -175,29 +200,35 @@ export const SettingsValidationRulePreview = ({
].filter((path) => path !== VALIDATION_RULE_NOW_VARIABLE_NAME)
: [];
+ const evaluationResult = compilationResult.isValid
+ ? evaluateValidationRuleExpression({
+ expression,
+ record,
+ fields,
+ now: new Date().toISOString(),
+ })
+ : undefined;
+
+ const trimmedMessage = message.trim();
+ const isErrorMessageVisible =
+ evaluationResult?.status === 'failed' && isNonEmptyString(trimmedMessage);
+
const renderStatus = () => {
- if (!compilationResult.isValid) {
+ if (!isDefined(evaluationResult)) {
return null;
}
- const evaluationResult = evaluateValidationRuleExpression({
- expression,
- record,
- fields,
- now: new Date().toISOString(),
- });
-
switch (evaluationResult.status) {
case 'passed':
return (
<StyledStatus>
- <Status color="green">{t`Allowed`}</Status>
+ <Status color="green">{t`Valid`}</Status>
</StyledStatus>
);
case 'failed':
return (
<StyledStatus>
- <Status color="red">{t`Rejected`}</Status>
+ <Status color="red">{t`Blocked`}</Status>
</StyledStatus>
);
case 'errored':
@@ -219,10 +250,30 @@ export const SettingsValidationRulePreview = ({
const recordCount = records.length;
return (
- <Card.Root fullWidth>
- <Card.Content>
- <StyledHeader>
- <StyledTitle>
+ <>
+ <StyledPreviewHeader>
+ {previewTitle}
+ <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>
+ </StyledPreviewHeader>
+ <Card.Root fullWidth>
+ <Card.Content>
+ <StyledRecordHeader>
<StyledRecord>
<RecordChip
objectNameSingular={objectMetadataItem.nameSingular}
@@ -231,67 +282,57 @@ export const SettingsValidationRulePreview = ({
/>
</StyledRecord>
{renderStatus()}
- </StyledTitle>
- <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>
- <StyledFieldValues>
+ </StyledRecordHeader>
{referencedPaths.length === 0 ? (
- <StyledMuted>
+ <StyledFieldValuesPlaceholder>
{compilationResult.isValid
? t`This condition doesn't read any field.`
: t`Fields used in the condition show their values here.`}
- </StyledMuted>
+ </StyledFieldValuesPlaceholder>
) : (
- referencedPaths.map((path) => {
- const editorField = editorFields.find(
- (candidate) => candidate.path === path,
- );
- const fieldLabel = isDefined(editorField)
- ? getValidationRuleEditorFieldChipLabel(editorField)
- : path;
- const FieldIcon = isDefined(editorField)
- ? getIcon(editorField.iconName)
- : undefined;
- const formattedValue = formatValidationRulePreviewValue(
- getValidationRulePreviewValue(record, path),
- );
+ <StyledFieldValues>
+ {referencedPaths.map((path) => {
+ const editorField = editorFields.find(
+ (candidate) => candidate.path === path,
+ );
+ const fieldLabel = isDefined(editorField)
+ ? getValidationRuleEditorFieldChipLabel(editorField)
+ : path;
+ const FieldIcon = isDefined(editorField)
+ ? getIcon(editorField.iconName)
+ : undefined;
+ const formattedValue = formatValidationRulePreviewValue(
+ getValidationRulePreviewValue(record, path),
+ );
- return (
- <StyledFieldValue key={path}>
- <StyledFieldLabel>
- {isDefined(FieldIcon) && (
- <FieldIcon
- size={theme.icon.size.md}
- stroke={theme.icon.stroke.sm}
- />
- )}
- {t`${fieldLabel}:`}
- </StyledFieldLabel>
- <StyledValue isEmpty={formattedValue.length === 0}>
- {formattedValue.length > 0 ? formattedValue : t`Empty`}
- </StyledValue>
- </StyledFieldValue>
- );
- })
+ return (
+ <Fragment key={path}>
+ <StyledFieldLabel>
+ {isDefined(FieldIcon) && (
+ <FieldIcon
+ size={theme.icon.size.md}
+ stroke={theme.icon.stroke.sm}
+ />
+ )}
+ {fieldLabel}
+ </StyledFieldLabel>
+ <StyledValue isEmpty={formattedValue.length === 0}>
+ {formattedValue.length > 0 ? formattedValue : t`Empty`}
+ </StyledValue>
+ </Fragment>
+ );
+ })}
+ </StyledFieldValues>
+ )}
+ {isErrorMessageVisible && (
+ <StyledErrorMessage>
+ <InlineBanner status="error" embedded>
+ {trimmedMessage}
+ </InlineBanner>
+ </StyledErrorMessage>
)}
- </StyledFieldValues>
- </Card.Content>
- </Card.Root>
+ </Card.Content>
+ </Card.Root>
+ </>
);
};