-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1928: Show warnings in Info component
- Loading branch information
Showing
8 changed files
with
113 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { Suspense, lazy } from "react"; | ||
import { connect } from "react-redux"; | ||
import styled from 'styled-components'; | ||
import { FaExclamationTriangle } from "react-icons/fa"; | ||
import { withTranslation } from 'react-i18next'; | ||
|
||
const MarkdownDisplay = lazy(() => import("../markdownDisplay")); | ||
|
||
const WarningContainer = styled.div` | ||
background-color: #FFF1D1; | ||
display: flex; | ||
align-items: stretch; | ||
`; | ||
|
||
const WarningIconContainer = styled.div` | ||
background-color: #FFC641; | ||
padding: 0 7px; | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
const WarningIcon = styled.div` | ||
padding-top: 3px; | ||
color: white; | ||
font-size: 24px; | ||
`; | ||
|
||
const WarningText = styled.div` | ||
padding: 0 7px; | ||
font-size: 15px; | ||
`; | ||
|
||
/** | ||
* React component for the warning of the current dataset. | ||
*/ | ||
@connect((state) => { | ||
return { | ||
warning: state.metadata.warning | ||
}; | ||
}) | ||
class Warning extends React.Component { | ||
render() { | ||
const { warning } = this.props; | ||
|
||
if (warning === undefined) return null; | ||
|
||
return ( | ||
<Suspense fallback={null}> | ||
<WarningContainer> | ||
<WarningIconContainer> | ||
<WarningIcon> | ||
<FaExclamationTriangle /> | ||
</WarningIcon> | ||
</WarningIconContainer> | ||
<WarningText> | ||
<MarkdownDisplay | ||
mdstring={warning} | ||
placeholder="This dataset contained a warning message to be displayed here, however it wasn't correctly formatted."/> | ||
</WarningText> | ||
</WarningContainer> | ||
</Suspense> | ||
); | ||
} | ||
} | ||
|
||
const WithTranslation = withTranslation()(Warning); | ||
export default WithTranslation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
import React from "react"; | ||
import { parseMarkdown } from "../../util/parseMarkdown"; | ||
|
||
export default function MarkdownDisplay({ mdstring, ...props }) { | ||
let cleanDescription; | ||
export default function MarkdownDisplay({ mdstring, placeholder, ...props }) { | ||
try { | ||
cleanDescription = parseMarkdown(mdstring); | ||
return ( | ||
<div | ||
{...props} | ||
dangerouslySetInnerHTML={{ __html: parseMarkdown(mdstring) }} | ||
/> | ||
); | ||
} catch (error) { | ||
console.error(`Error parsing Markdown: ${error}`); | ||
cleanDescription = '<p>There was an error parsing the Markdown. See the JS console.</p>'; | ||
if (typeof mdstring === 'string') { | ||
// This runs when there is a bug within parseMarkdown or the marked package. | ||
console.error(`There was an error parsing the provided text as Markdown. Using the raw text as-is. Error: ${error}`); | ||
return ( | ||
<div {...props}> | ||
<p>{mdstring}</p> | ||
<p>Note: This message was meant to be rendered with formatting, however there was an error parsing the message as Markdown.</p> | ||
</div> | ||
); | ||
} else { | ||
console.error(`There was an error parsing the provided text as Markdown or raw text. Error: ${error}`); | ||
return ( | ||
<div {...props}> | ||
<p>{placeholder}</p> | ||
</div> | ||
); | ||
} | ||
} | ||
return ( | ||
<div | ||
{...props} | ||
dangerouslySetInnerHTML={{ __html: cleanDescription }} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters