Skip to content

Commit

Permalink
feat: improve copy/past text [DHIS2-15012]
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Mar 28, 2023
1 parent e05a2a7 commit 52282e4
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 34 deletions.
53 changes: 48 additions & 5 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2022-11-02T09:25:00.426Z\n"
"PO-Revision-Date: 2022-11-02T09:25:00.426Z\n"
"POT-Creation-Date: 2023-03-24T13:11:23.515Z\n"
"PO-Revision-Date: 2023-03-24T13:11:23.515Z\n"

msgid "Aggregate data exchange information is not accessible"
msgstr "Aggregate data exchange information is not accessible"
Expand Down Expand Up @@ -79,6 +79,15 @@ msgstr "Exchange content not accessible"
msgid "Click to refresh"
msgstr "Click to refresh"

msgid "Conflicts"
msgstr "Conflicts"

msgid "Object"
msgstr "Object"

msgid "Value"
msgstr "Value"

msgid "Submitting..."
msgstr "Submitting..."

Expand Down Expand Up @@ -138,6 +147,43 @@ msgstr "Are you sure you want to submit this data?"
msgid "Submitting data"
msgstr "Submitting data"

msgid "imported"
msgstr "imported"

msgid "updated"
msgstr "updated"

msgid "ignored"
msgstr "ignored"

msgid "Exchange: {{- exchangeName}}"
msgstr "Exchange: {{- exchangeName}}"

msgid "Target URL: {{- exchangeURL}}"
msgstr "Target URL: {{- exchangeURL}}"

msgid "Run date: {{- runDate}}"
msgstr "Run date: {{- runDate}}"

msgid "SUMMARY"
msgstr "SUMMARY"

msgid ""
"Imported: {{importedCount}}, Updated: {{updatedCount}}, Ignored: "
"{{ignoredCount}}"
msgstr ""
"Imported: {{importedCount}}, Updated: {{updatedCount}}, Ignored: "
"{{ignoredCount}}"

msgid "DETAILS"
msgstr "DETAILS"

msgid "Report: {{- requestName}}"
msgstr "Report: {{- requestName}}"

msgid "Report"
msgstr "Report"

msgid "Imported"
msgstr "Imported"

Expand All @@ -147,9 +193,6 @@ msgstr "Updated"
msgid "Ignored"
msgstr "Ignored"

msgid "Report"
msgstr "Report"

msgid "Copy summary to clipboard"
msgstr "Copy summary to clipboard"

Expand Down
49 changes: 48 additions & 1 deletion i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ msgid "Ignored"
msgstr "Ignorés"

msgid "Copy summary to clipboard"
msgstr "Copier l'information sommaire vers lcde presse-papier"
msgstr "Copier l'information sommaire vers le presse-papier"

msgid "Data submitted successfully."
msgstr "Les données ont été envoyées avec succès."
Expand All @@ -148,3 +148,50 @@ msgstr "Échange de données"

msgid "Choose a data exchange"
msgstr "Choisir un échange de données"

msgid "Exchange: {{- exchangeName}}"
msgstr "Echange: {{- exchangeName}}"

msgid "Target URL: {{- exchangeURL}}"
msgstr "URL destination: {{- exchangeURL}}"

msgid "Run date: {{- runDate}}"
msgstr "Date d'éxécution: {{- runDate}}"

msgid "SUMMARY"
msgstr "SOMMAIRE"

msgid ""
"Imported: {{importedCount}}, Updated: {{updatedCount}}, Ignored: "
"{{ignoredCount}}"
msgstr ""
"Importés: {{importedCount}}, Mis-à-jour: {{updatedCount}}, Ignorés: "
"{{ignoredCount}}"

msgid "DETAILS"
msgstr "DETAILS"

msgid "Report: {{- requestName}}"
msgstr "Rapport: {{- requestName}}"

msgid "Conflicts"
msgstr "Conflits"

msgid "imported"
msgstr "importés"

msgid "updated"
msgstr "mis-à-jour"

msgid "ignored"
msgstr "ignorés"

msgid "Report"
msgstr "Rapport"


msgid "Object"
msgstr "Objet"

msgid "Value"
msgstr "Valeur"
2 changes: 1 addition & 1 deletion src/bottom-bar/bottom-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const BottomBar = ({ openSubmitModal, dataSubmitted }) => {
}

BottomBar.propTypes = {
dataSubmitted: PropTypes.bool,
dataSubmitted: PropTypes.string,
openSubmitModal: PropTypes.func,
}
export { BottomBar }
13 changes: 10 additions & 3 deletions src/submit-modal/submit-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ ErrorModalContent.propTypes = {
onRetry: PropTypes.func,
}

