@dhis2/analytics 23.10.4 → 23.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/build/cjs/components/Interpretations/InterpretationModal/Comment.js +64 -0
  3. package/build/cjs/components/Interpretations/InterpretationModal/CommentAddForm.js +93 -0
  4. package/build/cjs/components/Interpretations/InterpretationModal/CommentDeleteButton.js +62 -0
  5. package/build/cjs/components/Interpretations/InterpretationModal/CommentUpdateForm.js +95 -0
  6. package/build/cjs/components/Interpretations/InterpretationModal/InterpretationModal.js +187 -0
  7. package/build/cjs/components/Interpretations/InterpretationModal/InterpretationThread.js +100 -0
  8. package/build/cjs/components/Interpretations/InterpretationModal/index.js +13 -0
  9. package/build/cjs/components/Interpretations/InterpretationModal/useModalContentWidth.js +39 -0
  10. package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationForm.js +94 -0
  11. package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationList.js +94 -0
  12. package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +135 -0
  13. package/build/cjs/components/Interpretations/InterpretationsUnit/index.js +13 -0
  14. package/build/cjs/components/Interpretations/common/Interpretation/Interpretation.js +110 -0
  15. package/build/cjs/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js +58 -0
  16. package/build/cjs/components/Interpretations/common/Interpretation/InterpretationSharingLink.js +50 -0
  17. package/build/cjs/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js +108 -0
  18. package/build/cjs/components/Interpretations/common/Interpretation/index.js +21 -0
  19. package/build/cjs/components/Interpretations/common/Interpretation/useLike.js +53 -0
  20. package/build/cjs/components/Interpretations/common/Message/Message.js +55 -0
  21. package/build/cjs/components/Interpretations/common/Message/MessageButtonStrip.js +33 -0
  22. package/build/cjs/components/Interpretations/common/Message/MessageEditorContainer.js +42 -0
  23. package/build/cjs/components/Interpretations/common/Message/MessageIconButton.js +67 -0
  24. package/build/cjs/components/Interpretations/common/Message/MessageInput.js +31 -0
  25. package/build/cjs/components/Interpretations/common/Message/MessageStatsBar.js +33 -0
  26. package/build/cjs/components/Interpretations/common/Message/index.js +53 -0
  27. package/build/cjs/components/Interpretations/common/RichTextEditor/RichTextEditor.js +262 -0
  28. package/build/cjs/components/Interpretations/common/RichTextEditor/index.js +13 -0
  29. package/build/cjs/components/Interpretations/common/RichTextEditor/markdownHandler.js +148 -0
  30. package/build/cjs/components/Interpretations/common/RichTextEditor/styles/RichTextEditor.style.js +21 -0
  31. package/build/cjs/components/Interpretations/common/UserMention/UserList.js +48 -0
  32. package/build/cjs/components/Interpretations/common/UserMention/UserMentionWrapper.js +226 -0
  33. package/build/cjs/components/Interpretations/common/UserMention/styles/UserMentionWrapper.style.js +30 -0
  34. package/build/cjs/components/Interpretations/common/UserMention/useUserSearchResults.js +78 -0
  35. package/build/cjs/components/Interpretations/common/index.js +44 -0
  36. package/build/cjs/components/LegendKey/styles/LegendKey.style.js +2 -2
  37. package/build/cjs/index.js +22 -0
  38. package/build/cjs/locales/en/translations.json +32 -1
  39. package/build/cjs/locales/ro/translations.json +6 -6
  40. package/build/cjs/modules/legends.js +6 -2
  41. package/build/es/components/Interpretations/InterpretationModal/Comment.js +45 -0
  42. package/build/es/components/Interpretations/InterpretationModal/CommentAddForm.js +70 -0
  43. package/build/es/components/Interpretations/InterpretationModal/CommentDeleteButton.js +47 -0
  44. package/build/es/components/Interpretations/InterpretationModal/CommentUpdateForm.js +73 -0
  45. package/build/es/components/Interpretations/InterpretationModal/InterpretationModal.js +165 -0
  46. package/build/es/components/Interpretations/InterpretationModal/InterpretationThread.js +79 -0
  47. package/build/es/components/Interpretations/InterpretationModal/index.js +1 -0
  48. package/build/es/components/Interpretations/InterpretationModal/useModalContentWidth.js +28 -0
  49. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationForm.js +71 -0
  50. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationList.js +78 -0
  51. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +112 -0
  52. package/build/es/components/Interpretations/InterpretationsUnit/index.js +1 -0
  53. package/build/es/components/Interpretations/common/Interpretation/Interpretation.js +87 -0
  54. package/build/es/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js +43 -0
  55. package/build/es/components/Interpretations/common/Interpretation/InterpretationSharingLink.js +33 -0
  56. package/build/es/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js +85 -0
  57. package/build/es/components/Interpretations/common/Interpretation/index.js +2 -0
  58. package/build/es/components/Interpretations/common/Interpretation/useLike.js +45 -0
  59. package/build/es/components/Interpretations/common/Message/Message.js +41 -0
  60. package/build/es/components/Interpretations/common/Message/MessageButtonStrip.js +21 -0
  61. package/build/es/components/Interpretations/common/Message/MessageEditorContainer.js +30 -0
  62. package/build/es/components/Interpretations/common/Message/MessageIconButton.js +54 -0
  63. package/build/es/components/Interpretations/common/Message/MessageInput.js +16 -0
  64. package/build/es/components/Interpretations/common/Message/MessageStatsBar.js +21 -0
  65. package/build/es/components/Interpretations/common/Message/index.js +6 -0
  66. package/build/es/components/Interpretations/common/RichTextEditor/RichTextEditor.js +240 -0
  67. package/build/es/components/Interpretations/common/RichTextEditor/index.js +1 -0
  68. package/build/es/components/Interpretations/common/RichTextEditor/markdownHandler.js +128 -0
  69. package/build/es/components/Interpretations/common/RichTextEditor/styles/RichTextEditor.style.js +9 -0
  70. package/build/es/components/Interpretations/common/UserMention/UserList.js +33 -0
  71. package/build/es/components/Interpretations/common/UserMention/UserMentionWrapper.js +202 -0
  72. package/build/es/components/Interpretations/common/UserMention/styles/UserMentionWrapper.style.js +17 -0
  73. package/build/es/components/Interpretations/common/UserMention/useUserSearchResults.js +63 -0
  74. package/build/es/components/Interpretations/common/index.js +3 -0
  75. package/build/es/components/LegendKey/styles/LegendKey.style.js +2 -2
  76. package/build/es/index.js +3 -1
  77. package/build/es/locales/en/translations.json +32 -1
  78. package/build/es/locales/ro/translations.json +6 -6
  79. package/build/es/modules/legends.js +6 -2
  80. package/package.json +3 -2
