Skip to content

Conversation

@BandanaKM
Copy link
Contributor

@BandanaKM BandanaKM commented Jan 4, 2022

Overview

Feature: Migrate SimpleMonacoEditor to Codebytes in Client-Modules

PR Checklist

  • Related to JIRA ticket: DISC-353
  • I have run this code to verify it works

This pull request is part of a series of pull requests to migrate the codebytes UI to client modules. The component structure thus far is:

CodebyteEditor
   > Editor
       > Drawers 
           > SimpleMonacoEditor
         
  1. This pull request migrates the MonacoEditor component exactly as it is and ensures that it runs code on the snippets endpoint. See original in static sites: https://github.com/codecademy-engineering/static-sites/tree/577de863974111b4021c2bec6f4b5d2b1684a3c8/src/templates/CodeByteEditor/MonacoEditor
  2. Ensures that SimpleMonacoEditor css styles work nicely for Storybook. This is what the comment on main.ts was about. (This took some effort to figure out, even though it's a small change)

Some notes:

  1. I opted to use a local version of SimpleMonacoEditor as we do in the original Codebytes. If in the future, we want to import the one from gamut, we can handle as a Tech Investment item. Alex began some of this work in the past and has an existing RFC that Web Plat was going to inherit, but would add more scope to a project that is already multiphased.
  2. Tests for the full Codebytes component to come at the end.

Screen Shot 2022-01-06 at 11 39 08 PM

PR Checklist

To see the component locally:

  1. Checkout the branch. In the root, run "yarn start". This will start the storybook server. Visit http://localhost:6006/
  2. You can now run code in the story. :)

@BandanaKM BandanaKM requested review from a team and songstephen as code owners January 4, 2022 18:00
@BandanaKM BandanaKM requested review from thedoomshine and removed request for a team January 4, 2022 18:00
@BandanaKM BandanaKM marked this pull request as draft January 4, 2022 18:00
Base automatically changed from bm-add-editor-and-drawers-disc-351 to main January 4, 2022 19:22
@BandanaKM BandanaKM requested review from a team, aionate0812, dougyd92 and j10sanders and removed request for a team January 7, 2022 04:40
${({ hasError, theme }) => `
color: ${hasError ? theme.colors.orange : theme.colors.white};
background-color: ${theme.colors['gray-900']};
background-color: ${colors['gray-900']};
Copy link
Contributor

@borisonr borisonr Jan 10, 2022

Choose a reason for hiding this comment

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

i forget which we prefer theme.colors or importing colors directly but we should go with one instead of both :)
(we use theme.colors in the row above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is a really interesting one! The theme.colors['gray-900'], is different color than the ${colors['gray-900']}. We need the color that comes up in ${colors['gray-900']} but, yeah, colors is definitely deprecated. I'll shoot a message to @dreamwasp and see what the best approach is for a deprecated color?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh thats not great. definitely should loop in gamut team for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

spoke to cass, the new color is ${theme.colors['navy-900']}, so we're covered!

"react-monaco-editor": "0.34.0",
"@monaco-editor/react": "4.3.1",
"react-resize-observer": "1.1.1",
"monaco-editor": "0.20.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

since we are working with the latest version of @monaco-editor/react it may be worth updating the monaco-editor version as well

https://github.com/suren-atoyan/monaco-react/blob/cd924806506646e2270ade2df896b3603f1c3f30/package.json#L36

Copy link
Contributor Author

Choose a reason for hiding this comment

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

awesome, thank you for the heads up!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aionate0812 The amazing thing is that I wasn't getting syntax highlighting before, but with the package updates, I am 🎉

onMount={editorWillMount}
onChange={onChange}
options={{ minimap: { enabled: false } }}
theme="vs-dark"
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 resolved some of the flashing issues we were seeing earlier. It's using monaco's built in dark theme initially, before we add a custom dark theme. In line with how the component currently works.

import { dark } from './theme';
import { Monaco } from './types';

const ReactMonacoEditor = loadable(() => import('@monaco-editor/react'));
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure how this may play with Next.js as it uses dynamic imports instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Best solution here might be to keep this as a normal import, and have the parent component decide to use dynamic imports (next.js) or loadable (monolith) when calling the CodeByteEditor. Updating to this approach for now.

@@ -0,0 +1 @@
CONTAINER_API_BASE=propeller.cc-le-cf.com
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we using the prod endpoint in local? and can you set up the staging and prod ones too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@borisonr jake mentioned that since this is open source, then we want users to only be aware of our prod endpoint, not our staging one.

if we really do want to set up a staging endpoint here, which we would only need once we build a gamut-like storybook experience on a server, we'd probably need to do this in circleci or github actions. else, it's not essential.

for the current purposes, i think this covers what we need! cc'ing @jakemhiller to get some more input, too!

(eventually, the parent/container calling codebytes will pass in a staging/prod endpoint of its own)

Copy link
Contributor

Choose a reason for hiding this comment

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

thats fine! but maybe we dont call this file local then? just have one env file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

totally reasonable!

Copy link
Contributor

@borisonr borisonr left a comment

Choose a reason for hiding this comment

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

we're getting so close!!

@codecademydev
Copy link
Contributor

📬Published Alpha Packages:

@codecademy/codebytes@0.2.1-alpha.4f65b1.0
@codecademy/styleguide@0.2.1-alpha.4f65b1.0

@BandanaKM BandanaKM merged commit eec98ba into main Jan 12, 2022
@BandanaKM BandanaKM deleted the bm-add-simple-monaco-editor-disc-353 branch January 12, 2022 16:16
@BandanaKM BandanaKM restored the bm-add-simple-monaco-editor-disc-353 branch January 12, 2022 16:18
jakemhiller added a commit that referenced this pull request Jan 31, 2022
* origin/main:
  chore(release): publish
  chore: bumped codebytes to next version (#25)
  Revert "add yarn build task for codebytes (#23)" (#24)
  add yarn build task for codebytes (#23)
  chore(release): publish
  feat(Codebytes): Refactor tracking in Codebytes (#19)
  chore(release): publish
  feat(Codebytes): move language selection component disc 354 (#17)
  chore(release): publish
  feat(Codebytes): add simple monaco editor disc 353 (#16)
  chore(release): publish
  feat(Codebytes): add editor and drawers disc 351 (#14)
  chore(release): publish
  feat(Tracking): add search id param to userclick data
  chore(release): publish
  feat(Codebytes): move codebytes parent disc 351 (#11)
  chore(release): publish
  fix(tracking): remove navigator.sendBeacon .bind and add try/catch
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.

5 participants