Skip to content

Commit

Permalink
remove react-markdown lib
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksii Orel <[email protected]>
  • Loading branch information
olexii4 committed Jan 15, 2025
1 parent 6876874 commit c0552f4
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 958 deletions.
2 changes: 1 addition & 1 deletion .deps/EXCLUDED/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This file lists dependencies that do not need CQs or auto-detection does not wor
| `@patternfly/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@patternfly/react-icons/4.93.7) |
| `@patternfly/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@patternfly/react-table/4.113.6) |
| `[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/blueimp-md5/2.19.0) |
| `[email protected].16` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.16) |
| `[email protected].18` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.18) |
| `[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/cookie-signature/1.2.1) |
| `[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/elliptic/6.6.1) |
| `[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fast-uri/2.4.0) |
Expand Down
4 changes: 4 additions & 0 deletions .deps/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #10812 |
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #9382 |
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #15963 |
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #8266 |
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #8266 |
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #8266 |
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/[email protected]`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -134,6 +136,7 @@
| [`@typescript-eslint/[email protected]`](https://github.com/typescript-eslint/typescript-eslint.git) | BSD-2-Clause | #14423 |
| [`@typescript-eslint/[email protected]`](https://github.com/typescript-eslint/typescript-eslint.git) | MIT | clearlydefined |
| [`@typescript-eslint/[email protected]`](https://github.com/typescript-eslint/typescript-eslint.git) | MIT | clearlydefined |
| [`@ungap/[email protected]`](git+https://github.com/ungap/structured-clone.git) | ISC | clearlydefined |
| [`@webassemblyjs/[email protected]`](https://github.com/xtuc/webassemblyjs.git) | MIT | clearlydefined |
| [`@webassemblyjs/[email protected]`](https://github.com/xtuc/webassemblyjs.git) | MIT | #7959 |
| [`@webassemblyjs/[email protected]`](https://github.com/xtuc/webassemblyjs.git) | MIT | #7969 |
Expand Down Expand Up @@ -267,6 +270,7 @@
| [`[email protected]`](git+https://github.com/ljharb/define-data-property.git) | MIT | #10591 |
| `[email protected]` | MIT | clearlydefined |
| [`[email protected]`](git://github.com/ljharb/define-properties.git) | MIT | #7116 |
| `[email protected]` | MIT | clearlydefined |
| `[email protected]` | MIT | clearlydefined |
| `[email protected]` | MIT | clearlydefined |
| [`[email protected]`](https://github.com/jestjs/jest.git) | MIT | clearlydefined |
Expand Down
91 changes: 1 addition & 90 deletions .deps/prod.md

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions packages/dashboard-frontend/jest.setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,19 @@ jest.mock('@/components/CheTooltip', () => {
};
});

jest.mock('react-markdown', () => {
return jest.fn(props => {
return React.createElement('a', null, props.children, props.content);
});
jest.mock('@/components/BasicViewer', () => {
return {
BasicViewer: jest.fn(props => {
return (
<textarea
id={props.id}
data-testid={props['data-testid']}
value={props.value}
readOnly={true}
/>
);
}),
};
});

jest.mock('gravatar-url', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/dashboard-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@
"inversify-inject-decorators": "^3.1.0",
"inversify-react": "^1.1.0",
"js-yaml": "^4.1.0",
"lodash": "^4.7.21",
"lodash": "^4.17.21",
"multi-ini": "^2.3.2",
"process": "^0.11.10",
"qs": "^6.12.1",
"react": "^18.3.1",
"react-copy-to-clipboard": "^5.1.0",
"react-dom": "^18.3.1",
"react-helmet": "^6.1.0",
"react-markdown": "^9.0.1",
"react-pluralize": "^1.6.3",
"react-redux": "^9.1.2",
"react-router-dom": "^6.26.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`BasicViewer snapshot 1`] = `
<div
className="basicViewer"
>
<div
id="basic-viewer-id"
/>
</div>
<textarea
id="basic-viewer-id"
readOnly={true}
value="line 1
line 2
line 3"
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ describe('BasicViewer', () => {
const textbox = screen.getByRole('textbox');

// no new line character
expect(textbox).toHaveTextContent('line 1line 2line 3');
expect(textbox).toHaveTextContent('line 1 line 2 line 3');

reRenderComponent('line 4\nline 5\nline 6');

// no new line character
expect(textbox).toHaveTextContent('line 4line 5line 6');
expect(textbox).toHaveTextContent('line 4 line 5 line 6');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class BasicViewer extends React.PureComponent<Props> {
});
editor.setSize(`100%`, `100%`);
editor.setValue(this.props.value);
editor.save();
editor.focus();

this.editor = editor;
}
Expand All @@ -44,14 +44,14 @@ export class BasicViewer extends React.PureComponent<Props> {
componentDidUpdate(prevProps: Readonly<Props>): void {
if (this.editor && this.props.value !== prevProps.value) {
this.editor.setValue(this.props.value);
this.editor.save();
this.editor.focus();
}
}

public render(): React.ReactElement {
return (
<div className={styles.basicViewer}>
<textarea id={this.props.id} value={this.props.value}></textarea>
<textarea id={this.props.id} value={this.props.value} readOnly={true}></textarea>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@ export class DevfileViewer extends React.PureComponent<Props> {
});
editor.setSize(`100%`, `100%`);
editor.setValue(this.props.value);
editor.save();
editor.focus();

this.editor = editor;
}
}