@@ -0,0 +1,47 @@
1
+ import { useDataMutation } from '@dhis2/app-runtime';
2
+ import i18n from '@dhis2/d2-i18n';
3
+ import { IconDelete16 } from '@dhis2/ui';
4
+ import PropTypes from 'prop-types';
5
+ import React from 'react';
6
+ import { MessageIconButton } from '../common/index.js';
7
+ const mutation = {
8
+ resource: 'interpretations',
9
+ id: _ref => {
10
+ let {
11
+ interpretationId,
12
+ commentId
13
+ } = _ref;
14
+ return "".concat(interpretationId, "/comments/").concat(commentId);
15
+ },
16
+ type: 'delete'
17
+ };
18
+
19
+ const CommentDeleteButton = _ref2 => {
20
+ let {
21
+ commentId,
22
+ interpretationId,
23
+ onComplete
24
+ } = _ref2;
25
+ const [remove, {
26
+ loading
27
+ }] = useDataMutation(mutation, {
28
+ onComplete,
29
+ variables: {
30
+ commentId,
31
+ interpretationId
32
+ }
33
+ });
34
+ return /*#__PURE__*/React.createElement(MessageIconButton, {
35
+ tooltipContent: i18n.t('Delete'),
36
+ iconComponent: IconDelete16,
37
+ onClick: remove,
38
+ disabled: loading
39
+ });
40
+ };
41
+
42
+ CommentDeleteButton.propTypes = {
43
+ commentId: PropTypes.string.isRequired,
44
+ interpretationId: PropTypes.string.isRequired,
45
+ onComplete: PropTypes.func.isRequired
46
+ };
47
+ export { CommentDeleteButton };
@@ -0,0 +1,73 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { useDataMutation } from '@dhis2/app-runtime';
3
+ import i18n from '@dhis2/d2-i18n';
4
+ import { Button, spacers, colors } from '@dhis2/ui';
5
+ import PropTypes from 'prop-types';
6
+ import React, { useState, useRef } from 'react';
7
+ import { MessageEditorContainer, RichTextEditor, MessageButtonStrip } from '../common/index.js';
8
+ export const CommentUpdateForm = _ref => {
9
+ let {
10
+ interpretationId,
11
+ commentId,
12
+ currentUser,
13
+ text,
14
+ close,
15
+ onComplete
16
+ } = _ref;
17
+ const [commentText, setCommentText] = useState(text || '');
18
+ const updateMutationRef = useRef({
19
+ resource: "interpretations/".concat(interpretationId, "/comments/").concat(commentId),
20
+ type: 'update',
21
+ partial: false,
22
+ data: _ref2 => {
23
+ let {
24
+ commentText
25
+ } = _ref2;
26
+ return commentText;
27
+ }
28
+ });
29
+ const [update, {
30
+ loading,
31
+ error
32
+ }] = useDataMutation(updateMutationRef.current, {
33
+ onComplete: () => {
34
+ onComplete();
35
+ close();
36
+ }
37
+ });
38
+ const errorText = error ? error.message || i18n.t('Could not update comment') : '';
39
+ return /*#__PURE__*/React.createElement("div", {
40
+ className: _JSXStyle.dynamic([["2690082310", [spacers.dp8, spacers.dp8, colors.grey100]]]) + " " + "message"
41
+ }, /*#__PURE__*/React.createElement(MessageEditorContainer, {
42
+ currentUser: currentUser
43
+ }, /*#__PURE__*/React.createElement(RichTextEditor, {
44
+ inputPlaceholder: i18n.t('Enter comment text'),
45
+ onChange: setCommentText,
46
+ value: commentText,
47
+ disabled: loading,
48
+ errorText: errorText
49
+ }), /*#__PURE__*/React.createElement(MessageButtonStrip, null, /*#__PURE__*/React.createElement(Button, {
50
+ loading: loading,
51
+ primary: true,
52
+ small: true,
53
+ onClick: () => update({
54
+ commentText
55
+ })
56
+ }, i18n.t('Update')), /*#__PURE__*/React.createElement(Button, {
57
+ disabled: loading,
58
+ secondary: true,
59
+ small: true,
60
+ onClick: close
61
+ }, i18n.t('Cancel')))), /*#__PURE__*/React.createElement(_JSXStyle, {
62
+ id: "2690082310",
63
+ dynamic: [spacers.dp8, spacers.dp8, colors.grey100]
64
+ }, [".message.__jsx-style-dynamic-selector{padding:0 ".concat(spacers.dp8, " ").concat(spacers.dp8, ";background-color:").concat(colors.grey100, ";border-radius:5px;}")]));
65
+ };
66
+ CommentUpdateForm.propTypes = {
67
+ close: PropTypes.func.isRequired,
68
+ commentId: PropTypes.string.isRequired,
69
+ currentUser: PropTypes.object.isRequired,
70
+ interpretationId: PropTypes.string.isRequired,
71
+ onComplete: PropTypes.func.isRequired,
72
+ text: PropTypes.string
73
+ };
@@ -0,0 +1,165 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { useDataQuery } from '@dhis2/app-runtime';
3
+ import i18n from '@dhis2/d2-i18n';
4
+ import { Modal, ModalActions, ModalContent, NoticeBox, Button, spacers, colors, Layer, CenteredContent, CircularLoader } from '@dhis2/ui';
5
+ import cx from 'classnames';
6
+ import PropTypes from 'prop-types';
7
+ import React, { useEffect, useState } from 'react';
8
+ import { InterpretationThread } from './InterpretationThread.js';
9
+ import { useModalContentWidth } from './useModalContentWidth.js';
10
+ const modalCSS = {
11
+ styles: /*#__PURE__*/React.createElement(_JSXStyle, {
12
+ id: "422732072"
13
+ }, ["aside.jsx-422732072{max-width:calc(100vw - 128px) !important;max-height:calc(100vh - 128px) !important;width:auto !important;height:auto !important;overflow-y:hidden;}", "aside.hidden.jsx-422732072{display:none;}", "aside.jsx-422732072>div>div{max-height:none;}"]),
14
+ className: "jsx-422732072"
15
+ };
16
+
17
+ function getModalContentCSS(width) {
18
+ return {
19
+ styles: /*#__PURE__*/React.createElement(_JSXStyle, {
20
+ id: "1689110567",
21
+ dynamic: [width]
22
+ }, ["div.__jsx-style-dynamic-selector{width:".concat(width, "px;}")]),
23
+ className: _JSXStyle.dynamic([["1689110567", [width]]])
24
+ };
25
+ }
26
+
27
+ const query = {
28
+ interpretation: {
29
+ resource: 'interpretations',
30
+ id: _ref => {
31
+ let {
32
+ id
33
+ } = _ref;
34
+ return id;
35
+ },
36
+ params: {
37
+ fields: ['access', 'id', 'text', 'created', 'user[id,displayName]', 'likes', 'likedBy', 'comments[access,id,text,created,createdBy[id,displayName]]']
38
+ }
39
+ }
40
+ };
41
+
42
+ const InterpretationModal = _ref2 => {
43
+ let {
44
+ currentUser,
45
+ isVisualizationLoading,
46
+ visualization,
47
+ onResponsesReceived,
48
+ downloadMenuComponent,
49
+ onClose,
50
+ onInterpretationUpdate,
51
+ interpretationId,
52
+ initialFocus,
53
+ pluginComponent: VisualizationPlugin
54
+ } = _ref2;
55
+ const modalContentWidth = useModalContentWidth();
56
+ const modalContentCSS = getModalContentCSS(modalContentWidth);
57
+ const [isDirty, setIsDirty] = useState(false);
58
+ const {
59
+ data,
60
+ error,
61
+ loading,
62
+ fetching,
63
+ refetch
64
+ } = useDataQuery(query, {
65
+ lazy: true
66
+ });
67
+ const interpretation = data === null || data === void 0 ? void 0 : data.interpretation;
68
+ const shouldRenderModalContent = !error && interpretation;
69
+ const shouldCssHideModal = loading || isVisualizationLoading;
70
+
71
+ const handleClose = () => {
72
+ if (isDirty) {
73
+ onInterpretationUpdate();
74
+ setIsDirty(false);
75
+ }
76
+
77
+ onClose();
78
+ };
79
+
80
+ const onThreadUpdated = affectsInterpretation => {
81
+ if (affectsInterpretation) {
82
+ setIsDirty(true);
83
+ }
84
+
85
+ refetch({
86
+ id: interpretationId
87
+ });
88
+ };
89
+
90
+ const onInterpretationDeleted = () => {
91
+ setIsDirty(false);
92
+ onInterpretationUpdate();
93
+ onClose();
94
+ };
95
+
96
+ useEffect(() => {
97
+ if (interpretationId) {
98
+ refetch({
99
+ id: interpretationId
100
+ });
101
+ }
102
+ }, [interpretationId]);
103
+ return /*#__PURE__*/React.createElement(React.Fragment, null, shouldCssHideModal && /*#__PURE__*/React.createElement(Layer, null, /*#__PURE__*/React.createElement(CenteredContent, null, /*#__PURE__*/React.createElement(CircularLoader, null))), /*#__PURE__*/React.createElement(Modal, {
104
+ fluid: true,
105
+ onClose: handleClose,
106
+ className: cx(modalCSS.className, {
107
+ hidden: shouldCssHideModal
108
+ })
109
+ }, /*#__PURE__*/React.createElement("h1", {
110
+ className: _JSXStyle.dynamic([["3636222142", [colors.grey900, spacers.dp24, spacers.dp4, spacers.dp4]]]) + " " + "title"
111
+ }, /*#__PURE__*/React.createElement("span", {
112
+ className: _JSXStyle.dynamic([["3636222142", [colors.grey900, spacers.dp24, spacers.dp4, spacers.dp4]]]) + " " + "ellipsis"
113
+ }, i18n.t('Viewing interpretation: {{visualisationName}}', {
114
+ visualisationName: visualization.displayName,
115
+ nsSeparator: '^^'
116
+ }))), /*#__PURE__*/React.createElement(ModalContent, {
117
+ className: modalContentCSS.className
118
+ }, /*#__PURE__*/React.createElement("div", {
119
+ className: _JSXStyle.dynamic([["3636222142", [colors.grey900, spacers.dp24, spacers.dp4, spacers.dp4]]]) + " " + "container"
120
+ }, error && /*#__PURE__*/React.createElement(NoticeBox, {
121
+ error: true,
122
+ title: i18n.t('Could not load interpretation')
123
+ }, error.message || i18n.t('The interpretation couldn’t be displayed. Try again or contact your system administrator.')), shouldRenderModalContent && /*#__PURE__*/React.createElement("div", {
124
+ className: _JSXStyle.dynamic([["3636222142", [colors.grey900, spacers.dp24, spacers.dp4, spacers.dp4]]]) + " " + "row"
125
+ }, /*#__PURE__*/React.createElement("div", {
126
+ className: _JSXStyle.dynamic([["3636222142", [colors.grey900, spacers.dp24, spacers.dp4, spacers.dp4]]]) + " " + "visualisation-wrap"
127
+ }, /*#__PURE__*/React.createElement(VisualizationPlugin, {
128
+ filters: {
129
+ relativePeriodDate: interpretation.created
130
+ },
131
+ visualization: visualization,
132
+ onResponsesReceived: onResponsesReceived,
133
+ className: _JSXStyle.dynamic([["3636222142", [colors.grey900, spacers.dp24, spacers.dp4, spacers.dp4]]])
134
+ })), /*#__PURE__*/React.createElement("div", {
135
+ className: _JSXStyle.dynamic([["3636222142", [colors.grey900, spacers.dp24, spacers.dp4, spacers.dp4]]]) + " " + "thread-wrap"
136
+ }, /*#__PURE__*/React.createElement(InterpretationThread, {
137
+ currentUser: currentUser,
138
+ fetching: fetching,
139
+ interpretation: interpretation,
140
+ onInterpretationDeleted: onInterpretationDeleted,
141
+ onThreadUpdated: onThreadUpdated,
142
+ initialFocus: initialFocus,
143
+ downloadMenuComponent: downloadMenuComponent
144
+ }))))), /*#__PURE__*/React.createElement(ModalActions, null, /*#__PURE__*/React.createElement(Button, {
145
+ disabled: fetching,
146
+ onClick: handleClose
147
+ }, i18n.t('Hide interpretation'))), modalCSS.styles, modalContentCSS.styles, /*#__PURE__*/React.createElement(_JSXStyle, {
148
+ id: "3636222142",
149
+ dynamic: [colors.grey900, spacers.dp24, spacers.dp4, spacers.dp4]
150
+ }, [".title.__jsx-style-dynamic-selector{color:".concat(colors.grey900, ";margin:0px;padding:").concat(spacers.dp24, " 0 ").concat(spacers.dp4, ";}"), ".ellipsis.__jsx-style-dynamic-selector{display:inline-block;font-size:20px;font-weight:500;line-height:24px;white-space:nowrap;width:100%;overflow:hidden;text-overflow:ellipsis;}", ".container.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}", ".row.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;gap:16px;}", ".visualisation-wrap.__jsx-style-dynamic-selector{-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;}", ".thread-wrap.__jsx-style-dynamic-selector{padding-right:".concat(spacers.dp4, ";-webkit-flex-basis:300px;-ms-flex-preferred-size:300px;flex-basis:300px;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;overflow-y:auto;}")])));
151
+ };
152
+
153
+ InterpretationModal.propTypes = {
154
+ currentUser: PropTypes.object.isRequired,
155
+ downloadMenuComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]).isRequired,
156
+ interpretationId: PropTypes.string.isRequired,
157
+ isVisualizationLoading: PropTypes.bool.isRequired,
158
+ pluginComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]).isRequired,
159
+ visualization: PropTypes.object.isRequired,
160
+ onClose: PropTypes.func.isRequired,
161
+ onResponsesReceived: PropTypes.func.isRequired,
162
+ initialFocus: PropTypes.bool,
163
+ onInterpretationUpdate: PropTypes.func
164
+ };
165
+ export { InterpretationModal };
@@ -0,0 +1,79 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { IconClock16, colors } from '@dhis2/ui';
3
+ import cx from 'classnames';
4
+ import moment from 'moment';
5
+ import PropTypes from 'prop-types';
6
+ import React, { useRef, useEffect } from 'react';
7
+ import { Interpretation } from '../common/index.js';
8
+ import { Comment } from './Comment.js';
9
+ import { CommentAddForm } from './CommentAddForm.js';
10
+
11
+ const InterpretationThread = _ref => {
12
+ let {
13
+ currentUser,
14
+ fetching,
15
+ interpretation,
16
+ onInterpretationDeleted,
17
+ initialFocus,
18
+ onThreadUpdated,
19
+ downloadMenuComponent: DownloadMenu
20
+ } = _ref;
21
+ const focusRef = useRef();
22
+ useEffect(() => {
23
+ if (initialFocus && focusRef.current) {
24
+ window.requestAnimationFrame(() => {
25
+ focusRef.current.focus();
26
+ });
27
+ }
28
+ }, [initialFocus, focusRef.current]);
29
+ return /*#__PURE__*/React.createElement("div", {
30
+ className: "jsx-2924001448" + " " + (cx('container', {
31
+ fetching
32
+ }) || "")
33
+ }, /*#__PURE__*/React.createElement("div", {
34
+ className: "jsx-2924001448" + " " + 'scrollbox'
35
+ }, /*#__PURE__*/React.createElement("div", {
36
+ className: "jsx-2924001448" + " " + 'title'
37
+ }, /*#__PURE__*/React.createElement(IconClock16, {
38
+ color: colors.grey700
39
+ }), moment(interpretation.created).format('LLL')), /*#__PURE__*/React.createElement(DownloadMenu, {
40
+ relativePeriodDate: interpretation.created,
41
+ className: "jsx-2924001448"
42
+ }), /*#__PURE__*/React.createElement(Interpretation, {
43
+ currentUser: currentUser,
44
+ interpretation: interpretation,
45
+ onReplyIconClick: () => {
46
+ var _focusRef$current;
47
+
48
+ return (_focusRef$current = focusRef.current) === null || _focusRef$current === void 0 ? void 0 : _focusRef$current.focus();
49
+ },
50
+ onUpdated: () => onThreadUpdated(true),
51
+ onDeleted: onInterpretationDeleted
52
+ }), /*#__PURE__*/React.createElement("div", {
53
+ className: "jsx-2924001448" + " " + 'comments'
54
+ }, interpretation.comments.map(comment => /*#__PURE__*/React.createElement(Comment, {
55
+ key: comment.id,
56
+ comment: comment,
57
+ currentUser: currentUser,
58
+ interpretationId: interpretation.id,
59
+ onThreadUpdated: onThreadUpdated
60
+ }))), /*#__PURE__*/React.createElement(CommentAddForm, {
61
+ currentUser: currentUser,
62
+ interpretationId: interpretation.id,
63
+ onSave: () => onThreadUpdated(true),
64
+ focusRef: focusRef
65
+ })), /*#__PURE__*/React.createElement(_JSXStyle, {
66
+ id: "2924001448"
67
+ }, [".container.jsx-2924001448{position:relative;overflow:hidden;max-height:calc(100vh - 285px);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}", ".container.fetching.jsx-2924001448::before{content:'';position:absolute;inset:0px;background-color:rgba(255,255,255,0.8);}", ".container.fetching.jsx-2924001448::after{content:'';position:absolute;top:calc(50% - 12px);left:calc(50% - 12px);width:24px;height:24px;border-width:4px;border-style:solid;border-color:rgba(110,122,138,0.15) rgba(110,122,138,0.15) rgb(20,124,215);border-image:initial;border-radius:50%;-webkit-animation:1s linear 0s infinite normal none running rotation-jsx-2924001448;animation:1s linear 0s infinite normal none running rotation-jsx-2924001448;}", ".scrollbox.jsx-2924001448{overflow-y:auto;-webkit-scroll-behavior:smooth;-moz-scroll-behavior:smooth;-ms-scroll-behavior:smooth;scroll-behavior:smooth;}", ".title.jsx-2924001448{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;gap:var(--spacers-dp8);color:var(--colors-grey900);font-size:14px;line-height:18px;}", ".comments.jsx-2924001448{padding-left:16px;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;padding-top:var(--spacers-dp4);gap:var(--spacers-dp4);}", "@-webkit-keyframes rotation-jsx-2924001448{0%{-webkit-transform:rotate(0);-ms-transform:rotate(0);transform:rotate(0);}100%{-webkit-transform:rotate(360deg);-ms-transform:rotate(360deg);transform:rotate(360deg);}}", "@keyframes rotation-jsx-2924001448{0%{-webkit-transform:rotate(0);-ms-transform:rotate(0);transform:rotate(0);}100%{-webkit-transform:rotate(360deg);-ms-transform:rotate(360deg);transform:rotate(360deg);}}"]));
68
+ };
69
+
70
+ InterpretationThread.propTypes = {
71
+ currentUser: PropTypes.object.isRequired,
72
+ downloadMenuComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]).isRequired,
73
+ fetching: PropTypes.bool.isRequired,
74
+ interpretation: PropTypes.object.isRequired,
75
+ onInterpretationDeleted: PropTypes.func.isRequired,
76
+ initialFocus: PropTypes.bool,
77
+ onThreadUpdated: PropTypes.func
78
+ };
79
+ export { InterpretationThread };
@@ -0,0 +1 @@
1
+ export { InterpretationModal } from './InterpretationModal.js';
@@ -0,0 +1,28 @@
1
+ import { useState, useEffect } from 'react';
2
+ import { useDebounce } from '../../../modules/utils.js';
3
+ const MODAL_SIDE_PADDING = 2 * 24;
4
+ const MODAL_SIDE_MARGINS = 2 * 128;
5
+
6
+ const computeModalContentWidth = windowWidth => {
7
+ return windowWidth - MODAL_SIDE_MARGINS - MODAL_SIDE_PADDING;
8
+ };
9
+
10
+ export const useModalContentWidth = () => {
11
+ const [windowWidth, setWindowWidth] = useState(window.innerWidth);
12
+ const debouncedWindowWidth = useDebounce(windowWidth, 150);
13
+ const [modalContentWidth, setModalContentWidth] = useState(computeModalContentWidth(windowWidth));
14
+ useEffect(() => {
15
+ const onResize = () => {
16
+ setWindowWidth(window.innerWidth);
17
+ };
18
+
19
+ window.addEventListener('resize', onResize);
20
+ return () => {
21
+ window.removeEventListener('resize', onResize);
22
+ };
23
+ }, []);
24
+ useEffect(() => {
25
+ setModalContentWidth(computeModalContentWidth(debouncedWindowWidth));
26
+ }, [debouncedWindowWidth]);
27
+ return modalContentWidth;
28
+ };
@@ -0,0 +1,71 @@
1
+ import { useDataMutation } from '@dhis2/app-runtime';
2
+ import i18n from '@dhis2/d2-i18n';
3
+ import { Button, Input } from '@dhis2/ui';
4
+ import PropTypes from 'prop-types';
5
+ import React, { useRef, useState } from 'react';
6
+ import { RichTextEditor, MessageEditorContainer, MessageButtonStrip } from '../common/index.js';
7
+ export const InterpretationForm = _ref => {
8
+ let {
9
+ type,
10
+ id,
11
+ currentUser,
12
+ disabled,
13
+ onSave
14
+ } = _ref;
15
+ const [showRichTextEditor, setShowRichTextEditor] = useState(false);
16
+ const [interpretationText, setInterpretationText] = useState('');
17
+ const saveMutationRef = useRef({
18
+ resource: "interpretations/".concat(type, "/").concat(id),
19
+ type: 'create',
20
+ data: _ref2 => {
21
+ let {
22
+ interpretationText
23
+ } = _ref2;
24
+ return interpretationText;
25
+ }
26
+ });
27
+ const [save, {
28
+ loading: saveMutationInProgress
29
+ }] = useDataMutation(saveMutationRef.current, {
30
+ onComplete: () => {
31
+ setShowRichTextEditor(false);
32
+ setInterpretationText('');
33
+ onSave();
34
+ }
35
+ });
36
+ const inputPlaceholder = i18n.t('Write an interpretation');
37
+ return /*#__PURE__*/React.createElement(MessageEditorContainer, {
38
+ currentUser: currentUser
39
+ }, showRichTextEditor ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(RichTextEditor, {
40
+ disabled: saveMutationInProgress,
41
+ inputPlaceholder: inputPlaceholder,
42
+ onChange: setInterpretationText,
43
+ value: interpretationText
44
+ }), /*#__PURE__*/React.createElement(MessageButtonStrip, null, /*#__PURE__*/React.createElement(Button, {
45
+ primary: true,
46
+ small: true,
47
+ disabled: saveMutationInProgress,
48
+ onClick: () => save({
49
+ interpretationText
50
+ })
51
+ }, i18n.t('Post interpretation')), /*#__PURE__*/React.createElement(Button, {
52
+ secondary: true,
53
+ small: true,
54
+ disabled: saveMutationInProgress,
55
+ onClick: () => {
56
+ setInterpretationText('');
57
+ setShowRichTextEditor(false);
58
+ }
59
+ }, i18n.t('Cancel')))) : /*#__PURE__*/React.createElement(Input, {
60
+ onFocus: () => setShowRichTextEditor(true),
61
+ placeholder: inputPlaceholder,
62
+ disabled: disabled
63
+ }));
64
+ };
65
+ InterpretationForm.propTypes = {
66
+ currentUser: PropTypes.object,
67
+ disabled: PropTypes.bool,
68
+ id: PropTypes.string,
69
+ type: PropTypes.string,
70
+ onSave: PropTypes.func
71
+ };
@@ -0,0 +1,78 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { IconCalendar24, colors, spacers } from '@dhis2/ui';
3
+ import moment from 'moment';
4
+ import PropTypes from 'prop-types';
5
+ import React from 'react';
6
+ import { Interpretation } from '../common/index.js';
7
+
8
+ const sortByCreatedDateDesc = (a, b) => {
9
+ const dateA = a.created;
10
+ const dateB = b.created;
11
+
12
+ if (dateA < dateB) {
13
+ return 1;
14
+ }
15
+
16
+ if (dateA > dateB) {
17
+ return -1;
18
+ }
19
+
20
+ return 0;
21
+ };
22
+
23
+ export const InterpretationList = _ref => {
24
+ let {
25
+ currentUser,
26
+ interpretations,
27
+ onInterpretationClick,
28
+ onReplyIconClick,
29
+ refresh,
30
+ disabled
31
+ } = _ref;
32
+ const interpretationsByDate = interpretations.reduce((groupedInterpretations, interpretation) => {
33
+ const date = interpretation.created.split('T')[0];
34
+
35
+ if (date in groupedInterpretations) {
36
+ groupedInterpretations[date].push(interpretation);
37
+ } else {
38
+ groupedInterpretations[date] = [interpretation];
39
+ }
40
+
41
+ return groupedInterpretations;
42
+ }, {});
43
+ return /*#__PURE__*/React.createElement("ol", {
44
+ className: _JSXStyle.dynamic([["4058400613", [spacers.dp8, spacers.dp8, spacers.dp16, colors.grey800, spacers.dp12, spacers.dp12, spacers.dp32, spacers.dp4]]]) + " " + "interpretation-groups"
45
+ }, Object.keys(interpretationsByDate).sort().reverse().map(date => /*#__PURE__*/React.createElement("li", {
46
+ key: date,
47
+ className: _JSXStyle.dynamic([["4058400613", [spacers.dp8, spacers.dp8, spacers.dp16, colors.grey800, spacers.dp12, spacers.dp12, spacers.dp32, spacers.dp4]]])
48
+ }, /*#__PURE__*/React.createElement("div", {
49
+ className: _JSXStyle.dynamic([["4058400613", [spacers.dp8, spacers.dp8, spacers.dp16, colors.grey800, spacers.dp12, spacers.dp12, spacers.dp32, spacers.dp4]]]) + " " + "date-section"
50
+ }, /*#__PURE__*/React.createElement(IconCalendar24, {
51
+ color: colors.grey600
52
+ }), /*#__PURE__*/React.createElement("time", {
53
+ dateTime: date,
54
+ className: _JSXStyle.dynamic([["4058400613", [spacers.dp8, spacers.dp8, spacers.dp16, colors.grey800, spacers.dp12, spacers.dp12, spacers.dp32, spacers.dp4]]]) + " " + "date-header"
55
+ }, moment(date).format('ll'))), /*#__PURE__*/React.createElement("ol", {
56
+ className: _JSXStyle.dynamic([["4058400613", [spacers.dp8, spacers.dp8, spacers.dp16, colors.grey800, spacers.dp12, spacers.dp12, spacers.dp32, spacers.dp4]]]) + " " + "interpretation-list"
57
+ }, interpretationsByDate[date].sort(sortByCreatedDateDesc).map(interpretation => /*#__PURE__*/React.createElement(Interpretation, {
58
+ key: interpretation.id,
59
+ interpretation: interpretation,
60
+ currentUser: currentUser,
61
+ onClick: onInterpretationClick,
62
+ onReplyIconClick: onReplyIconClick,
63
+ onDeleted: refresh,
64
+ onUpdated: refresh,
65
+ disabled: disabled
66
+ }))))), /*#__PURE__*/React.createElement(_JSXStyle, {
67
+ id: "4058400613",
68
+ dynamic: [spacers.dp8, spacers.dp8, spacers.dp16, colors.grey800, spacers.dp12, spacers.dp12, spacers.dp32, spacers.dp4]
69
+ }, [".date-section.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:".concat(spacers.dp8, ";-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;margin-bottom:").concat(spacers.dp8, ";}"), ".date-header.__jsx-style-dynamic-selector{font-size:14px;font-weight:500;line-height:".concat(spacers.dp16, ";color:").concat(colors.grey800, ";}"), ".interpretation-groups.__jsx-style-dynamic-selector{margin:0;padding:0;padding-top:".concat(spacers.dp12, ";list-style:none;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:").concat(spacers.dp12, ";}"), ".interpretation-list.__jsx-style-dynamic-selector{margin:0;padding-left:".concat(spacers.dp32, ";list-style:none;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;gap:").concat(spacers.dp4, ";}")]));
70
+ };
71
+ InterpretationList.propTypes = {
72
+ currentUser: PropTypes.object.isRequired,
73
+ interpretations: PropTypes.array.isRequired,
74
+ refresh: PropTypes.func.isRequired,
75
+ onInterpretationClick: PropTypes.func.isRequired,
76
+ onReplyIconClick: PropTypes.func.isRequired,
77
+ disabled: PropTypes.bool
78
+ };
@@ -0,0 +1,112 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { useDataQuery } from '@dhis2/app-runtime';
3
+ import i18n from '@dhis2/d2-i18n';
4
+ import { CircularLoader, IconChevronDown24, IconChevronUp24, colors, spacers } from '@dhis2/ui';
5
+ import cx from 'classnames';
6
+ import PropTypes from 'prop-types';
7
+ import React, { useEffect, useState, useImperativeHandle, forwardRef } from 'react';
8
+ import { InterpretationForm } from './InterpretationForm.js';
9
+ import { InterpretationList } from './InterpretationList.js';
10
+ const interpretationsQuery = {
11
+ interpretations: {
12
+ resource: 'interpretations',
13
+ params: _ref => {
14
+ let {
15
+ type,
16
+ id
17
+ } = _ref;
18
+ return {
19
+ fields: ['access', 'id', 'user[displayName]', 'created', 'text', 'comments[id]', 'likes', 'likedBy[id]'],
20
+ filter: "".concat(type, ".id:eq:").concat(id)
21
+ };
22
+ }
23
+ }
24
+ };
25
+ export const InterpretationsUnit = /*#__PURE__*/forwardRef((_ref2, ref) => {
26
+ let {
27
+ currentUser,
28
+ type,
29
+ id,
30
+ onInterpretationClick,
31
+ onReplyIconClick,
32
+ disabled
33
+ } = _ref2;
34
+ const [isExpanded, setIsExpanded] = useState(true);
35
+ const {
36
+ data,
37
+ loading,
38
+ fetching,
39
+ refetch
40
+ } = useDataQuery(interpretationsQuery, {
41
+ lazy: true
42
+ });
43
+
44
+ const onCompleteAction = () => {
45
+ refetch({
46
+ type,
47
+ id
48
+ });
49
+ };
50
+
51
+ useImperativeHandle(ref, () => ({
52
+ refresh: onCompleteAction
53
+ }), []);
54
+ useEffect(() => {
55
+ if (id) {
56
+ refetch({
57
+ type,
58
+ id
59
+ });
60
+ }
61
+ }, [type, id]);
62
+ return /*#__PURE__*/React.createElement("div", {
63
+ className: _JSXStyle.dynamic([["4120713286", [spacers.dp16, colors.grey400, colors.white, spacers.dp32, colors.grey900]]]) + " " + (cx('container', {
64
+ expanded: isExpanded
65
+ }) || "")
66
+ }, fetching && !loading && /*#__PURE__*/React.createElement("div", {
67
+ className: _JSXStyle.dynamic([["4120713286", [spacers.dp16, colors.grey400, colors.white, spacers.dp32, colors.grey900]]]) + " " + "fetching-loader"
68
+ }, /*#__PURE__*/React.createElement(CircularLoader, {
69
+ small: true
70
+ })), /*#__PURE__*/React.createElement("div", {
71
+ onClick: () => setIsExpanded(!isExpanded),
72
+ className: _JSXStyle.dynamic([["4120713286", [spacers.dp16, colors.grey400, colors.white, spacers.dp32, colors.grey900]]]) + " " + "header"
73
+ }, /*#__PURE__*/React.createElement("span", {
74
+ className: _JSXStyle.dynamic([["4120713286", [spacers.dp16, colors.grey400, colors.white, spacers.dp32, colors.grey900]]]) + " " + "title"
75
+ }, i18n.t('Interpretations')), isExpanded ? /*#__PURE__*/React.createElement(IconChevronUp24, {
76
+ color: colors.grey700
77
+ }) : /*#__PURE__*/React.createElement(IconChevronDown24, {
78
+ color: colors.grey700
79
+ })), isExpanded && /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement("div", {
80
+ className: _JSXStyle.dynamic([["4120713286", [spacers.dp16, colors.grey400, colors.white, spacers.dp32, colors.grey900]]]) + " " + "loader"
81
+ }, /*#__PURE__*/React.createElement(CircularLoader, {
82
+ small: true
83
+ })), data && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(InterpretationForm, {
84
+ currentUser: currentUser,
85
+ type: type,
86
+ id: id,
87
+ onSave: onCompleteAction,
88
+ disabled: disabled
89
+ }), /*#__PURE__*/React.createElement(InterpretationList, {
90
+ currentUser: currentUser,
91
+ interpretations: data.interpretations.interpretations,
92
+ onInterpretationClick: onInterpretationClick,
93
+ onReplyIconClick: onReplyIconClick,
94
+ refresh: onCompleteAction,
95
+ disabled: disabled
96
+ }))), /*#__PURE__*/React.createElement(_JSXStyle, {
97
+ id: "4120713286",
98
+ dynamic: [spacers.dp16, colors.grey400, colors.white, spacers.dp32, colors.grey900]
99
+ }, [".container.__jsx-style-dynamic-selector{position:relative;padding:".concat(spacers.dp16, ";border-bottom:1px solid ").concat(colors.grey400, ";background-color:").concat(colors.white, ";}"), ".fetching-loader.__jsx-style-dynamic-selector{position:absolute;inset:0px;background-color:rgba(255,255,255,0.8);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;z-index:1;}", ".expanded.__jsx-style-dynamic-selector{padding-bottom:".concat(spacers.dp32, ";}"), ".loader.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}", ".header.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;cursor:pointer;}", ".title.__jsx-style-dynamic-selector{font-size:16px;font-weight:500;line-height:21px;color:".concat(colors.grey900, ";}")]));
100
+ });
101
+ InterpretationsUnit.displayName = 'InterpretationsUnit';
102
+ InterpretationsUnit.defaultProps = {
103
+ onInterpretationClick: Function.prototype
104
+ };
105
+ InterpretationsUnit.propTypes = {
106
+ currentUser: PropTypes.object.isRequired,
107
+ id: PropTypes.string.isRequired,
108
+ type: PropTypes.string.isRequired,
109
+ disabled: PropTypes.bool,
110
+ onInterpretationClick: PropTypes.func,
111
+ onReplyIconClick: PropTypes.func
112
+ };
@@ -0,0 +1 @@
1
+ export { InterpretationsUnit } from './InterpretationsUnit.js';