Skip to content

Topgear #4676

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

Merged
merged 2 commits into from
Jul 22, 2020
Merged

Topgear #4676

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/shared/components/MarkdownRenderer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
*
* Support for additional components can be added to the above file.
*/
import _ from 'lodash';
import PT from 'prop-types';
import React, { Fragment } from 'react';
import { connect } from 'react-redux';

import md from 'utils/markdown';

export default class MarkdownRenderer extends React.Component {
class MarkdownRenderer extends React.Component {
constructor(props) {
super(props);
this.state = {
Expand All @@ -31,10 +33,17 @@ export default class MarkdownRenderer extends React.Component {
}

renderElements(markdown) {
const { preview, spaceName, environment } = this.props;
const {
preview,
spaceName,
environment,
profile,
} = this.props;
if (markdown) {
const compiled = _.template(markdown, { variable: 'profile' });
const interpolated = compiled(profile);
this.setState({
elements: md(markdown, { preview, spaceName, environment }),
elements: md(interpolated, { preview, spaceName, environment }),
});
}
}
Expand All @@ -58,11 +67,24 @@ MarkdownRenderer.defaultProps = {
preview: false,
spaceName: null,
environment: null,
profile: {},
};

MarkdownRenderer.propTypes = {
markdown: PT.string,
preview: PT.bool,
spaceName: PT.string,
environment: PT.string,
profile: PT.shape(),
};

function mapStateToProps(state) {
const profile = state.auth && state.auth.profile ? { ...state.auth.profile } : {};
return { profile };
}

const MarkdownRendererContainer = connect(
mapStateToProps,
)(MarkdownRenderer);

export default MarkdownRendererContainer;