Skip to content

The open alternative to Salesforce, designed for AI.

JSON visualizer: Highlight the parent nodes of in-use nodes (#11373)

Baptiste Devessier144a3267092d
diff --git a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepInputDetail.tsx b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepInputDetail.tsx
index 85c7b08e61a..0eabbc86627 100644
--- a/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepInputDetail.tsx
+++ b/packages/twenty-front/src/modules/workflow/workflow-steps/components/WorkflowRunStepInputDetail.tsx
@@ -14,6 +14,7 @@ import { useLingui } from '@lingui/react/macro';
import { isDefined } from 'twenty-shared/utils';
import { IconBrackets, useIcons } from 'twenty-ui/display';
import {
+ GetJsonNodeHighlighting,
JsonNestedNode,
JsonTreeContextProvider,
ShouldExpandNodeInitiallyProps,
@@ -70,6 +71,7 @@ export const WorkflowRunStepInputDetail = ({ stepId }: { stepId: string }) => {
const variablesUsedInStep = getWorkflowVariablesUsedInStep({
step,
});
+ const allVariablesUsedInStep = Array.from(variablesUsedInStep);
const stepContext = getWorkflowRunStepContext({
context: workflowRun.context,
@@ -80,6 +82,21 @@ export const WorkflowRunStepInputDetail = ({ stepId }: { stepId: string }) => {
throw new Error('The input tab must be rendered with a non-empty context.');
}
+ const getNodeHighlighting: GetJsonNodeHighlighting = (keyPath: string) => {
+ if (variablesUsedInStep.has(keyPath)) {
+ return 'blue';
+ }
+
+ const isUsedVariableParent = allVariablesUsedInStep.some((variable) =>
+ variable.startsWith(keyPath),
+ );
+ if (isUsedVariableParent) {
+ return 'partial-blue';
+ }
+
+ return undefined;
+ };
+
const isFirstNodeDepthOfPreviousStep = ({
keyPath,
depth,
@@ -104,8 +121,7 @@ export const WorkflowRunStepInputDetail = ({ stepId }: { stepId: string }) => {
emptyStringLabel: t`[empty string]`,
arrowButtonCollapsedLabel: t`Expand`,
arrowButtonExpandedLabel: t`Collapse`,
- getNodeHighlighting: (keyPath) =>
- variablesUsedInStep.has(keyPath) ? 'blue' : undefined,
+ getNodeHighlighting,
shouldExpandNodeInitially: isFirstNodeDepthOfPreviousStep,
}}
>
diff --git a/packages/twenty-ui/src/json-visualizer/__stories__/JsonTree.stories.tsx b/packages/twenty-ui/src/json-visualizer/__stories__/JsonTree.stories.tsx
index 822b3185df8..25af1430e2b 100644
--- a/packages/twenty-ui/src/json-visualizer/__stories__/JsonTree.stories.tsx
+++ b/packages/twenty-ui/src/json-visualizer/__stories__/JsonTree.stories.tsx
@@ -447,6 +447,26 @@ export const BlueHighlighting: Story = {
},
};
+export const PartialBlueHighlighting: Story = {
+ args: {
+ value: {
+ name: 'John Doe',
+ age: 30,
+ address: {
+ city: 'Paris',
+ },
+ },
+ getNodeHighlighting: (keyPath: string) =>
+ keyPath === 'address' ? 'partial-blue' : undefined,
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ const ageElement = await canvas.findByText('age');
+ expect(ageElement).toBeVisible();
+ },
+};
+
export const RedHighlighting: Story = {
args: {
value: {
diff --git a/packages/twenty-ui/src/json-visualizer/components/JsonArrayNode.tsx b/packages/twenty-ui/src/json-visualizer/components/JsonArrayNode.tsx
index d17da3ab63b..1919b7adf6c 100644
--- a/packages/twenty-ui/src/json-visualizer/components/JsonArrayNode.tsx
+++ b/packages/twenty-ui/src/json-visualizer/components/JsonArrayNode.tsx
@@ -1,6 +1,7 @@
import { IconBrackets } from '@ui/display';
import { JsonNestedNode } from '@ui/json-visualizer/components/JsonNestedNode';
import { useJsonTreeContextOrThrow } from '@ui/json-visualizer/hooks/useJsonTreeContextOrThrow';
+import { JsonNodeHighlighting } from '@ui/json-visualizer/types/JsonNodeHighlighting';
import { JsonArray } from 'type-fest';
export const JsonArrayNode = ({
@@ -8,11 +9,13 @@ export const JsonArrayNode = ({
value,
depth,
keyPath,
+ highlighting,
}: {
label?: string;
value: JsonArray;
depth: number;
keyPath: string;
+ highlighting: JsonNodeHighlighting | undefined;
}) => {
const { emptyArrayLabel } = useJsonTreeContextOrThrow();
@@ -29,6 +32,7 @@ export const JsonArrayNode = ({
depth={depth}
emptyElementsText={emptyArrayLabel}
keyPath={keyPath}
+ highlighting={highlighting}
/>
);
};
diff --git a/packages/twenty-ui/src/json-visualizer/components/JsonNestedNode.tsx b/packages/twenty-ui/src/json-visualizer/components/JsonNestedNode.tsx
index 4adbb4fadd1..7b6fbc814c9 100644
--- a/packages/twenty-ui/src/json-visualizer/components/JsonNestedNode.tsx
+++ b/packages/twenty-ui/src/json-visualizer/components/JsonNestedNode.tsx
@@ -6,11 +6,12 @@ import { JsonList } from '@ui/json-visualizer/components/internal/JsonList';
import { JsonNodeLabel } from '@ui/json-visualizer/components/internal/JsonNodeLabel';
import { JsonNode } from '@ui/json-visualizer/components/JsonNode';
import { useJsonTreeContextOrThrow } from '@ui/json-visualizer/hooks/useJsonTreeContextOrThrow';
+import { JsonNodeHighlighting } from '@ui/json-visualizer/types/JsonNodeHighlighting';
import { ANIMATION } from '@ui/theme';
import { AnimatePresence, motion } from 'framer-motion';
import { useState } from 'react';
-import { JsonValue } from 'type-fest';
import { isDefined } from 'twenty-shared/utils';
+import { JsonValue } from 'type-fest';
const StyledContainer = styled.li`
display: grid;
@@ -41,6 +42,7 @@ export const JsonNestedNode = ({
emptyElementsText,
depth,
keyPath,
+ highlighting,
}: {
label?: string;
Icon: IconComponent;
@@ -49,6 +51,7 @@ export const JsonNestedNode = ({
emptyElementsText: string;
depth: number;
keyPath: string;
+ highlighting?: JsonNodeHighlighting | undefined;
}) => {
const { shouldExpandNodeInitially } = useJsonTreeContextOrThrow();
@@ -115,7 +118,11 @@ export const JsonNestedNode = ({
return (
<StyledContainer>
<StyledLabelContainer>
- <JsonArrow isOpen={isOpen} onClick={handleArrowClick} />
+ <JsonArrow
+ isOpen={isOpen}
+ onClick={handleArrowClick}
+ variant={highlighting === 'partial-blue' ? 'blue' : undefined}
+ />
<JsonNodeLabel label={label} Icon={Icon} />
diff --git a/packages/twenty-ui/src/json-visualizer/components/JsonNode.tsx b/packages/twenty-ui/src/json-visualizer/components/JsonNode.tsx
index 6812354d10f..b58aa6c80dd 100644
--- a/packages/twenty-ui/src/json-visualizer/components/JsonNode.tsx
+++ b/packages/twenty-ui/src/json-visualizer/components/JsonNode.tsx
@@ -84,6 +84,7 @@ export const JsonNode = ({
value={value}
depth={depth}
keyPath={keyPath}
+ highlighting={highlighting}
/>
);
}
@@ -94,6 +95,7 @@ export const JsonNode = ({
value={value}
depth={depth}
keyPath={keyPath}
+ highlighting={highlighting}
/>
);
};
diff --git a/packages/twenty-ui/src/json-visualizer/components/JsonObjectNode.tsx b/packages/twenty-ui/src/json-visualizer/components/JsonObjectNode.tsx
index e3f32fd34a2..29c6a17867a 100644
--- a/packages/twenty-ui/src/json-visualizer/components/JsonObjectNode.tsx
+++ b/packages/twenty-ui/src/json-visualizer/components/JsonObjectNode.tsx
@@ -1,6 +1,7 @@
import { IconCube } from '@ui/display';
import { JsonNestedNode } from '@ui/json-visualizer/components/JsonNestedNode';
import { useJsonTreeContextOrThrow } from '@ui/json-visualizer/hooks/useJsonTreeContextOrThrow';
+import { JsonNodeHighlighting } from '@ui/json-visualizer/types/JsonNodeHighlighting';
import { JsonObject } from 'type-fest';
export const JsonObjectNode = ({
@@ -8,11 +9,13 @@ export const JsonObjectNode = ({
value,
depth,
keyPath,
+ highlighting,
}: {
label?: string;
value: JsonObject;
depth: number;
keyPath: string;
+ highlighting: JsonNodeHighlighting | undefined;
}) => {
const { emptyObjectLabel } = useJsonTreeContextOrThrow();
@@ -29,6 +32,7 @@ export const JsonObjectNode = ({
depth={depth}
emptyElementsText={emptyObjectLabel}
keyPath={keyPath}
+ highlighting={highlighting}
/>
);
};
diff --git a/packages/twenty-ui/src/json-visualizer/components/internal/JsonArrow.tsx b/packages/twenty-ui/src/json-visualizer/components/internal/JsonArrow.tsx
index 46ed517934e..46da248dc0c 100644
--- a/packages/twenty-ui/src/json-visualizer/components/internal/JsonArrow.tsx
+++ b/packages/twenty-ui/src/json-visualizer/components/internal/JsonArrow.tsx
@@ -27,9 +27,11 @@ const MotionIconChevronDown = motion.create(IconChevronDown);
export const JsonArrow = ({
isOpen,
onClick,
+ variant,
}: {
isOpen: boolean;
onClick: () => void;
+ variant?: 'blue';
}) => {
const theme = useTheme();
@@ -44,7 +46,9 @@ export const JsonArrow = ({
<MotionIconChevronDown
size={theme.icon.size.md}
- color={theme.font.color.secondary}
+ color={
+ variant === 'blue' ? theme.color.blue : theme.font.color.secondary
+ }
initial={false}
animate={{ rotate: isOpen ? 0 : -90 }}
transition={{ duration: ANIMATION.duration.normal }}
diff --git a/packages/twenty-ui/src/json-visualizer/components/internal/JsonNodeValue.tsx b/packages/twenty-ui/src/json-visualizer/components/internal/JsonNodeValue.tsx
index 9dfcb4958bf..61940c2b8ae 100644
--- a/packages/twenty-ui/src/json-visualizer/components/internal/JsonNodeValue.tsx
+++ b/packages/twenty-ui/src/json-visualizer/components/internal/JsonNodeValue.tsx
@@ -8,7 +8,7 @@ const StyledText = styled.span<{
highlighting === 'blue'
? theme.adaptiveColors.blue4
: highlighting === 'red'
- ? theme.font.color.danger
+ ? theme.adaptiveColors.red4
: theme.font.color.tertiary};
`;
diff --git a/packages/twenty-ui/src/json-visualizer/types/JsonNodeHighlighting.ts b/packages/twenty-ui/src/json-visualizer/types/JsonNodeHighlighting.ts
index fe0465505de..3defacd2f76 100644
--- a/packages/twenty-ui/src/json-visualizer/types/JsonNodeHighlighting.ts
+++ b/packages/twenty-ui/src/json-visualizer/types/JsonNodeHighlighting.ts
@@ -1,3 +1,5 @@
import { ThemeColor } from '@ui/theme';
-export type JsonNodeHighlighting = Extract<ThemeColor, 'blue' | 'red'>;
+export type JsonNodeHighlighting =
+ | Extract<ThemeColor, 'blue' | 'red'>
+ | 'partial-blue';