componentDidUpdate(prevProps: Readonly<Props>): void {
if (this.editor && this.props.value !== prevProps.value) {
this.editor.setValue(this.props.value);
this.editor.save();
}
componentDidUpdate(): void {
this.editor.setValue(this.props.value);
this.editor.focus();
}

public render(): React.ReactElement {
return (
<div className={styles.devfileViewer}>
<textarea id={this.props.id}></textarea>
<textarea id={this.props.id} readOnly={true}></textarea>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,41 @@ describe('Editor Selector Entry', () => {
});

describe('provider info', () => {
test('show text', () => {
test('convert markdown links into html', () => {
renderComponent(
editorGroup[0].id,
[...editorGroup].map(editor => Object.assign({}, editor, { provider: 'Provided by...' })),
[...editorGroup].map(editor =>
Object.assign({}, editor, {
provider:
'Provided by [DummyProvider](https://dummy.test-provider.com/) under [DummyLicense](https://www.dummy.test-licence.com/docs/)',
}),
),
);

expect(screen.queryByText('Provided by...')).not.toBeNull();
const providerInfo = screen.getByTestId('providerInfo');

expect(providerInfo).not.toBeNull();
expect(providerInfo.innerHTML).toEqual(
'<p>Provided by <a href="https://dummy.test-provider.com/" target="_blank" rel="noopener noreferrer">DummyProvider</a> under <a href="https://www.dummy.test-licence.com/docs/" target="_blank" rel="noopener noreferrer">DummyLicense</a></p>',
);
});
test('convert text into html', () => {
renderComponent(
editorGroup[0].id,
[...editorGroup].map(editor =>
Object.assign({}, editor, {
provider:
'Provided by <a href="https://dummy.test-provider.com/">DummyProvider</a> under <a href="https://www.dummy.test-licence.com/docs/">DummyLicense</a>',
}),
),
);

const providerInfo = screen.getByTestId('providerInfo');

expect(providerInfo).not.toBeNull();
expect(providerInfo.innerHTML).toEqual(
'<p>Provided by <a href="https://dummy.test-provider.com/">DummyProvider</a> under <a href="https://www.dummy.test-licence.com/docs/">DummyLicense</a></p>',
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from '@patternfly/react-core';
import { CheckIcon } from '@patternfly/react-icons';
import React from 'react';
import ReactMarkdown from 'react-markdown';
import sanitizeHtml from 'sanitize-html';

import styles from '@/components/EditorSelector/Gallery/Entry/index.module.css';
import { TagLabel } from '@/components/TagLabel';
Expand Down Expand Up @@ -62,37 +62,11 @@ export class EditorSelectorEntry extends React.PureComponent<Props, State> {
};
}

private setAttribute(
widgetId: string,
querySelector: string = 'a',
attributeName: string = 'target',
attributeValue: string = '_blank',
): void {
clearTimeout(this.timerId);
this.timerId = window.setTimeout(() => {
const widget = document.getElementById(widgetId);
if (widget) {
widget.querySelectorAll(querySelector).forEach(targetElement => {
targetElement.setAttribute(attributeName, attributeValue);
});
}
}, 500);
}

private get id(): string {
return `editor-selector-card-${this.state.activeEditor.id}`;
}

public componentDidMount(): void {
if (this.state.activeEditor.provider) {
this.setAttribute(this.id);
}
}

public componentDidUpdate(prevProps: Props): void {
if (this.state.activeEditor.provider) {
this.setAttribute(this.id);
}
if (prevProps.selectedId !== this.props.selectedId) {
const selectedEditor = this.props.editorsGroup.find(
editor => editor.id === this.props.selectedId,
Expand Down Expand Up @@ -238,7 +212,25 @@ export class EditorSelectorEntry extends React.PureComponent<Props, State> {
</CardBody>
{activeEditor.provider && (
<CardFooter>
<ReactMarkdown className={styles.provider}>{activeEditor.provider}</ReactMarkdown>
<div data-testid="providerInfo" className={styles.provider}>
{React.createElement('p', {
dangerouslySetInnerHTML: {
__html: sanitizeHtml(
activeEditor.provider.replace(
/\[([^\]]+)\]\(([^)]+)\)/g,
'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>',
),
{
allowedTags: ['a'],
allowedAttributes: {
a: ['href', 'target', 'rel'],
},
allowedSchemes: ['http', 'https'],
},
),
},
})}
</div>
</CardFooter>
)}
</Card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('GitConfigViewer', () => {
};
renderComponent(config);

const viewerContent = screen.getByTestId('basic-viewer-value');
const viewerContent = screen.getByRole('textbox');
expect(viewerContent).toHaveTextContent('[user] name="John Doe" email="[email protected]"');
});
});
Expand Down
2 changes: 1 addition & 1 deletion scripts/yarn/old_version/.deps/EXCLUDED/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This file lists dependencies that do not need CQs or auto-detection does not wor
| `@patternfly/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@patternfly/react-icons/4.93.7) |
| `@patternfly/[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/@patternfly/react-table/4.113.6) |
| `[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/blueimp-md5/2.19.0) |
| `[email protected].16` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.16) |
| `[email protected].18` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.18) |
| `[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/cookie-signature/1.2.1) |
| `[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/elliptic/6.6.1) |
| `[email protected]` | [clearlydefined](https://clearlydefined.io/definitions/npm/npmjs/-/fast-uri/2.4.0) |
Expand Down
Loading

0 comments on commit c0552f4

Please sign in to comment.