Skip to content

Commit

Permalink
fix: updated changes and added text with link support
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvanshus-crest committed May 12, 2021
1 parent 6c94df9 commit e14c940
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
7 changes: 6 additions & 1 deletion ui/src/main/webapp/components/ControlWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class ControlWrapper extends React.PureComponent {
render() {
const { field, options, type, label, tooltip, help, encrypted = false } = this.props.entity;
const { handleChange, addCustomValidator, utilCustomFunctions } = this.props.utilityFuncts;
const { text, link, color } = this.props.markDownMessage || {};
// We have to put empty object because markDownMessage prop can be undefined
// because we are not explicitly setting it but expecting it from custom hooks only.
const { text, link, color, markdownType, token, linkText } = this.props.markDownMessage || {};
let rowView;
if (this.props.entity.type === 'custom') {
const data = {
Expand Down Expand Up @@ -82,6 +84,9 @@ class ControlWrapper extends React.PureComponent {
text={ text || '' }
link={ link || '' }
color={ color || ''}
markdownType={ markdownType || '' }
token={ token || '' }
linkText={ linkText || '' }
/>
{help}
</>
Expand Down
33 changes: 29 additions & 4 deletions ui/src/main/webapp/components/MarkDownMessage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,36 @@ const MarkdownWrapper = styled.div`
`;

function MarkDownMessage(props) {

function flatMap(array, fn) {
var markdownText = [];
for (var i = 0; i < array.length; i++) {
var mapping = fn(array[i]);
markdownText = markdownText.concat(mapping);
}
return markdownText;
}

var markdownText = props.text;
markdownText = flatMap(markdownText.split(props.token), function (part) {
return [part, <Link data-test="msg-markdown" key= {part} to={props.link}>{props.linkText}</Link>];
});

markdownText.pop();

return (
<>
{props.link !== '' ?
<Link to={props.link} >
{props.markdownType === 'link' ?
<Link data-test="msg-markdown" to={props.link}>
{props.text}
</Link>
:
<MarkdownWrapper color={props.color}>{props.text}</MarkdownWrapper>
props.markdownType === 'hybrid' ?
markdownText
:
<MarkdownWrapper color={props.color} data-test="msg-markdown">
{props.text}
</MarkdownWrapper>
}
</>
);
Expand All @@ -26,7 +48,10 @@ function MarkDownMessage(props) {
MarkDownMessage.propTypes = {
text: PropTypes.string,
link: PropTypes.string,
color: PropTypes.string
color: PropTypes.string,
markdownType: PropTypes.string,
token: PropTypes.string,
linkText: PropTypes.string
};

export default MarkDownMessage;

0 comments on commit e14c940

Please sign in to comment.