The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Allow json in workflow run's error field (#12762)
Baptiste Devessier22e126869c01
diff --git a/packages/twenty-front/src/modules/workflow/hooks/useWorkflowRun.ts b/packages/twenty-front/src/modules/workflow/hooks/useWorkflowRun.tsindex 860f21d35df..cd414e735d7 100644--- a/packages/twenty-front/src/modules/workflow/hooks/useWorkflowRun.ts+++ b/packages/twenty-front/src/modules/workflow/hooks/useWorkflowRun.ts@@ -3,6 +3,7 @@ import { useFindOneRecord } from '@/object-record/hooks/useFindOneRecord';import { WorkflowRun } from '@/workflow/types/Workflow';import { workflowRunSchema } from '@/workflow/validation-schemas/workflowSchema';import { useMemo } from 'react';+import { isDefined } from 'twenty-shared/utils';export const useWorkflowRun = ({workflowRunId,@@ -14,14 +15,19 @@ export const useWorkflowRun = ({objectRecordId: workflowRunId,});- const { success, data: record } = useMemo(- () => workflowRunSchema.safeParse(rawRecord),- [rawRecord],- );+ const {+ success,+ data: record,+ error,+ } = useMemo(() => workflowRunSchema.safeParse(rawRecord), [rawRecord]);- if (!success) {+ if (!isDefined(rawRecord)) {return undefined;}+ if (!success) {+ throw error;+ }+return record;};diff --git a/packages/twenty-front/src/modules/workflow/validation-schemas/workflowSchema.ts b/packages/twenty-front/src/modules/workflow/validation-schemas/workflowSchema.tsindex b740a993d4e..44793cb92ea 100644--- a/packages/twenty-front/src/modules/workflow/validation-schemas/workflowSchema.ts+++ b/packages/twenty-front/src/modules/workflow/validation-schemas/workflowSchema.ts@@ -271,7 +271,7 @@ export const workflowTriggerSchema = z.discriminatedUnion('type', [// Step output schemasexport const workflowExecutorOutputSchema = z.object({result: z.any().optional(),- error: z.string().optional(),+ error: z.any().optional(),pendingEvent: z.boolean().optional(),});@@ -286,7 +286,7 @@ export const workflowRunOutputSchema = z.object({steps: z.array(workflowActionSchema),}),stepsOutput: workflowRunOutputStepsOutputSchema.optional(),- error: z.string().optional(),+ error: z.any().optional(),});export const workflowRunContextSchema = z.record(z.any());diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepOutputDetail.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepOutputDetail.tsxindex 2bec95129b8..5da5840d1b5 100644--- a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepOutputDetail.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepOutputDetail.tsx@@ -67,7 +67,13 @@ export const WorkflowRunStepOutputDetail = ({ stepId }: { stepId: string }) => {? getTriggerHeaderType(stepDefinition.definition): i18n._(getActionHeaderTypeOrThrow(stepDefinition.definition.type));- const setRedHighlightingForEveryNode: GetJsonNodeHighlighting = () => 'red';+ const setRedHighlightingForEveryNode: GetJsonNodeHighlighting = (keyPath) => {+ if (keyPath === 'error') {+ return 'red';+ }++ return undefined;+ };return (<>diff --git a/packages/twenty-ui/src/json-visualizer/__stories__/JsonTree.stories.tsx b/packages/twenty-ui/src/json-visualizer/__stories__/JsonTree.stories.tsxindex d2a1df6d080..d73f105583f 100644--- a/packages/twenty-ui/src/json-visualizer/__stories__/JsonTree.stories.tsx+++ b/packages/twenty-ui/src/json-visualizer/__stories__/JsonTree.stories.tsx@@ -571,6 +571,9 @@ export const RedHighlighting: Story = {value: {name: 'John Doe',age: 30,+ address: {+ city: 'Paris',+ },},getNodeHighlighting: () => 'red',},diff --git a/packages/twenty-ui/src/json-visualizer/components/JsonNestedNode.tsx b/packages/twenty-ui/src/json-visualizer/components/JsonNestedNode.tsxindex 06b1d837323..3fdb1a9afd8 100644--- a/packages/twenty-ui/src/json-visualizer/components/JsonNestedNode.tsx+++ b/packages/twenty-ui/src/json-visualizer/components/JsonNestedNode.tsx@@ -25,8 +25,9 @@ const StyledLabelContainer = styled.div`gap: ${({ theme }) => theme.spacing(2)};`;-const StyledElementsCount = styled.span`- color: ${({ theme }) => theme.font.color.tertiary};+const StyledElementsCount = styled.span<{ variant?: 'red' }>`+ color: ${({ theme, variant }) =>+ variant === 'red' ? theme.font.color.danger : theme.font.color.tertiary};`;const StyledJsonList = styled(JsonList)``.withComponent(motion.ul);@@ -118,13 +119,25 @@ export const JsonNestedNode = ({<JsonArrowisOpen={isOpen}onClick={handleArrowClick}- variant={highlighting === 'partial-blue' ? 'blue' : undefined}+ variant={+ highlighting === 'partial-blue'+ ? 'blue'+ : highlighting === 'red'+ ? highlighting+ : undefined+ }/>- <JsonNodeLabel label={label} Icon={Icon} />+ <JsonNodeLabel+ label={label}+ Icon={Icon}+ highlighting={highlighting === 'red' ? highlighting : undefined}+ />{renderElementsCount && (- <StyledElementsCount>+ <StyledElementsCount+ variant={highlighting === 'red' ? 'red' : undefined}+ >{renderElementsCount(elements.length)}</StyledElementsCount>)}diff --git a/packages/twenty-ui/src/json-visualizer/components/internal/JsonArrow.tsx b/packages/twenty-ui/src/json-visualizer/components/internal/JsonArrow.tsxindex 46da248dc0c..73737db9b08 100644--- a/packages/twenty-ui/src/json-visualizer/components/internal/JsonArrow.tsx+++ b/packages/twenty-ui/src/json-visualizer/components/internal/JsonArrow.tsx@@ -6,16 +6,20 @@ import { useJsonTreeContextOrThrow } from '@ui/json-visualizer/hooks/useJsonTreeimport { ANIMATION } from '@ui/theme';import { motion } from 'framer-motion';-const StyledButton = styled(motion.button)`+const StyledButton = styled(motion.button)<{ variant?: 'blue' | 'red' }>`align-items: center;- border-color: ${({ theme }) => theme.border.color.medium};+ background-color: ${({ theme, variant }) =>+ variant === 'red'+ ? theme.background.danger+ : theme.background.transparent.lighter};+ border-color: ${({ theme, variant }) =>+ variant === 'red' ? theme.border.color.danger : theme.border.color.medium};border-radius: ${({ theme }) => theme.border.radius.sm};border-style: solid;border-width: 1px;display: flex;justify-content: center;padding-inline: ${({ theme }) => theme.spacing(1)};- background-color: ${({ theme }) => theme.background.transparent.lighter};height: 24px;width: 24px;box-sizing: border-box;@@ -31,7 +35,7 @@ export const JsonArrow = ({}: {isOpen: boolean;onClick: () => void;- variant?: 'blue';+ variant?: 'blue' | 'red';}) => {const theme = useTheme();@@ -39,7 +43,7 @@ export const JsonArrow = ({useJsonTreeContextOrThrow();return (- <StyledButton onClick={onClick}>+ <StyledButton variant={variant} onClick={onClick}><VisibilityHidden>{isOpen ? arrowButtonExpandedLabel : arrowButtonCollapsedLabel}</VisibilityHidden>@@ -47,7 +51,11 @@ export const JsonArrow = ({<MotionIconChevronDownsize={theme.icon.size.md}color={- variant === 'blue' ? theme.color.blue : theme.font.color.secondary+ variant === 'blue'+ ? theme.color.blue+ : variant === 'red'+ ? theme.font.color.danger+ : theme.font.color.secondary}initial={false}animate={{ rotate: isOpen ? 0 : -90 }}