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

Add OSCALJsonEditor Component #265

Merged
merged 32 commits into from
Mar 2, 2022
Merged

Add OSCALJsonEditor Component #265

merged 32 commits into from
Mar 2, 2022

Conversation

pkothare
Copy link
Member

@pkothare pkothare commented Feb 21, 2022

Uses react-split to create a vertically split element into two panes. This only manifests in REST mode and starts off with 50/50 split for the two panes. The end user is then able to adjust the width of the pane up to a certain limit.

  • The left pane wraps the OSCALJsonEditor component which consists of a configured instance of the @monaco-editor component. The editor is does take up 100% of the vertical height of the HTML page, instead, it adapts to screen height and is positioned relative to the scrollport based on sticky positioning.
  • The right pane wraps the viewer, which based on the route is one of the specific OSCALLoader components.

TO DOs:

  • Migrate static CSS to makeStyles used by MUI
  • Use fetch to complete PUT request
  • Write tests
  • Fix overflow issues with OSCAL components. MUI 4 has significant issues element overflows when generic spacing is used.

References

Added conditional checks for `isRestMode` and added the
react-split control so that when `isRestMode` is `true`
the `OSCALLoader` component will render a split pane.
The `maxWidth` value of `xl` was added which overrides the default of
large. This was done so that the JSON editor can be accomodated in the
application.
The split pane defaults were updated so that the JSON Editor and viewer
share a 50/50 split. The `minSize` value was also updated to 500 as a
sensible default, because collapsing a pane to 0 can cause issues.
The updates improve the look and feel based on the margins and grid
layout. The editor was also made sticky so that it follows veritical
scrolling.
Removed overflow attributes, since they cause conflicts with sticky HTML
elements.
The split pane defaults were updated so that the JSON Editor and viewer
share a 50/50 split. The `minSize` value was also updated to 500 as a
sensible default, because collapsing a pane to 0 can cause issues.
The split pane defaults were updated so that the JSON Editor and viewer
share a 50/50 split. The `minSize` value was also updated to 500 as a
sensible default, because collapsing a pane to 0 can cause issues.
@kylelaker
Copy link
Contributor

kylelaker commented Feb 25, 2022

Seems like the content uses ~100% of the display width in non-REST mode now. Is that an intentional change?

Other small nitpicks on UI stuff:

  • The dropdown for the document and the toggle for REST mode should be aligned (REST mode toggle is currently higher)
  • The top bar goes away when scrolling -- do we want to keep it? maybe not?
  • Save/Discard buttons require scrolling to see (on my monitor)

@pkothare
Copy link
Member Author

pkothare commented Feb 25, 2022

Seems like the content uses ~100% of the display width in non-REST mode now. Is that an intentional change?

Intentional, based on the screenshot that @rgauss shared with us on the potential design of including an editor. If we change the display width between rest/non-rest mode, the layout changes pretty dramatically which leads to some cognitive load. Nonetheless, this has been factored by a very small change to maxWidth. So if we decide to go smaller we can. 🤞, all other components are dynamically sized.

The dropdown for the document and the toggle for REST mode should be aligned (REST mode toggle is currently higher)

Worked this in already, the changes will be up soon.

The top bar goes away when scrolling -- do we want to keep it? maybe not?

I tried not to modify existing layout/style decisions. Prior to this PR, the header was not fixed, so no change there. However changing it to be fixed isn't that hard.

Save/Discard buttons require scrolling to see (on my monitor).

This was intentional, so that when you do scroll past a certain point (i.e. when the top nav and selector are past the scroll port), the editor (including the buttons) fills up the viewport vertical space. Eventually the OSCALLoaderForm will move to a left hand drawer which will pull the editor and the buttons up, and no scroll will be required. We can either reduce the height now, or it can be part of the update when we develop the left hand drawer. It's mostly a matter of testing with different Editor Vertical Height values

@pkothare pkothare marked this pull request as ready for review February 25, 2022 21:23
kylelaker
kylelaker previously approved these changes Feb 26, 2022
Copy link
Contributor

@kylelaker kylelaker left a comment

Choose a reason for hiding this comment

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

