Skip to content

Commit

Permalink
Merge pull request #13462 from newrelic/tabatha/comment-component
Browse files Browse the repository at this point in the history
feat: Create comment component for markdown pages
  • Loading branch information
tabathadelane committed Jun 13, 2023
2 parents 783f48c + 484c68d commit 26e3f40
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ exports[`serializes mark to html 1`] = `"<mark data-type=\\"component\\"><p>PDF<
exports[`serializes var to html 1`] = `"<var data-type=\\"component\\"><p>JAVA_AGENT_VERSION</p></var>"`;
exports[`serializing CONTRIBUTOR_NOTE removes it from translated files 1`] = `""`;
exports[`test <InlineCode> element serializes and adds 'notranslate' class to element 1`] = `"<code data-type=\\"component\\" data-component=\\"InlineCode\\" class=\\"notranslate\\">This is a test</code>"`;
exports[`test <b> element serializes 1`] = `
Expand Down
12 changes: 12 additions & 0 deletions scripts/actions/__tests__/serialize-mdx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,15 @@ test('serialize InlineSignup component', async () => {
const html = await serializeMDX(mdx);
expect(html).toMatchSnapshot();
});

test('serializing CONTRIBUTOR_NOTE removes it from translated files', async () => {
const html = await serializeMDX(`
<CONTRIBUTOR_NOTE>
This is a note to future authors about the MDX content.
It does not render in the UI
</CONTRIBUTOR_NOTE>
`);

expect(html).toMatchSnapshot();
});
5 changes: 5 additions & 0 deletions scripts/actions/utils/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ module.exports = {
wrapChildren: false,
}),
},
CONTRIBUTOR_NOTE: {
// this pulls this component out of translated files
// there should never be anything to deserialize
serialize: () => null,
},
ExternalLink: {
deserialize: deserializeComponent,
serialize: serializeComponent,
Expand Down
8 changes: 8 additions & 0 deletions src/components/ContributorNote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* In place of comments, this component is intended to be used by authors
* to leave important notes about MDX content for future contributors.
*
* It is not rendered in the UI and is not translated.
*/
const ContributorNote = () => null;

export default ContributorNote;
2 changes: 2 additions & 0 deletions src/components/MDXContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import InlinePopover from './InlinePopover';
import InstallFeedback from './InstallFeedback';
import MDXButton from './MDXButton';
import MDXButtonGroup from './MDXButtonGroup';
import ContributorNote from './ContributorNote';
import MDXTechTileGrid from './MDXTechTileGrid';
import PropTypes from 'prop-types';
import React from 'react';
Expand Down Expand Up @@ -91,6 +92,7 @@ const defaultComponents = {
ButtonLink: (props) => <MDXButton as={Link} {...props} />,
ButtonGroup: MDXButtonGroup,
DoNotTranslate: ({ children }) => <>{children}</>,
CONTRIBUTOR_NOTE: ContributorNote,
Tabs: Tabs,
TabsBar: Tabs.Bar,
TabsBarItem: Tabs.BarItem,
Expand Down

0 comments on commit 26e3f40

Please sign in to comment.