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(dashboard): in-app editor form fields based on codemirror #6809

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

LetItRock
Copy link
Contributor

What changed? Why was the change needed?

In-App Editor - updated the form fields to be based on the "editor" primitive, which is the CodeMirror component.

TODO:

  • styling
  • autosuggestions

Screenshots

Screenshot 2024-10-30 at 23 56 17

Copy link

linear bot commented Oct 30, 2024

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for novu-stg-vite-dashboard-poc ready!

Name Link
🔨 Latest commit 676990f
🔍 Latest deploy log https://app.netlify.com/sites/novu-stg-vite-dashboard-poc/deploys/67255593b6315e000860c0cf
😎 Deploy Preview https://deploy-preview-6809--novu-stg-vite-dashboard-poc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -43,10 +43,14 @@
"@segment/analytics-next": "^1.73.0",
"@sentry/react": "^8.35.0",
"@tanstack/react-query": "^5.59.6",
"@uiw/codemirror-theme-white": "^4.23.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

use the CodeMirror white theme as default; we will adjust it to our needs

"@xyflow/react": "^12.3.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "1.0.0",
"codemirror-lang-liquid": "^1.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

liquid syntax and autocomplete

Comment on lines +7 to +17
const editorVariants = cva('-mx-1 -mt-[2px] h-full w-full flex-1 [&_.cm-focused]:outline-none', {
variants: {
size: {
default: 'text-xs [&_.cm-editor]:py-1',
md: 'text-sm [&_.cm-editor]:py-2',
},
},
defaultVariants: {
size: 'default',
},
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these styles adjust the editor to look good when placed inside the InputField component; basically to have the correct padding from the top

Comment on lines +57 to +61
useEffect(() => {
if (editor.current) {
setContainer(editor.current);
}
}, [setContainer]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the recommended way from the docs

export const Editor = ({ value, placeholder, className, height, size, onChange }: EditorProps) => {
const editor = useRef<HTMLDivElement>(null);
const { setContainer } = useCodeMirror({
extensions: [LiquidHTML({}), EditorView.lineWrapping],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

liquid and line wrapping extensions

placeholder={placeholder}
value={value.url}
onChange={(val) => onChange({ ...value, url: val })}
height={size === 'md' ? '38px' : '30px'}
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'm not sure how to do this better without hardcoding these values, basically, our inputs heights are md 40px and default 32px. These values exclude border.
And the height should be set if we want to have "single line" input, otherwise the editor will be growing with more content.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I'll move to constants or something.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we using code mirror in online inputs to reuse the autocomplete functionality for variables? It's a smart approach to keep it dry, although it feels like an overkill for simple text or email inputs. I wonder if it's more future proof to have the autocomplete CodeMirror offers for code text areas and then implement it again with a popover for regular inputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we use it in all form fields, subject, redirect etc.
The "regular" single-line fields are limited in the number of characters that you can type and also the way it works currently with CodeMirror is not optimal as you can move the text to the next line and in this case the previous line won't be visible. We need to think about the pattern here, the potential solution might be to have "auto" height on the fields, but then you can't build all types of form UI with this approach as you can easily break the UI.

@@ -178,7 +179,7 @@ const ConfigureActionPopover = (
}}
>
<PopoverTrigger {...rest} />
<PopoverContent>
<PopoverContent className="max-w-72">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the editor fields expand the popover content, so I had to set the max

Comment on lines +27 to +28
const [subject, setSubject] = useState('');
const [body, setBody] = useState('');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just temporarily

Copy link

pkg-pr-new bot commented Oct 30, 2024

Open in Stackblitz

@novu/client

pnpm add https://pkg.pr.new/novuhq/novu/@novu/client@6809

@novu/headless

pnpm add https://pkg.pr.new/novuhq/novu/@novu/headless@6809

@novu/framework

pnpm add https://pkg.pr.new/novuhq/novu/@novu/framework@6809

@novu/js

pnpm add https://pkg.pr.new/novuhq/novu/@novu/js@6809

@novu/nest

pnpm add https://pkg.pr.new/novuhq/novu/@novu/nest@6809

@novu/nextjs

pnpm add https://pkg.pr.new/novuhq/novu/@novu/nextjs@6809

@novu/node

pnpm add https://pkg.pr.new/novuhq/novu/@novu/node@6809

@novu/notification-center

pnpm add https://pkg.pr.new/novuhq/novu/@novu/notification-center@6809

novu

pnpm add https://pkg.pr.new/novuhq/novu@6809

@novu/providers

pnpm add https://pkg.pr.new/novuhq/novu/@novu/providers@6809

@novu/react

pnpm add https://pkg.pr.new/novuhq/novu/@novu/react@6809

@novu/react-native

pnpm add https://pkg.pr.new/novuhq/novu/@novu/react-native@6809

@novu/shared

pnpm add https://pkg.pr.new/novuhq/novu/@novu/shared@6809

@novu/stateless

pnpm add https://pkg.pr.new/novuhq/novu/@novu/stateless@6809

commit: 676990f

Copy link
Contributor

@SokratisVidros SokratisVidros left a comment

Choose a reason for hiding this comment

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

Code mirror!!! Yay!!!

Copy link
Contributor

@SokratisVidros SokratisVidros left a comment

Choose a reason for hiding this comment

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

I approve this one and we will chat about using CodeMirror editor across for all form fields separately.

placeholder={placeholder}
value={value.url}
onChange={(val) => onChange({ ...value, url: val })}
height={size === 'md' ? '38px' : '30px'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we using code mirror in online inputs to reuse the autocomplete functionality for variables? It's a smart approach to keep it dry, although it feels like an overkill for simple text or email inputs. I wonder if it's more future proof to have the autocomplete CodeMirror offers for code text areas and then implement it again with a popover for regular inputs.

@LetItRock LetItRock merged commit 96889c1 into next Nov 1, 2024
35 of 40 checks passed
@LetItRock LetItRock deleted the nv-4556-in-app-editor-codemirror-fields branch November 1, 2024 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants