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

feat: add json editor #4784

Merged
merged 4 commits into from
Sep 27, 2023
Merged

Conversation

spgandhi
Copy link
Contributor

@spgandhi spgandhi commented Sep 20, 2023

About the changes

In this PR we are adding a JSON Editor that will be used for json variant payload type. Its using vanilla-jsoneditor package https://www.npmjs.com/package/vanilla-jsoneditor and is lazy loaded only when the json payload type is selected in the dropdown UI.

Feature preview - https://recordit.co/p4Px9DNUIC

Closes #4450

Important files

Discussion points

@vercel
Copy link

vercel bot commented Sep 20, 2023

@spgandhi is attempting to deploy a commit to the unleash-team Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Sep 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2023 7:16am
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2023 7:16am

value: e.target.value,
}));
}}
placeholder={''}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we have removed the JSON placeholder because this block won't be used for JSON payload anymore

Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

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

This is looking good @spgandhi. Could you also make it match our theme colors in the dark mode? Currently it looks like this which isn't ideal:

Skjermbilde 2023-09-26 kl  09 29 45

Comment on lines 446 to 484
{payload.type === 'json' ? (
<Suspense fallback={null}>
<LazyReactJSONEditor
content={{ text: payload.value }}
onChange={content =>
setPayload(payload => {
return {
...payload,
value:
'json' in content
? content.json?.toString() ||
''
: content.text,
};
})
}
/>
</Suspense>
) : (
<StyledInput
id="variant-payload-value"
name="variant-payload-value"
label="Value"
multiline={payload.type !== 'string'}
rows={
payload.type === 'string' ||
payload.type === 'number'
? 1
: 4
}
value={payload.value}
onChange={e => {
clearError(ErrorField.PAYLOAD);
setPayload(payload => ({
...payload,
value: e.target.value,
}));
}}
placeholder={''}
Copy link
Contributor

Choose a reason for hiding this comment

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

We use a ConditionallyRender component to help with readability for conditional renders. Could be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@spgandhi
Copy link
Contributor Author

@FredrikOseberg made some changes to make the editor more theme compatible. For the hover and focus effect, I see that for inputs, the border width increases from 1px -> 2px on focus. For the JSON Editor, doing this causes the width to change and so looks shaky.So for now I have only updating the colors but not the width

Screenshot 2023-09-26 at 11 55 01 PM Screenshot 2023-09-26 at 11 54 55 PM

@spgandhi spgandhi marked this pull request as ready for review September 27, 2023 06:56
Copy link
Contributor

@FredrikOseberg FredrikOseberg left a comment

Choose a reason for hiding this comment

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

Very nice! This looks good to me. Thanks for contributing @spgandhi 💯

@FredrikOseberg FredrikOseberg merged commit e6cdf5a into Unleash:main Sep 27, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants