[MM-23418] : Migrate "components/admin_console/schema_text.jsx" and tests to Typescript (#23614)
Этот коммит содержится в:
@@ -2,24 +2,20 @@
|
|||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import marked from 'marked';
|
import marked from 'marked';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {FormattedMessage} from 'react-intl';
|
import {FormattedMessage} from 'react-intl';
|
||||||
|
|
||||||
import FormattedMarkdownMessage, {CustomRenderer} from 'components/formatted_markdown_message';
|
import FormattedMarkdownMessage, {CustomRenderer} from 'components/formatted_markdown_message';
|
||||||
|
|
||||||
export default class SchemaText extends React.PureComponent {
|
type Props = {
|
||||||
static propTypes = {
|
isMarkdown?: boolean;
|
||||||
isMarkdown: PropTypes.bool,
|
isTranslated?: boolean;
|
||||||
isTranslated: PropTypes.bool,
|
text: string | object;
|
||||||
text: PropTypes.oneOfType([
|
textDefault?: string;
|
||||||
PropTypes.string,
|
textValues?: Record<string, React.ReactNode>;
|
||||||
PropTypes.object,
|
}
|
||||||
]).isRequired,
|
|
||||||
textDefault: PropTypes.string,
|
|
||||||
textValues: PropTypes.object,
|
|
||||||
};
|
|
||||||
|
|
||||||
|
export default class SchemaText extends React.PureComponent<Props> {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
isTranslated: true,
|
isTranslated: true,
|
||||||
};
|
};
|
||||||
@@ -56,8 +52,12 @@ export default class SchemaText extends React.PureComponent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
renderUntranslated = () => {
|
renderUntranslated = () => {
|
||||||
if (this.props.isMarkdown) {
|
const {isMarkdown, text} = this.props;
|
||||||
const html = marked(this.props.text, {
|
if (isMarkdown) {
|
||||||
|
if (typeof text === 'object') {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
const html = marked(text, {
|
||||||
breaks: true,
|
breaks: true,
|
||||||
sanitize: true,
|
sanitize: true,
|
||||||
renderer: new CustomRenderer(),
|
renderer: new CustomRenderer(),
|
||||||
@@ -66,7 +66,7 @@ export default class SchemaText extends React.PureComponent {
|
|||||||
return <span dangerouslySetInnerHTML={{__html: html}}/>;
|
return <span dangerouslySetInnerHTML={{__html: html}}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <span>{this.props.text}</span>;
|
return <span>{text}</span>;
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
Ссылка в новой задаче
Block a user