-
Notifications
You must be signed in to change notification settings - Fork 43
feat: [DHIS2-21266] Integrate react Markdown lib #4621
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
Open
simonadomnisoru
wants to merge
19
commits into
master
Choose a base branch
from
DHIS2-21266-from-fork
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fb04895
chore(release): cut 106.5.0 [skip release]
dhis2-bot 751ec20
chore(deps-dev): bump @babel/core from 7.29.6 to 7.29.7 (#4616)
dependabot[bot] f000b0b
chore(deps-dev): bump @dhis2/cypress-plugins from 10.1.0 to 10.1.2 (#…
dependabot[bot] 7548d44
chore(deps-dev): bump dotenv from 16.6.1 to 17.4.2 (#4615)
dependabot[bot] 1458caa
chore(deps-dev): bump @babel/eslint-parser from 7.28.6 to 7.29.7 (#4613)
dependabot[bot] 2d787c6
feat: DHIS2-21266 - Integrate react Markdown lib
fernandogmz 1eb3de7
fix: fix code analysis report for parseFloat and isNaN
fernandogmz df378c9
chore: dedup wrap-ansi to fix the CI run
simonadomnisoru e9800d3
fix: [DHIS2-21266] Apply changes from PR feedback
fernandogmz 0176502
fix: [DHIS2-21266] Code format fix
fernandogmz 4347f20
Merge branch 'master' into DHIS2-21266-from-fork
simonadomnisoru 85c13eb
test: adapt markadown scenarios for versions bellow 43
simonadomnisoru 48bb641
fix: [DHIS2-21266] Update MarkdownWrapper & remove unused params
fernandogmz 5e03c6f
Merge branch 'master' into DHIS2-21266-from-fork
simonadomnisoru 295d2b1
chore: cleanup dead code
simonadomnisoru 61d7a68
fix: resolve Devin analysis comments
simonadomnisoru f2420e0
fix: resolve Devin analysis comments
simonadomnisoru af8d7b1
docs: add markdown support docs
simonadomnisoru 49ca87a
Merge branch 'master' into DHIS2-21266-from-fork
simonadomnisoru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,53 @@ | ||
| Feature: Feedback widget renders markdown content from program rules | ||
|
|
||
| Scenario: Feedback widget is visible on the enrollment dashboard | ||
| Given user lands on the enrollment edit event page by having typed #/enrollmentEventEdit?eventId=EKlWxFF9NPb | ||
| Then the feedback widget should be visible | ||
|
|
||
| Scenario: Feedback widget list contains 4 items | ||
| Given user lands on the enrollment edit event page by having typed #/enrollmentEventEdit?eventId=EKlWxFF9NPb | ||
| Then the list should contain 4 items | ||
|
|
||
| Scenario Outline: Headers feedback item renders markdown correctly | ||
| Given user lands on the enrollment edit event page by having typed #/enrollmentEventEdit?eventId=EKlWxFF9NPb | ||
| Then the <n> list item should contain p with text "Headers" | ||
| And the <n> list item should contain h1 with text "Header 1" | ||
| And the <n> list item should contain h2 with text "Header 2" | ||
| And the <n> list item should contain h3 with text "Header 3" | ||
| And the <n> list item should contain h4 with text "Header 4" | ||
| And the <n> list item should contain h5 with text "Header 5" | ||
| And the <n> list item should contain h6 with text "Header 6" | ||
|
|
||
| @v>=43 | ||
| Examples: | ||
| | n | | ||
| | first | | ||
|
|
||
| @v<43 | ||
| Examples: | ||
| | n | | ||
| | second | | ||
|
|
||
| Scenario Outline: Italic heading and table feedback item renders correctly | ||
| Given user lands on the enrollment edit event page by having typed #/enrollmentEventEdit?eventId=EKlWxFF9NPb | ||
| Then the <n> list item h6 should contain italic text "Feedback" | ||
| And the <n> list item table should match: | ||
| | Column A | Column B | | ||
| | Content A | Content B | | ||
|
|
||
| @v>=43 | ||
| Examples: | ||
| | n | | ||
| | second | | ||
|
|
||
| @v<43 | ||
| Examples: | ||
| | n | | ||
| | first | | ||
|
|
||
| @v>=43 | ||
| Scenario: Fourth feedback item renders score with color indicator correctly | ||
| Given user lands on the enrollment edit event page by having typed #/enrollmentEventEdit?eventId=EKlWxFF9NPb | ||
| Then the fourth list item left section should have h1 with text "1. Score 1" | ||
| And the fourth list item right section color indicator should be "rgb(57, 166, 45)" | ||
| And the fourth list item right section should have p with text "90%" |
This file contains hidden or 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,77 @@ | ||
| import {Given, Then, defineStep as And} from '@badeball/cypress-cucumber-preprocessor'; | ||
|
|
||
| const LONG_TIMEOUT = { timeout: 120000 }; | ||
|
|
||
| const getFeedbackDiv = () => | ||
| cy.get('[data-test="feedback-widget"]', LONG_TIMEOUT); | ||
|
|
||
| // SHARED | ||
|
|
||
| Given(/^user lands on the enrollment edit event page by having typed (.*)$/, (url) => { | ||
| cy.visit(url, LONG_TIMEOUT); | ||
| getFeedbackDiv().should('exist'); | ||
| }); | ||
|
|
||
| Then('the feedback widget should be visible', () => { | ||
| getFeedbackDiv().should('be.visible'); | ||
| }); | ||
|
|
||
| Then('the list should contain {int} items', (expectedCount) => { | ||
| getFeedbackDiv() | ||
| .find('[data-test="widget-contents"]', LONG_TIMEOUT) | ||
| .find('ul') | ||
| .find('li') | ||
| .should('have.length', expectedCount); | ||
| }); | ||
|
|
||
| const getListItem = (n) => | ||
| getFeedbackDiv() | ||
| .find('[data-test="widget-contents"]', LONG_TIMEOUT) | ||
| .find('ul li') | ||
| .eq(n - 1); | ||
|
|
||
| const ordinalToIndex = { first: 1, second: 2, third: 3, fourth: 4 }; | ||
|
|
||
| And('the {word} list item should contain {word} with text {string}', (ordinal, tag, text) => { | ||
| getListItem(ordinalToIndex[ordinal]) | ||
| .find(tag) | ||
| .should('have.text', text); | ||
| }); | ||
|
|
||
| Then('the {word} list item {word} should contain italic text {string}', (ordinal, tag, text) => { | ||
| getListItem(ordinalToIndex[ordinal]) | ||
| .find(tag) | ||
| .find('em') | ||
| .should('have.text', text); | ||
| }); | ||
|
|
||
| And('the {word} list item table should match:', (ordinal, dataTable) => { | ||
| const [headerRow, ...bodyRows] = dataTable.raw(); | ||
|
|
||
| getListItem(ordinalToIndex[ordinal]).find('table').within(() => { | ||
| cy.get('thead th').each(($th, i) => { | ||
| expect($th.text()).to.equal(headerRow[i]); | ||
| }); | ||
|
|
||
| cy.get('tbody tr').each(($tr, rowIndex) => { | ||
| bodyRows[rowIndex].forEach((cell, colIndex) => { | ||
| expect($tr.find('td').eq(colIndex).text()).to.equal(cell); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
| // FOURTH FEEDBACK ELEMENT | ||
|
|
||
| Then('the fourth list item left section should have {word} with text {string}', (tag, text) => { | ||
| getListItem(4).find('> div > div').first().find(tag).should('have.text', text); | ||
| }); | ||
|
|
||
| And('the fourth list item right section color indicator should be {string}', (color) => { | ||
| getListItem(4).find('> div > div').last().find('span').should('have.css', 'background-color', color); | ||
| }); | ||
|
|
||
| And('the fourth list item right section should have {word} with text {string}', (tag, text) => { | ||
| getListItem(4).find('> div > div').last().find(tag).should('have.text', text); | ||
| }); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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
169 changes: 169 additions & 0 deletions
169
...-core/components/WidgetFeedback/WidgetFeedbackContent/MarkdownWrapper/MarkdownWrapper.tsx
This file contains hidden or 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,169 @@ | ||
| import React, { ComponentType, memo } from 'react'; | ||
| import { spacersNum, colors } from '@dhis2/ui'; | ||
| import Markdown from 'react-markdown'; | ||
| import { withStyles, type WithStyles } from 'capture-core-utils/styles'; | ||
| import remarkGfm from 'remark-gfm'; | ||
| import { MarkdownWrapperProps } from './MarkdownWrapper.types'; | ||
|
|
||
|
|
||
| const styles = { | ||
| container: { | ||
| width: '100%', | ||
| margin: '8px 0px', | ||
| display: 'flex', | ||
| gap: '1rem', | ||
| }, | ||
| title: { | ||
| flex: '1 0 50%', | ||
| minWidth: '50%', | ||
| }, | ||
| content: { | ||
| flex: '0 1 auto', | ||
| maxWidth: '50%', | ||
| minWidth: '0', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: '8px', | ||
| }, | ||
| legend: { | ||
| height: '12px', | ||
| width: '12px', | ||
| minWidth: '12px', | ||
| borderRadius: '2px', | ||
| }, | ||
| markdown: { | ||
| fontSize: '14px', | ||
| lineHeight: 1.45, | ||
| color: colors.grey900, | ||
| '&:first-child': { | ||
| marginTop: 0, | ||
| }, | ||
| '& p': { | ||
| margin: `${spacersNum.dp8}px 0 0 0`, | ||
| display: 'inline-block', | ||
| }, | ||
| '& p:first-child': { | ||
| marginTop: 0, | ||
| }, | ||
| '& h1': { | ||
| fontSize: '18px', | ||
| fontWeight: 700, | ||
| lineHeight: 1.25, | ||
| margin: `${spacersNum.dp12}px 0 ${spacersNum.dp8}px 0`, | ||
| paddingBottom: spacersNum.dp4, | ||
| borderBottom: `2px solid ${colors.grey400}`, | ||
| color: colors.grey900, | ||
| }, | ||
| '& h2': { | ||
| fontSize: '16px', | ||
| fontWeight: 700, | ||
| margin: `${spacersNum.dp12}px 0 ${spacersNum.dp4}px 0`, | ||
| color: colors.grey900, | ||
| }, | ||
| '& h3': { | ||
| fontSize: '15px', | ||
| fontWeight: 600, | ||
| margin: `${spacersNum.dp8}px 0 ${spacersNum.dp4}px 0`, | ||
| color: colors.grey900, | ||
| }, | ||
| '& h4, & h5, & h6': { | ||
| fontSize: '14px', | ||
| fontWeight: 600, | ||
| margin: `${spacersNum.dp8}px 0 ${spacersNum.dp4}px 0`, | ||
| color: colors.grey900, | ||
| }, | ||
| '& strong': { | ||
| fontWeight: 700, | ||
| color: colors.grey900, | ||
| }, | ||
| '& em': { | ||
| fontStyle: 'italic', | ||
| color: colors.grey900, | ||
| }, | ||
| '& a': { | ||
| color: colors.blue800, | ||
| textDecoration: 'underline', | ||
| }, | ||
| '& ul, & ol': { | ||
| margin: `${spacersNum.dp8}px 0 0 0`, | ||
| paddingInlineStart: spacersNum.dp16, | ||
| }, | ||
| '& li': { | ||
| marginTop: spacersNum.dp4, | ||
| }, | ||
| '& code': { | ||
| fontFamily: 'Menlo, Monaco, Consolas, monospace', | ||
| fontSize: '12px', | ||
| background: colors.grey200, | ||
| padding: `1px ${spacersNum.dp4}px`, | ||
| borderRadius: '3px', | ||
| }, | ||
| '& pre': { | ||
| margin: `${spacersNum.dp8}px 0 0 0`, | ||
| padding: spacersNum.dp8, | ||
| background: colors.grey200, | ||
| borderRadius: '4px', | ||
| overflow: 'auto', | ||
| fontSize: '12px', | ||
| }, | ||
| '& pre code': { | ||
| background: 'transparent', | ||
| padding: 0, | ||
| }, | ||
| '& blockquote': { | ||
| margin: `${spacersNum.dp8}px 0 0 0`, | ||
| paddingInlineStart: spacersNum.dp12, | ||
| borderInlineStart: `4px solid ${colors.grey400}`, | ||
| color: colors.grey800, | ||
| fontStyle: 'italic', | ||
| }, | ||
| '& hr': { | ||
| margin: `${spacersNum.dp12}px 0`, | ||
| border: 'none', | ||
| borderTop: `1px solid ${colors.grey400}`, | ||
| }, | ||
| '& table': { | ||
| borderCollapse: 'collapse', | ||
| width: '100%', | ||
| margin: `${spacersNum.dp8}px 0`, | ||
| fontSize: '13px', | ||
| lineHeight: '18px', | ||
| }, | ||
| '& th, & td': { | ||
| padding: `${spacersNum.dp4}px ${spacersNum.dp8}px`, | ||
| border: `1px solid ${colors.grey300}`, | ||
| textAlign: 'left', | ||
| }, | ||
| '& th': { | ||
| fontWeight: 600, | ||
| color: colors.grey800, | ||
| whiteSpace: 'nowrap', | ||
| }, | ||
| '& td': { | ||
| color: colors.grey900, | ||
| }, | ||
| }, | ||
| }; | ||
| const REMARK_PLUGINS = [remarkGfm]; | ||
|
|
||
| type Props = MarkdownWrapperProps & WithStyles<typeof styles>; | ||
| const MarkdownWrapperComponent = memo(({ title, content, color, classes }:Props) => ( | ||
| <div className={classes.container} > | ||
| <div className={classes.title}> | ||
| <div className={classes.markdown}> | ||
| <Markdown remarkPlugins={REMARK_PLUGINS}>{title}</Markdown> | ||
| </div> | ||
| </div> | ||
|
|
||
| { content && | ||
| <div className={classes.content}> | ||
| { color && <span className={classes.legend} style={{ backgroundColor: color }} /> } | ||
| <div className={classes.markdown}> | ||
| <Markdown remarkPlugins={REMARK_PLUGINS}>{content}</Markdown> | ||
| </div> | ||
| </div> | ||
| } | ||
| </div> | ||
| )); | ||
|
|
||
| export const MarkdownWrapper = withStyles(styles)(MarkdownWrapperComponent) as ComponentType<MarkdownWrapperProps>; | ||
|
henrikmv marked this conversation as resolved.
|
||
5 changes: 5 additions & 0 deletions
5
.../components/WidgetFeedback/WidgetFeedbackContent/MarkdownWrapper/MarkdownWrapper.types.ts
This file contains hidden or 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,5 @@ | ||
| export type MarkdownWrapperProps = { | ||
| title: string; | ||
| content?: string; | ||
| color?: string; | ||
| } |
1 change: 1 addition & 0 deletions
1
...les/capture-core/components/WidgetFeedback/WidgetFeedbackContent/MarkdownWrapper/index.ts
This file contains hidden or 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 @@ | ||
| export { MarkdownWrapper } from './MarkdownWrapper'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.