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(editor): improve documentation editor using Remirror #6631

Merged

Conversation

ngamanda
Copy link
Contributor

@ngamanda ngamanda commented Dec 4, 2022

Highlights

editor-demo

  • Improved UX for documentation editing with
    • Modals to Add Links / Images
    • Inline menus for quicker access to style text
    • Inline link previews
  • @mentions: users can now tag entities by typing @. More details about the entity shown upon hovering over the mention
  • Resizable images: users can now resize images
    • By default, uploading images will be saved as markdown (i.e. ![alt text](my-image.png)). Upon resizing, the image will be stored as HTML Markup (i.e. <img height="46" width="54" src="my-image.png" alt="alt text" />)
  • Table editing
    • Controls to add/remove table rows/columns easily
    • Tables are converted to markdown where possible. Otherwise, it will be stored as in HTML Markup. (Markdown tables cannot contain lists, headings, code blocks, or another table)

Summary of Changes

  • Install additional packages - @remirror/* for editor, prosemirror-autocomplete for powering inline suggestions, turndown-plugin-gfm to add gfm support for tables
  • Add custom buttons/controls to fit with AntD stylings
  • Add new Remirror DataHubMentionsExtension to contain rendering logic and to import prosemirror-autocomplete plugin
  • Remove sanitising of documentations located outside the editor (already handled by Remirror)
  • Update Jest configuration to explicitly transpile lib0 and y-protocols, keeping '^.+\\.module\\.(css|sass|scss)$' from default configurations

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Updating DataHub

@github-actions github-actions bot added the product PR or Issue related to the DataHub UI/UX label Dec 4, 2022
@github-actions
Copy link

github-actions bot commented Dec 4, 2022

Unit Test Results (build & test)

621 tests  ±0   617 ✔️ ±0   15m 46s ⏱️ -1s
157 suites ±0       4 💤 ±0 
157 files   ±0       0 ±0 

Results for commit 739654c. ± Comparison against base commit 2de9d3d.

♻️ This comment has been updated with latest results.

@ngamanda ngamanda force-pushed the remirror-documentation branch 2 times, most recently from b114d15 to 739654c Compare December 5, 2022 05:45
@anshbansal anshbansal added the community-contribution PR or Issue raised by member(s) of DataHub Community label Dec 6, 2022
@chriscollins3456 chriscollins3456 self-assigned this Dec 6, 2022
Copy link
Collaborator

@chriscollins3456 chriscollins3456 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 incredible! I have some comments here and there, some suggestions and some requests for things like docs and tests. However overall this is looking so good.

I pulled it down myself and am having a blast with it locally! You guys absolutely killed this. After you get back to us with my comments / suggestions let's work to get this in soon!

Comment on lines 43 to 52
jest: {
configure: (jestConfig) => {
jestConfig.transformIgnorePatterns = [
'node_modules/(?!(lib0|y-protocols)).+\\.(js|jsx|mjs|cjs|ts|tsx)$',
'^.+\\.module\\.(css|sass|scss)$',
];
return jestConfig;
},
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a comment as to what this is doing and what it's necessary?

const hideLinksButton = properties?.hideLinksButton;
const { urn, entityData } = useEntityData();
const refetch = useRefetch();
const description = entityData?.editableProperties?.description || entityData?.properties?.description || '';
const sanitizedDescription = DOMPurify.sanitize(description);
Copy link
Collaborator

Choose a reason for hiding this comment

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

even if remirror also handles this, do you think it's a problem to sanitize here as well? just in case anything ever changes with remirror I really want to avoid any unsafe scripts or anything getting into documentation

Copy link
Collaborator

Choose a reason for hiding this comment

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

same idea with sanitizing below before sending to the BE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I remembered the double sanitisation did throw out some unwanted syntax in the output. Let me take a look at it again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

okay if that's the case I don't think it's a problem as long as we feel good about remirror being able to handle this for us

onChange?: (md: string) => void;
};

export const Editor = forwardRef((props: EditorProps, ref) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice this is my first time seeing forwardRef - nicer than having to explicitly pass in a ref as another old prop!

Comment on lines +74 to +78
useMount(() => {
manager.view.focus();
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

i've been waiting for something like useMount... what a time to be alive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha yup, react-use is a lifesaver!

import { MentionsComponent } from './extensions/mentions/MentionsComponent';

type EditorProps = {
readonly?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: can we change to camel case and be readOnly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will make the change

handleEvents?: Handler<(action: AutocompleteAction) => boolean>;
}

class DataHubMentionsExtension extends NodeExtension<DataHubMentionsOptions> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah as I mentioned in another comment, some docs here would be great as creating out own remirror extension requires a lot of special knowledge.

import { CommandButton } from './CommandButton';
import { LinkModal } from './LinkModal';

export const AddLinkButton = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

these are great individual toolbar components! very useful and organzied

import Icon from '@ant-design/icons';
import { CustomIconComponentProps } from '@ant-design/icons/lib/components/Icon';

export const CodeIcon = (props: Partial<CustomIconComponentProps>) => (
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is awesome

overflow: hidden;
`;

export const FloatingToolbar = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks like the floating toolbar gets cut off from the top toolbar:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix this!

<Toolbar />
<CodeBlockToolbar />
<FloatingToolbar />
<TableComponents tableCellMenuProps={{ Component: TableCellMenu }} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it possible to resize columns and rows of the table with your mouse? I'm trying to do it locally but not figuring out how if it is possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it's possible and it's enabled in Grab's fork. The downside is that the table will be stored in HTML rather than Markdown format. I wasn't sure if DataHub wanted that activated since you can't 'un-resize' a table (or we could also introduce a button to 'un-resize' it but I'll need more time to investigate it).

Copy link
Collaborator

Choose a reason for hiding this comment

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

okay gotcha! yeah if it were possible to resize and store in markdown I think that would be fantastic, but if it's too much of a lift initially I think we can come back to that as a followup improvement.

Copy link
Collaborator

@chriscollins3456 chriscollins3456 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 so great!

Thanks so much for getting back to my comments and adding all the tests and what not. I pulled down again and tried locally and things are looking awesome :)

I have one more comment about making links target="_blank" so they open in a new tab, but otherwise I think this thing is ready to rumble!

I did notice that there's a few conflicts with master, though, so once those are resolved and we get CI to pass everything, let's get this guy merged.

@@ -0,0 +1,69 @@
import { htmlToMarkdown } from '../../../../components/editor/extensions/htmlToMarkdown';

const cases = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

thank you!

handleClose: () => void;
};

export const LinkModal = (props: LinkModalProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a way that we can add target: "_blank" to links created in documentation so they open in a new tab?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, fixed in bd3d8d2

Comment on lines +317 to +318
env:
NODE_OPTIONS: "--max-old-space-size=3072"
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh it's to resolve the failing build that was caused by FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory. in https://github.com/datahub-project/datahub/actions/runs/3804191769/jobs/6471221050. This line simply increases the memory limit allocated to node. If there are other solutions please feel free to make changes to the PR too!

Copy link
Collaborator

Choose a reason for hiding this comment

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

it looks like this failure is still happening :( do you know if we need to put this type of change elsewhere?

Copy link
Collaborator

Choose a reason for hiding this comment

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

another initiative we've discussed is removing the unneeded dependencies from our package.json - unsure how many things we can remove but if we can shrink our dependencies this may help solve this problem! it's something i'm looking into and will see if it helps 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.

Hmm, the latest build passed though: https://github.com/datahub-project/datahub/actions/runs/3805789729/jobs/6559405831. The only pipeline that's failing is https://github.com/datahub-project/datahub/actions/runs/3805789729/jobs/6559407548 which looks unrelated to the documentation, probably a flaky test (but I can't rereun it :x)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also let me know if you need help looking into shrinking the dependencies 🗡️ !

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah so it looks like it's fixed in the Docker, Build, Scan, Test runs, but i'm still seeing the error in the logs on the general build & test / build job (https://github.com/datahub-project/datahub/actions/runs/3805789734/jobs/6521531814) - you'll have to search for it cuz that's a huge log lol

also it seems that that's timing out after 60 minutes, my hunch is that it's related to this build failing or even that something is taking much longer for some reason.

@chriscollins3456
Copy link
Collaborator

everything is passing in CI now woo! except for these failing Monitoring tests but those are failing for all open PRs

@ngamanda
Copy link
Contributor Author

Awesome, thanks for the help @chriscollins3456 !

Copy link
Collaborator

@jjoyce0510 jjoyce0510 left a comment

Choose a reason for hiding this comment

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

I finally got a chance to take a deep look at this PR.

All I have to say is: WOW. The new experience looks and feels incredible - A major improvement on usability that will benefit many people (thousands of active users) in the community directly!

This PR represents an incredible piece of collaboration between Grab and the DataHub Community. I want to say thank you to @ngamanda, @chriscollins3456, and of course Harvey on behalf of the entire DataHub Team and the broader community. I look forward to continued partnership between our teams as we continue to improve DataHub.

Very happy to give this a final "LGTM" stamp.

Cheers!
John

@chriscollins3456 chriscollins3456 merged commit 087b169 into datahub-project:master Jan 17, 2023
shirshanka pushed a commit to shirshanka/datahub that referenced this pull request Jan 18, 2023
…oject#6631)

Co-authored-by: Chris Collins <chriscollins3456@gmail.com>
ericyomi pushed a commit to ericyomi/datahub that referenced this pull request Jan 18, 2023
…oject#6631)

Co-authored-by: Chris Collins <chriscollins3456@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution PR or Issue raised by member(s) of DataHub Community product PR or Issue related to the DataHub UI/UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants