Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON visualizer for JSON fields #11428

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

Devessier
Copy link
Contributor

@Devessier Devessier commented Apr 7, 2025

  • Updates on the JSON field input
    • Previously, we were editing json fields in a textarea
    • Now, we display a JSON visualizer and the user can click on an Edit button to edit the JSON in Monaco
  • The JSON field input has a special behavior for workflow run output. We want the error to be displayed first in the visualizer. Displaying the error in red was optional but makes the output clearer in the context of a workflow run record board.
  • Made the code editor transparent in the json field input
  • Ensure workflow run's output is not considered readonly in packages/twenty-front/src/modules/object-record/record-field/utils/isFieldValueReadOnly.ts; we want the json visualizer to always be displayed in this specific case

Demo

Failed Workflow Run

CleanShot.2025-04-08.at.11.24.16.mp4

Any JSON field in the record table

CleanShot.2025-04-08.at.11.37.29.mp4

Closes twentyhq/core-team-issues#539

Comment on lines +148 to +183
const getWorkflowRunOutputElements = () => {
if (!isWorkflowRunOutputField) {
return [];
}

const parsedValue = workflowRunOutputSchema.safeParse(
JSON.parse(draftValue ?? ''),
);
if (!parsedValue.success) {
return [];
}

return [
isDefined(parsedValue.data.error)
? {
id: 'error',
label: 'error',
value: parsedValue.data.error as JsonValue,
}
: undefined,
isDefined(parsedValue.data.stepsOutput)
? {
id: 'stepsOutput',
label: 'stepsOutput',
value: parsedValue.data.stepsOutput as JsonValue,
}
: undefined,
isDefined(parsedValue.data.flow)
? {
id: 'flow',
label: 'flow',
value: parsedValue.data.flow as JsonValue,
}
: undefined,
].filter(isDefined);
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this part is hard-coded and adds business logic to the RawJsonFieldInput component which is used all around the application. Do you see a better way of writing that?

@Devessier Devessier marked this pull request as ready for review April 8, 2025 10:07
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR enhances JSON field inputs by integrating a JSON visualizer with a toggle to a Monaco code editor while also updating theming and editing rules for workflow run outputs.

  • RawJsonFieldInput.tsx: Replaces textarea with a JSON visualizer and Monaco editor, reordering workflow run outputs and highlighting errors.
  • isFieldValueReadOnly.ts: Adjusts conditions to allow editing for workflow run outputs.
  • CodeEditor.tsx: Uses a new variant prop ("with-header") and transparentBackground with BASE_CODE_EDITOR_THEME_ID.
  • Index & Theme Files: Re-exports and functions updated to follow the new theming and naming conventions.
  • Serverless Function Components: Updated to align with the revised CodeEditor API.

11 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +26 to +31
if (
objectNameSingular === CoreObjectNameSingular.WorkflowRun &&
fieldName === 'output'
) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Check ordering: the special case for WorkflowRun output is placed after the isRecordReadOnly check. If the intent is to always allow editing of workflow run outputs, even when the record is flagged as read-only, consider moving this block before the read-only check.

Comment on lines +240 to +242
<JsonTree
value={isDefined(draftValue) ? JSON.parse(draftValue) : ''}
emptyArrayLabel={t`Empty Array`}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: JSON.parse(draftValue) in the non-workflow branch may throw if draftValue is invalid. Consider adding error handling (e.g., try-catch).

Suggested change
<JsonTree
value={isDefined(draftValue) ? JSON.parse(draftValue) : ''}
emptyArrayLabel={t`Empty Array`}
<JsonTree
value={isDefined(draftValue) ? (() => { try { return JSON.parse(draftValue); } catch { return ''; } })() : ''}
emptyArrayLabel={t`Empty Array`}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Workflows] Display a workflow run's output in a JSON visualizer inside a popover
1 participant