Skip to content

Commit 405384c

Browse files
committed
docs: interpretations storybook examples
1 parent 3598c51 commit 405384c

4 files changed

Lines changed: 1088 additions & 41 deletions

File tree

.storybook/preview.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { CssReset } from '@dhis2/ui'
1+
import { CssReset, CssVariables } from '@dhis2/ui'
22
import React from 'react'
33

44
export const decorators = [
55
(Story) => (
66
<div>
77
<CssReset />
8+
<CssVariables spacers colors layers elevations theme />
89
<Story />
910
<style jsx>{`
1011
:global(html) {
Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
import { CustomDataProvider } from '@dhis2/app-runtime'
2+
import i18n from '@dhis2/d2-i18n'
3+
import { colors, spacers, DropdownButton } from '@dhis2/ui'
4+
import PropTypes from 'prop-types'
5+
import React from 'react'
6+
import { InterpretationModal } from '../components/Interpretations/InterpretationModal/InterpretationModal.js'
7+
import { InterpretationsProvider } from '../components/Interpretations/InterpretationsProvider/InterpretationsProvider.js'
8+
9+
export default {
10+
title: 'InterpretationModal',
11+
}
12+
13+
const currentUser = {
14+
id: 'user001',
15+
name: 'Tom Wakiki',
16+
authorities: [],
17+
settings: {
18+
keyAnalysisDisplayProperty: 'name',
19+
},
20+
}
21+
22+
const makeInterpretation = (overrides) => ({
23+
id: 'interp-1',
24+
text: 'Interpretation text',
25+
created: '2026-04-10T14:22:00.000',
26+
likes: 0,
27+
createdBy: {
28+
id: 'user002',
29+
displayName: 'Amina Diallo',
30+
},
31+
comments: [],
32+
likedBy: [],
33+
access: { write: true, manage: false },
34+
...overrides,
35+
})
36+
37+
const PlaceholderVisualization = () => (
38+
<div
39+
style={{
40+
width: '100%',
41+
height: '100%',
42+
minHeight: 300,
43+
display: 'flex',
44+
alignItems: 'center',
45+
justifyContent: 'center',
46+
backgroundColor: colors.grey100,
47+
border: `1px dashed ${colors.grey400}`,
48+
borderRadius: 4,
49+
color: colors.grey700,
50+
fontSize: 14,
51+
padding: spacers.dp16,
52+
}}
53+
>
54+
Visualization placeholder
55+
</div>
56+
)
57+
58+
const ModalDownloadDropdown = () => (
59+
<div style={{ marginTop: spacers.dp12, marginBottom: spacers.dp16 }}>
60+
<DropdownButton
61+
component={<div />}
62+
disabled
63+
open={false}
64+
secondary
65+
small
66+
>
67+
{i18n.t('Download data from this date')}
68+
</DropdownButton>
69+
</div>
70+
)
71+
72+
const ModalStory = ({ interpretation, interpretationsResolver, children }) => (
73+
<CustomDataProvider
74+
data={{
75+
interpretations:
76+
interpretationsResolver ??
77+
((_type, query) => {
78+
if (query.id) {
79+
return interpretation
80+
}
81+
return { interpretations: [interpretation] }
82+
}),
83+
}}
84+
>
85+
<InterpretationsProvider currentUser={currentUser}>
86+
{children}
87+
</InterpretationsProvider>
88+
</CustomDataProvider>
89+
)
90+
91+
ModalStory.propTypes = {
92+
children: PropTypes.node,
93+
interpretation: PropTypes.object,
94+
interpretationsResolver: PropTypes.func,
95+
}
96+
97+
export const NoComments = () => {
98+
const interpretation = makeInterpretation({
99+
text: 'The ANC coverage rate has improved steadily across all districts this quarter, with the Eastern region showing the most significant gains.',
100+
likes: 2,
101+
likedBy: [{ id: 'user001' }, { id: 'user003' }],
102+
})
103+
104+
return (
105+
<ModalStory interpretation={interpretation}>
106+
<InterpretationModal
107+
interpretationId="interp-1"
108+
isVisualizationLoading={false}
109+
visualization={{
110+
id: 'viz-1',
111+
displayName: 'ANC Coverage by District - Q1 2026',
112+
}}
113+
pluginComponent={PlaceholderVisualization}
114+
downloadMenuComponent={ModalDownloadDropdown}
115+
onClose={Function.prototype}
116+
onResponsesReceived={Function.prototype}
117+
/>
118+
</ModalStory>
119+
)
120+
}
121+
122+
NoComments.story = {
123+
name: 'No comments',
124+
}
125+
126+
export const WithAFewComments = () => {
127+
const interpretation = makeInterpretation({
128+
text: 'Immunization coverage for Penta 3 dropped below 80% in three districts last month. This needs urgent attention before the next reporting cycle.',
129+
likes: 5,
130+
likedBy: [
131+
{ id: 'user001' },
132+
{ id: 'user003' },
133+
{ id: 'user004' },
134+
{ id: 'user005' },
135+
{ id: 'user006' },
136+
],
137+
comments: [
138+
{
139+
id: 'c1',
140+
text: 'I checked the district-level data and it looks like the drop is concentrated in two facilities that had staff turnover last month.',
141+
created: '2026-04-11T09:15:00.000',
142+
createdBy: {
143+
id: 'user003',
144+
displayName: 'James Okonkwo',
145+
},
146+
},
147+
{
148+
id: 'c2',
149+
text: 'We should flag this for the regional review meeting next week.',
150+
created: '2026-04-11T11:42:00.000',
151+
createdBy: {
152+
id: 'user004',
153+
displayName: 'Dr. Fatou Mensah',
154+
},
155+
},
156+
{
157+
id: 'c3',
158+
text: 'Agreed. I will prepare a summary of the affected facilities and share it before the meeting.',
159+
created: '2026-04-12T08:05:00.000',
160+
createdBy: {
161+
id: 'user001',
162+
displayName: 'Tom Wakiki',
163+
},
164+
},
165+
],
166+
})
167+
168+
return (
169+
<ModalStory interpretation={interpretation}>
170+
<InterpretationModal
171+
interpretationId="interp-1"
172+
isVisualizationLoading={false}
173+
visualization={{
174+
id: 'viz-2',
175+
displayName:
176+
'Penta 3 Immunization Coverage by District Sorted by Participation Rates and Coverage Beyond District Funding Levels - March 2026',
177+
}}
178+
pluginComponent={PlaceholderVisualization}
179+
// downloadMenuComponent={ModalDownloadDropdown}
180+
onClose={Function.prototype}
181+
onResponsesReceived={Function.prototype}
182+
/>
183+
</ModalStory>
184+
)
185+
}
186+
187+
WithAFewComments.story = {
188+
name: 'With a few comments',
189+
}
190+
191+
export const WithManyComments = () => {
192+
const interpretation = makeInterpretation({
193+
text: 'Disease surveillance data shows an unusual cluster of acute watery diarrhoea cases in the Ashanti region. The pattern warrants investigation by the rapid response team.',
194+
likes: 10,
195+
likedBy: [
196+
{ id: 'user001' },
197+
{ id: 'user002' },
198+
{ id: 'user003' },
199+
{ id: 'user004' },
200+
{ id: 'user005' },
201+
{ id: 'user006' },
202+
{ id: 'user007' },
203+
{ id: 'user008' },
204+
{ id: 'user009' },
205+
{ id: 'user010' },
206+
],
207+
comments: [
208+
{
209+
id: 'c1',
210+
text: 'I noticed this trend last week. The cluster seems to be centred around the Kumasi metropolitan area.',
211+
created: '2026-04-10T15:30:00.000',
212+
createdBy: {
213+
id: 'user003',
214+
displayName: 'James Okonkwo',
215+
},
216+
},
217+
{
218+
id: 'c2',
219+
text: 'Could this be linked to the water supply disruption reported two weeks ago? The timing fits.',
220+
created: '2026-04-10T16:12:00.000',
221+
createdBy: {
222+
id: 'user004',
223+
displayName: 'Dr. Fatou Mensah',
224+
},
225+
},
226+
{
227+
id: 'c3',
228+
text: 'Good point. I have pulled the WASH indicators for those communities and there is a clear correlation with facilities reporting low water quality scores.',
229+
created: '2026-04-11T08:45:00.000',
230+
createdBy: {
231+
id: 'user005',
232+
displayName: 'Kwame Asante',
233+
},
234+
},
235+
{
236+
id: 'c4',
237+
text: 'The rapid response team has been notified. They are planning field visits for Thursday and Friday this week.',
238+
created: '2026-04-11T10:20:00.000',
239+
createdBy: {
240+
id: 'user006',
241+
displayName: 'Grace Nkrumah',
242+
},
243+
},
244+
{
245+
id: 'c5',
246+
text: 'We should also check neighbouring districts for any spillover. Brong-Ahafo and Eastern regions share water sources with some of the affected communities.',
247+
created: '2026-04-11T14:00:00.000',
248+
createdBy: {
249+
id: 'user001',
250+
displayName: 'Tom Wakiki',
251+
},
252+
},
253+
{
254+
id: 'c6',
255+
text: 'Preliminary lab results from Komfo Anokye confirm Vibrio cholerae in 3 of the 8 samples. This needs to be escalated immediately.',
256+
created: '2026-04-12T07:30:00.000',
257+
createdBy: {
258+
id: 'user004',
259+
displayName: 'Dr. Fatou Mensah',
260+
},
261+
},
262+
{
263+
id: 'c7',
264+
text: 'I have updated the weekly epidemiological bulletin to include this cluster. The national surveillance team has been copied.',
265+
created: '2026-04-12T09:55:00.000',
266+
createdBy: {
267+
id: 'user007',
268+
displayName: 'Samuel Owusu',
269+
},
270+
},
271+
{
272+
id: 'c8',
273+
text: 'Stock levels of ORS and IV fluids at the affected facilities look adequate for now, but we should monitor daily given the trajectory.',
274+
created: '2026-04-12T13:10:00.000',
275+
createdBy: {
276+
id: 'user005',
277+
displayName: 'Kwame Asante',
278+
},
279+
},
280+
],
281+
})
282+
283+
return (
284+
<ModalStory interpretation={interpretation}>
285+
<InterpretationModal
286+
interpretationId="interp-1"
287+
isVisualizationLoading={false}
288+
visualization={{
289+
id: 'viz-3',
290+
displayName:
291+
'Acute Watery Diarrhoea Cases - Ashanti Region Weekly Surveillance',
292+
}}
293+
pluginComponent={PlaceholderVisualization}
294+
downloadMenuComponent={ModalDownloadDropdown}
295+
onClose={Function.prototype}
296+
onResponsesReceived={Function.prototype}
297+
/>
298+
</ModalStory>
299+
)
300+
}
301+
302+
WithManyComments.story = {
303+
name: 'With many comments',
304+
}
305+
306+
export const Error = () => (
307+
<ModalStory
308+
interpretationsResolver={() =>
309+
Promise.reject(
310+
new Error(
311+
'Network request failed while loading the interpretation'
312+
)
313+
)
314+
}
315+
>
316+
<InterpretationModal
317+
interpretationId="interp-1"
318+
isVisualizationLoading={false}
319+
visualization={{
320+
id: 'viz-error',
321+
displayName: 'Errored visualization',
322+
}}
323+
pluginComponent={PlaceholderVisualization}
324+
downloadMenuComponent={ModalDownloadDropdown}
325+
onClose={Function.prototype}
326+
onResponsesReceived={Function.prototype}
327+
/>
328+
</ModalStory>
329+
)
330+
331+
Error.story = {
332+
name: 'Error',
333+
}

0 commit comments

Comments
 (0)