This looks good. There are things it might be sorta nice to fix in future tickets but that I don't think should slow down our progress here. A few of them are:

  • base64 encoding should be handled as part of the build process, we should avoid directly writing b64 strings directly into the application (we do have Webpack here which may help)
  • it would be cool if the browser find functionality worked within the JSON editor. it has it's own (better) find functionality but you have to click within it and if you don't the browser doesn't see any of the Editor content
  • TABS?! 😆

@pkothare
Copy link
Member Author

base64 encoding should be handled as part of the build process, we should avoid directly writing b64 strings directly into the application (we do have Webpack here which may help)

Webpack should help here, after doing some exploratory testing, I feel like this should be improved as part of another PR, since there are some decisions that need to be made around which one of the following paths we should use to bundle/package the library:

  • microbundle-crl
  • webpack
  • webpack + microbundle-crl

Currently we are using the microbundle-crl to create the bundle. If in the future we decide to use webpack, it will help optimize packaging; and IMO my least favorite option is to use webpack + microbundle-crl because it will introduce too much complexity in packaging.

it would be cool if the browser find functionality worked within the JSON editor. it has it's own (better) find functionality but you have to click within it and if you don't the browser doesn't see any of the Editor content

Confirmed that I can replicate this, the browser find only matches text in the current viewport, this is because the editor is maintains the rest of the text in virtual DOM. Not sure how we get around it, unless we render all the lines. However, the OSCAL JSON files can sometimes be 70K+ lines, which when rendered might lead to a poor experience. Maybe there is a better way that I just haven't discovered yet 🤷

TABS?! 😆

Note for future improvement: Tab Trapping.

src/components/OSCALLoader.js Show resolved Hide resolved
src/components/OSCALLoaderForm.js Outdated Show resolved Hide resolved
src/components/OSCALLoader.js Outdated Show resolved Hide resolved
src/components/OSCALJsonEditor.js Show resolved Hide resolved
src/components/OSCALJsonEditor.js Outdated Show resolved Hide resolved
result = isRestMode ? (
<Split className={classes.split} minSize={500} sizes={[50, 50]}>
<Box>
<OSCALJsonEditor value={oscalData} onSave={handleRestPut} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Here oscalData will often contain fields other than what's returned in the REST response due to things like profile resolution. For example, SSPs will contain a resolvedControls array that should not be shown in source and should not be sent in the PUT REST request.

Copy link
Member Author

Choose a reason for hiding this comment

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

Handled the removal of resolvedControls in cf83ad1. If there are any others that need to be removed, please let me know. It's pretty opaque to me how those got in added to oscalData.

Copy link
Contributor

Choose a reason for hiding this comment

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

The way the additional fields are populated and passed in the resolvers (example) is currently a bit sloppy.

At some point we should revisit how we pass that additional info around to the components, but for now, perhaps we should consider shoving the original response string in something like oscalData.oscalSource rather than the approach of copying and removing what was added?

Copy link
Contributor

Choose a reason for hiding this comment

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

resolvedControls was just one example, modifications is another.

perhaps we should consider shoving the original response string in something like oscalData.oscalSource rather than the approach of copying and removing what was added?

Update layout of editor, hide `resolvedControls` attribute,
and minor changes that improve testing. Tests were added in
OSCALJsonEditor.test.js.
Copy link
Contributor

@hreineck hreineck left a comment

Choose a reason for hiding this comment

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

UI looks great tested locally. Would like to see the toggle functionality as Ray described but other than that ready to merge.

@kylelaker
Copy link
Contributor

@pkothare This merge conflict stemmed from #286 if that helps at all in the conflict resolution.

@kylelaker kylelaker dismissed their stale review March 1, 2022 16:14

Based on @rgauss's comments, I am going to dismiss my review and withold approval until those issues are resolved.

This change adds the a `Fab` button that floats over the enitre
viewer via a toolbar. Upon clicking the button, the JSON editor is
toggled to either be displayed or hidden.
@rgauss
Copy link
Contributor

rgauss commented Mar 2, 2022

@kylelaker, have your concerns been addressed here?

@kylelaker
Copy link
Contributor

@rgauss I think so for the most part. I had previously approved and I think then dismissed because others had raised concerns. I haven't been following the developments on this branch super closely but I have no objections to merging it.

@rgauss rgauss merged commit cecc1af into develop Mar 2, 2022
@rgauss rgauss deleted the feature/json-editor branch March 2, 2022 17:58
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.

None yet

4 participants