Skip to content

Commit

Permalink
fix: show warning text below RichTextEditor when unable to show snaps…
Browse files Browse the repository at this point in the history
…hot (DHIS2-15781)
  • Loading branch information
HendrikThePendric committed Oct 16, 2023
1 parent 8e60f26 commit f27bc38
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
7 changes: 5 additions & 2 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: 2023-07-06T08:30:33.216Z\n"
"PO-Revision-Date: 2023-07-06T08:30:33.216Z\n"
"POT-Creation-Date: 2023-09-27T14:15:13.876Z\n"
"PO-Revision-Date: 2023-09-27T14:15:13.876Z\n"

msgid "view only"
msgstr "view only"
Expand Down Expand Up @@ -374,6 +374,9 @@ msgstr "Hide interpretation"
msgid "Write an interpretation"
msgstr "Write an interpretation"

msgid "Other people viewing this interpretation in the future may see more data."
msgstr "Other people viewing this interpretation in the future may see more data."

msgid "Post interpretation"
msgstr "Post interpretation"

Expand Down
51 changes: 51 additions & 0 deletions src/__demo__/InterpretationsUnit.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { CustomDataProvider } from '@dhis2/app-runtime'
import { storiesOf } from '@storybook/react'
import React from 'react'
import { InterpretationsUnit } from '../components/Interpretations/InterpretationsUnit/index.js'

storiesOf('IntepretationsUnit', module).add('Default', () => {
return (
<CustomDataProvider
data={{
interpretations: {
interpretations: [],
},
}}
>
<InterpretationsUnit
currentUser={{
name: 'Tom Wakiki',
}}
id="abcd"
onReplyIconClick={Function.prototype}
type="eventVisualization"
visualizationHasTimeDimension={true}
/>
</CustomDataProvider>
)
})

storiesOf('IntepretationsUnit', module).add(
'With no time dimensions warning',
() => {
return (
<CustomDataProvider
data={{
interpretations: {
interpretations: [],
},
}}
>
<InterpretationsUnit
currentUser={{
name: 'Tom Wakiki',
}}
id="abcd"
onReplyIconClick={Function.prototype}
type="eventVisualization"
visualizationHasTimeDimension={false}
/>
</CustomDataProvider>
)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const InterpretationForm = ({
id,
currentUser,
disabled,
showNoTimeDimensionHelpText,
onSave,
}) => {
const [showRichTextEditor, setShowRichTextEditor] = useState(false)
Expand Down Expand Up @@ -51,6 +52,13 @@ export const InterpretationForm = ({
inputPlaceholder={inputPlaceholder}
onChange={setInterpretationText}
value={interpretationText}
helpText={
showNoTimeDimensionHelpText
? i18n.t(
'Other people viewing this interpretation in the future may see more data.'
)
: undefined
}
/>
<MessageButtonStrip>
<Button
Expand Down Expand Up @@ -89,6 +97,7 @@ InterpretationForm.propTypes = {
currentUser: PropTypes.object,
disabled: PropTypes.bool,
id: PropTypes.string,
showNoTimeDimensionHelpText: PropTypes.bool,
type: PropTypes.string,
onSave: PropTypes.func,
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const InterpretationsUnit = forwardRef(
currentUser,
type,
id,
visualizationHasTimeDimension,
onInterpretationClick,
onReplyIconClick,
disabled,
Expand All @@ -52,6 +53,8 @@ export const InterpretationsUnit = forwardRef(
ref
) => {
const [isExpanded, setIsExpanded] = useState(true)
const showNoTimeDimensionHelpText =
type === 'eventVisualization' && !visualizationHasTimeDimension

const { data, loading, fetching, refetch } = useDataQuery(
interpretationsQuery,
Expand Down Expand Up @@ -115,6 +118,9 @@ export const InterpretationsUnit = forwardRef(
id={id}
onSave={onCompleteAction}
disabled={disabled}
showNoTimeDimensionHelpText={
showNoTimeDimensionHelpText
}
/>
<InterpretationList
currentUser={currentUser}
Expand Down Expand Up @@ -181,6 +187,7 @@ InterpretationsUnit.displayName = 'InterpretationsUnit'

InterpretationsUnit.defaultProps = {
onInterpretationClick: Function.prototype,
visualizationHasTimeDimension: true,
}

InterpretationsUnit.propTypes = {
Expand All @@ -189,6 +196,7 @@ InterpretationsUnit.propTypes = {
type: PropTypes.string.isRequired,
disabled: PropTypes.bool,
renderId: PropTypes.number,
visualizationHasTimeDimension: PropTypes.bool,
onInterpretationClick: PropTypes.func,
onReplyIconClick: PropTypes.func,
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Toolbar.propTypes = {

export const RichTextEditor = forwardRef(
(
{ value, disabled, inputPlaceholder, onChange, errorText },
{ value, disabled, inputPlaceholder, onChange, errorText, helpText },
externalRef
) => {
const [previewMode, setPreviewMode] = useState(false)
Expand Down Expand Up @@ -234,7 +234,11 @@ export const RichTextEditor = forwardRef(
<RichTextParser>{value}</RichTextParser>
</div>
) : (
<Field error={!!errorText} validationText={errorText}>
<Field
error={!!errorText}
validationText={errorText}
helpText={helpText}
>
<UserMentionWrapper
onUserSelect={onChange}
inputReference={textareaRef}
Expand Down Expand Up @@ -268,5 +272,6 @@ RichTextEditor.propTypes = {
onChange: PropTypes.func.isRequired,
disabled: PropTypes.bool,
errorText: PropTypes.string,
helpText: PropTypes.string,
inputPlaceholder: PropTypes.string,
}

0 comments on commit f27bc38

Please sign in to comment.