const SuccessModalContent = ({ onClose, data }) => (
const SuccessModalContent = ({ onClose, data, dataSubmitted }) => (
<>
<ModalContent>
<ModalContentWrapper>
<SuccessContent data={data} />
<SuccessContent data={data} dataSubmitted={dataSubmitted} />
</ModalContentWrapper>
</ModalContent>

Expand All @@ -97,6 +97,7 @@ const SuccessModalContent = ({ onClose, data }) => (

SuccessModalContent.propTypes = {
data: PropTypes.object,
dataSubmitted: PropTypes.string,
onClose: PropTypes.func,
}

Expand Down Expand Up @@ -295,7 +296,13 @@ const SubmitModal = ({ open, onClose, setDataSubmitted }) => {
onClose={onClose}
/>
)}
{data && <SuccessModalContent data={data} onClose={onClose} />}
{data && (
<SuccessModalContent
data={data}
dataSubmitted={dataSubmitted}
onClose={onClose}
/>
)}
{loading && <LoadingStateModalContent />}
</Modal>
)
Expand Down
118 changes: 96 additions & 22 deletions src/submit-modal/success-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import styles from './success-content.module.css'
const importTypeConfig = {
imported: {
style: 'success',
text: i18n.t('Imported'),
text: i18n.t('imported'),
},
updated: {
style: 'success',
text: i18n.t('Updated'),
text: i18n.t('updated'),
},
ignored: {
style: 'ignored',
text: i18n.t('Ignored'),
text: i18n.t('ignored'),
},
}

Expand All @@ -42,7 +42,7 @@ const SummaryBox = ({ importType, importCount }) => {
<div className={boxStyle}>
<div className={styles.count}>{importCount}</div>
<div className={styles.label}>
<span>{text.toLowerCase()}</span>
<span>{i18n.t(text)}</span>
</div>
</div>
</div>
Expand All @@ -53,34 +53,94 @@ SummaryBox.propTypes = {
importType: PropTypes.string,
}

const copyTableToClipboard = ({ importSummaries, requests }) => {
const headerRowText = [
i18n.t('Report'),
i18n.t('Imported'),
i18n.t('Updated'),
i18n.t('Ignored'),
].join()
const clipboardText = importSummaries.reduce(
const getConflictLines = (conflicts) => {
if (!conflicts) {
return ''
}
return conflicts
.map((conflict) => `${conflict.object}: ${conflict.value}`)
.join('\n')
}

const copyTableToClipboard = ({
exchangeName,
exchangeURL,
importSummaries,
summaryCounts,
requests,
dataSubmitted,
}) => {
let text = ''
const exchangeNameLine = i18n.t('Exchange: {{- exchangeName}}', {
exchangeName,
nsSeparator: '-:-',
})
const targetURLLine = i18n.t('Target URL: {{- exchangeURL}}', {
exchangeURL: decodeURI(exchangeURL),
nsSeparator: '-:-',
})
const runDateLine = i18n.t('Run date: {{- runDate}}', {
runDate: dataSubmitted,
nsSeparator: '-:-',
})

if (exchangeURL) {
text += `${exchangeNameLine}\n${targetURLLine}`
} else {
text += exchangeNameLine
}
text += '\n' + runDateLine + '\n\n\n' + i18n.t('SUMMARY') + '\n'

const summaryLine = i18n.t(
'Imported: {{importedCount}}, Updated: {{updatedCount}}, Ignored: {{ignoredCount}}',
{
importedCount: summaryCounts.imported,
updatedCount: summaryCounts.updated,
ignoredCount: summaryCounts.ignored,
nsSeparator: '-:-',
}
)
text += summaryLine + '\n\n\n' + i18n.t('DETAILS')

const detailsText = importSummaries.reduce(
(fullText, importSummary, index) => {
let requestName = requests?.[index]?.name ?? ''
if (requests?.[index]?.name?.includes(',')) {
requestName = `"${requests?.[index]?.name}"`
}
const requestNameLine = i18n.t('Report: {{- requestName}}', {
requestName,
nsSeparator: '-:-',
})
const importedCount = importSummary.importCount?.imported
const ignoredCount = importSummary.importCount?.ignored
const updatedCount = importSummary.importCount?.updated
const summaryCountLine = i18n.t(
'Imported: {{importedCount}}, Updated: {{updatedCount}}, Ignored: {{ignoredCount}}',
{
importedCount,
updatedCount,
ignoredCount,
nsSeparator: '-:-',
}
)
const conflictLines = getConflictLines(importSummary.conflicts)
return (
fullText +
'\n\n' +
requestNameLine +
'\n' +
[
requestName,
importSummary.importCount?.imported,
importSummary.importCount?.updated,
importSummary.importCount?.ignored,
].join()
summaryCountLine +
'\n' +
conflictLines
)
},
headerRowText
''
)

navigator.clipboard.writeText(clipboardText)
text += detailsText

navigator.clipboard.writeText(text)
}

const SummaryRow = ({
Expand Down Expand Up @@ -124,7 +184,12 @@ SummaryRow.propTypes = {
importSummary: PropTypes.object,
}

const SummaryTable = ({ importSummaries, hasConflicts }) => {
const SummaryTable = ({
importSummaries,
summaryCounts,
hasConflicts,
dataSubmitted,
}) => {
const { exchange } = useExchangeContext()
const [expandedRows, setExpandedRows] = useState([])

Expand Down Expand Up @@ -177,8 +242,12 @@ const SummaryTable = ({ importSummaries, hasConflicts }) => {
icon={<IconCopy16 />}
onClick={() => {
copyTableToClipboard({
exchangeName: exchange.displayName,
exchangeURL: exchange.target?.api?.url,
importSummaries,
summaryCounts,
requests: exchange?.source?.requests,
dataSubmitted,
})
}}
>
Expand All @@ -190,11 +259,13 @@ const SummaryTable = ({ importSummaries, hasConflicts }) => {
}

SummaryTable.propTypes = {
dataSubmitted: PropTypes.string,
hasConflicts: PropTypes.bool,
importSummaries: PropTypes.array,
summaryCounts: PropTypes.object,
}

const SuccessContent = ({ data }) => {
const SuccessContent = ({ data, dataSubmitted }) => {
const { importSummaries } = data

const summaryCounts = importSummaries.reduce(
Expand Down Expand Up @@ -240,14 +311,17 @@ const SuccessContent = ({ data }) => {
</div>
<SummaryTable
importSummaries={importSummaries}
summaryCounts={summaryCounts}
hasConflicts={summaryCounts.conflicts > 0}
dataSubmitted={dataSubmitted}
/>
</>
)
}

SuccessContent.propTypes = {
data: PropTypes.object,
dataSubmitted: PropTypes.submitted,
}

export { SuccessContent }
Loading

0 comments on commit 52282e4

Please sign in to comment.