@dhis2/analytics 28.1.2 → 29.0.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 (59) hide show
  1. package/build/cjs/__demo__/InterpretationsUnit.stories.js +9 -6
  2. package/build/cjs/__fixtures__/interpretationsMockData.js +204 -0
  3. package/build/cjs/components/Interpretations/DashboardItemInterpretations/DashboardInterpretationThread.js +56 -0
  4. package/build/cjs/components/Interpretations/DashboardItemInterpretations/DashboardItemInterpretations.js +54 -0
  5. package/build/cjs/components/Interpretations/DashboardItemInterpretations/index.js +12 -0
  6. package/build/cjs/components/Interpretations/InterpretationModal/Comment.js +12 -17
  7. package/build/cjs/components/Interpretations/InterpretationModal/CommentAddForm.js +20 -34
  8. package/build/cjs/components/Interpretations/InterpretationModal/CommentDeleteButton.js +11 -36
  9. package/build/cjs/components/Interpretations/InterpretationModal/CommentUpdateForm.js +11 -27
  10. package/build/cjs/components/Interpretations/InterpretationModal/InterpretationModal.js +11 -68
  11. package/build/cjs/components/Interpretations/InterpretationModal/InterpretationThread.js +11 -24
  12. package/build/cjs/components/Interpretations/InterpretationsProvider/InterpretationsManager.js +275 -0
  13. package/build/cjs/components/Interpretations/InterpretationsProvider/InterpretationsProvider.js +28 -0
  14. package/build/cjs/components/Interpretations/InterpretationsProvider/__tests__/groupInterpretationIdsByDate.spec.js +37 -0
  15. package/build/cjs/components/Interpretations/InterpretationsProvider/__tests__/hooks.spec.js +565 -0
  16. package/build/cjs/components/Interpretations/InterpretationsProvider/groupInterpretationIdsByDate.js +16 -0
  17. package/build/cjs/components/Interpretations/InterpretationsProvider/hooks.js +278 -0
  18. package/build/cjs/components/Interpretations/InterpretationsProvider/index.js +12 -0
  19. package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationForm.js +25 -30
  20. package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationList.js +8 -38
  21. package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +22 -73
  22. package/build/cjs/components/Interpretations/common/Interpretation/Interpretation.js +20 -34
  23. package/build/cjs/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js +10 -12
  24. package/build/cjs/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js +13 -24
  25. package/build/cjs/components/Interpretations/common/Message/MessageEditorContainer.js +3 -3
  26. package/build/cjs/index.js +72 -63
  27. package/build/cjs/locales/en/translations.json +10 -1
  28. package/build/cjs/modules/pivotTable/getHeaderForDisplay.js +1 -1
  29. package/build/es/__demo__/InterpretationsUnit.stories.js +9 -6
  30. package/build/es/__fixtures__/interpretationsMockData.js +198 -0
  31. package/build/es/components/Interpretations/DashboardItemInterpretations/DashboardInterpretationThread.js +48 -0
  32. package/build/es/components/Interpretations/DashboardItemInterpretations/DashboardItemInterpretations.js +45 -0
  33. package/build/es/components/Interpretations/DashboardItemInterpretations/index.js +1 -0
  34. package/build/es/components/Interpretations/InterpretationModal/Comment.js +14 -19
  35. package/build/es/components/Interpretations/InterpretationModal/CommentAddForm.js +21 -35
  36. package/build/es/components/Interpretations/InterpretationModal/CommentDeleteButton.js +11 -35
  37. package/build/es/components/Interpretations/InterpretationModal/CommentUpdateForm.js +12 -28
  38. package/build/es/components/Interpretations/InterpretationModal/InterpretationModal.js +12 -69
  39. package/build/es/components/Interpretations/InterpretationModal/InterpretationThread.js +11 -24
  40. package/build/es/components/Interpretations/InterpretationsProvider/InterpretationsManager.js +268 -0
  41. package/build/es/components/Interpretations/InterpretationsProvider/InterpretationsProvider.js +19 -0
  42. package/build/es/components/Interpretations/InterpretationsProvider/__tests__/groupInterpretationIdsByDate.spec.js +35 -0
  43. package/build/es/components/Interpretations/InterpretationsProvider/__tests__/hooks.spec.js +561 -0
  44. package/build/es/components/Interpretations/InterpretationsProvider/groupInterpretationIdsByDate.js +9 -0
  45. package/build/es/components/Interpretations/InterpretationsProvider/hooks.js +258 -0
  46. package/build/es/components/Interpretations/InterpretationsProvider/index.js +1 -0
  47. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationForm.js +26 -31
  48. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationList.js +8 -38
  49. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +23 -75
  50. package/build/es/components/Interpretations/common/Interpretation/Interpretation.js +21 -35
  51. package/build/es/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js +11 -13
  52. package/build/es/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js +14 -25
  53. package/build/es/components/Interpretations/common/Message/MessageEditorContainer.js +3 -3
  54. package/build/es/index.js +3 -1
  55. package/build/es/locales/en/translations.json +10 -1
  56. package/build/es/modules/pivotTable/getHeaderForDisplay.js +1 -1
  57. package/package.json +1 -1
  58. package/build/cjs/components/Interpretations/common/Interpretation/useLike.js +0 -56
  59. package/build/es/components/Interpretations/common/Interpretation/useLike.js +0 -50
@@ -0,0 +1,198 @@
1
+ export const currentUser = {
2
+ id: 'currentuserid',
3
+ name: 'John Traore',
4
+ email: 'dummy@dhis2.org',
5
+ settings: {
6
+ keyDbLocale: 'en',
7
+ keyMessageSmsNotification: false,
8
+ keyTrackerDashboardLayout: '',
9
+ keyCurrentStyle: 'light_blue/light_blue.css',
10
+ keyStyle: 'light_blue/light_blue.css',
11
+ keyUiLocale: 'en',
12
+ keyAnalysisDisplayProperty: 'name',
13
+ keyMessageEmailNotification: false
14
+ },
15
+ authorities: ['F_VIEW_UNAPPROVED_DATA']
16
+ };
17
+ export const interpretations = [{
18
+ id: 'interpretation1',
19
+ text: 'This is the first interpretation',
20
+ created: '2025-09-04T07:47:12.477',
21
+ createdBy: {
22
+ id: 'currentuserid',
23
+ code: null,
24
+ name: 'John Traore',
25
+ displayName: 'John Traore',
26
+ username: 'admin'
27
+ },
28
+ comments: [{
29
+ id: 'commentid1'
30
+ }, {
31
+ id: 'commentid2'
32
+ }],
33
+ likes: 1,
34
+ access: {
35
+ manage: true,
36
+ write: true
37
+ },
38
+ likedBy: [{
39
+ id: 'currentuserid',
40
+ code: null,
41
+ name: 'John Traore',
42
+ displayName: 'John Traore',
43
+ username: 'admin'
44
+ }]
45
+ }, {
46
+ id: 'interpretation2',
47
+ text: 'Analysis shows interesting trends in the data distribution across different regions',
48
+ created: '2025-09-03T14:22:35.891',
49
+ createdBy: {
50
+ id: 'otheruserid1',
51
+ code: null,
52
+ name: 'Sarah Johnson',
53
+ displayName: 'Sarah Johnson',
54
+ username: 'sjohnson'
55
+ },
56
+ comments: [{
57
+ id: 'commentid3'
58
+ }],
59
+ likes: 3,
60
+ access: {
61
+ manage: false,
62
+ write: false
63
+ },
64
+ likedBy: [{
65
+ id: 'currentuserid',
66
+ code: null,
67
+ name: 'John Traore',
68
+ displayName: 'John Traore',
69
+ username: 'admin'
70
+ }, {
71
+ id: 'otheruserid1',
72
+ code: null,
73
+ name: 'Sarah Johnson',
74
+ displayName: 'Sarah Johnson',
75
+ username: 'sjohnson'
76
+ }, {
77
+ id: 'otheruserid2',
78
+ code: null,
79
+ name: 'Mike Chen',
80
+ displayName: 'Mike Chen',
81
+ username: 'mchen'
82
+ }]
83
+ }, {
84
+ id: 'interpretation3',
85
+ text: 'The quarterly report reveals significant improvements in performance metrics',
86
+ created: '2025-09-02T10:15:48.123',
87
+ createdBy: {
88
+ id: 'currentuserid',
89
+ code: null,
90
+ name: 'John Traore',
91
+ displayName: 'John Traore',
92
+ username: 'admin'
93
+ },
94
+ comments: [],
95
+ likes: 0,
96
+ access: {
97
+ manage: true,
98
+ write: true
99
+ },
100
+ likedBy: []
101
+ }, {
102
+ id: 'interpretation4',
103
+ text: 'We need to investigate the outliers in this dataset more thoroughly',
104
+ created: '2025-09-01T16:33:21.654',
105
+ createdBy: {
106
+ id: 'otheruserid2',
107
+ code: null,
108
+ name: 'Mike Chen',
109
+ displayName: 'Mike Chen',
110
+ username: 'mchen'
111
+ },
112
+ comments: [{
113
+ id: 'commentid4'
114
+ }, {
115
+ id: 'commentid5'
116
+ }, {
117
+ id: 'commentid6'
118
+ }],
119
+ likes: 2,
120
+ access: {
121
+ manage: false,
122
+ write: true
123
+ },
124
+ likedBy: [{
125
+ id: 'otheruserid1',
126
+ code: null,
127
+ name: 'Sarah Johnson',
128
+ displayName: 'Sarah Johnson',
129
+ username: 'sjohnson'
130
+ }, {
131
+ id: 'otheruserid2',
132
+ code: null,
133
+ name: 'Mike Chen',
134
+ displayName: 'Mike Chen',
135
+ username: 'mchen'
136
+ }]
137
+ }];
138
+ export const interpretationDetails = {
139
+ ...interpretations[0],
140
+ comments: [{
141
+ created: '2025-09-04T07:47:39.167',
142
+ createdBy: {
143
+ id: 'currentuserid',
144
+ code: null,
145
+ name: 'John Traore',
146
+ displayName: 'John Traore',
147
+ username: 'admin'
148
+ },
149
+ text: 'This is the first comment',
150
+ id: 'commentid1'
151
+ }, {
152
+ created: '2025-09-04T07:47:42.011',
153
+ createdBy: {
154
+ id: 'currentuserid',
155
+ code: null,
156
+ name: 'John Traore',
157
+ displayName: 'John Traore',
158
+ username: 'admin'
159
+ },
160
+ text: 'This is the second comment',
161
+ id: 'commentid2'
162
+ }]
163
+ };
164
+ export const newInterpretation = {
165
+ id: 'interpretation5',
166
+ text: 'This is a new interpretation for testing',
167
+ created: '2025-09-04T08:30:15.123',
168
+ createdBy: {
169
+ id: 'currentuserid',
170
+ code: null,
171
+ name: 'John Traore',
172
+ displayName: 'John Traore',
173
+ username: 'admin'
174
+ },
175
+ comments: [],
176
+ likes: 0,
177
+ access: {
178
+ manage: true,
179
+ write: true
180
+ },
181
+ likedBy: []
182
+ };
183
+ export const newComment = {
184
+ created: '2025-09-04T08:45:22.456',
185
+ createdBy: {
186
+ id: 'currentuserid',
187
+ code: null,
188
+ name: 'John Traore',
189
+ displayName: 'John Traore',
190
+ username: 'admin'
191
+ },
192
+ text: 'This is a new comment for testing',
193
+ id: 'commentid7'
194
+ };
195
+ export const visualization = {
196
+ id: 'viz123',
197
+ type: 'CHART'
198
+ };
@@ -0,0 +1,48 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import i18n from '@dhis2/d2-i18n';
3
+ import { Layer, CenteredContent, CircularLoader, Button, IconChevronLeft16, NoticeBox } from '@dhis2/ui';
4
+ import PropTypes from 'prop-types';
5
+ import React from 'react';
6
+ import { InterpretationThread } from '../InterpretationModal/InterpretationThread.js';
7
+ import { useActiveInterpretation } from '../InterpretationsProvider/hooks.js';
8
+ export const DashboardInterpretationThread = ({
9
+ interpretationId,
10
+ onClose,
11
+ dashboardRedirectUrl,
12
+ initialFocus
13
+ }) => {
14
+ const {
15
+ data: interpretation,
16
+ loading,
17
+ error
18
+ } = useActiveInterpretation(interpretationId);
19
+ if (loading) {
20
+ return /*#__PURE__*/React.createElement(Layer, null, /*#__PURE__*/React.createElement(CenteredContent, null, /*#__PURE__*/React.createElement(CircularLoader, null)));
21
+ }
22
+ return /*#__PURE__*/React.createElement("div", {
23
+ className: "jsx-95761030" + " " + "container"
24
+ }, /*#__PURE__*/React.createElement("div", {
25
+ className: "jsx-95761030" + " " + "button-container"
26
+ }, /*#__PURE__*/React.createElement(Button, {
27
+ small: true,
28
+ icon: /*#__PURE__*/React.createElement(IconChevronLeft16, null),
29
+ onClick: onClose
30
+ }, i18n.t('Back to all interpretations'))), error && /*#__PURE__*/React.createElement(NoticeBox, {
31
+ error: true,
32
+ title: i18n.t('Could not load interpretation details')
33
+ }, i18n.t('The request to fetch interpretation comments failed')), interpretation && !error && /*#__PURE__*/React.createElement(InterpretationThread, {
34
+ loading: loading,
35
+ interpretation: interpretation,
36
+ onInterpretationDeleted: onClose,
37
+ initialFocus: initialFocus,
38
+ dashboardRedirectUrl: dashboardRedirectUrl
39
+ }), /*#__PURE__*/React.createElement(_JSXStyle, {
40
+ id: "95761030"
41
+ }, [".container.jsx-95761030{padding:var(--spacers-dp16) var(--spacers-dp16) var(--spacers-dp32) var(--spacers-dp16);}", ".button-container.jsx-95761030{margin-bottom:var(--spacers-dp8);}"]));
42
+ };
43
+ DashboardInterpretationThread.propTypes = {
44
+ interpretationId: PropTypes.string.isRequired,
45
+ onClose: PropTypes.func.isRequired,
46
+ dashboardRedirectUrl: PropTypes.string,
47
+ initialFocus: PropTypes.bool
48
+ };
@@ -0,0 +1,45 @@
1
+ import PropTypes from 'prop-types';
2
+ import React, { useCallback, useState } from 'react';
3
+ import { InterpretationsProvider } from '../InterpretationsProvider/InterpretationsProvider.js';
4
+ import { InterpretationsUnit } from '../InterpretationsUnit/InterpretationsUnit.js';
5
+ import { DashboardInterpretationThread } from './DashboardInterpretationThread.js';
6
+ export const DashboardItemInterpretations = ({
7
+ currentUser,
8
+ dashboardRedirectUrl,
9
+ id,
10
+ type
11
+ }) => {
12
+ const [activeInterpretationId, setActiveInterpretationId] = useState(null);
13
+ const [initialFocus, setInitialFocus] = useState(false);
14
+ const onInterpretationClick = useCallback(interpretationId => {
15
+ setActiveInterpretationId(interpretationId);
16
+ }, []);
17
+ const onReplyIconClick = useCallback(interpretationId => {
18
+ setActiveInterpretationId(interpretationId);
19
+ setInitialFocus(true);
20
+ }, []);
21
+ const onClose = useCallback(() => {
22
+ setActiveInterpretationId(null);
23
+ setInitialFocus(false);
24
+ }, []);
25
+ return /*#__PURE__*/React.createElement(InterpretationsProvider, {
26
+ currentUser: currentUser
27
+ }, activeInterpretationId ? /*#__PURE__*/React.createElement(DashboardInterpretationThread, {
28
+ interpretationId: activeInterpretationId,
29
+ onClose: onClose,
30
+ dashboardRedirectUrl: dashboardRedirectUrl,
31
+ initialFocus: initialFocus
32
+ }) : /*#__PURE__*/React.createElement(InterpretationsUnit, {
33
+ id: id,
34
+ type: type,
35
+ dashboardRedirectUrl: dashboardRedirectUrl,
36
+ onInterpretationClick: onInterpretationClick,
37
+ onReplyIconClick: onReplyIconClick
38
+ }));
39
+ };
40
+ DashboardItemInterpretations.propTypes = {
41
+ currentUser: PropTypes.object.isRequired,
42
+ dashboardRedirectUrl: PropTypes.string.isRequired,
43
+ id: PropTypes.string.isRequired,
44
+ type: PropTypes.string.isRequired
45
+ };
@@ -0,0 +1 @@
1
+ export { DashboardItemInterpretations } from './DashboardItemInterpretations.js';
@@ -1,28 +1,28 @@
1
1
  import i18n from '@dhis2/d2-i18n';
2
2
  import { IconEdit16 } from '@dhis2/ui';
3
3
  import PropTypes from 'prop-types';
4
- import React, { useState } from 'react';
5
- import { Message, MessageIconButton, MessageStatsBar, getCommentAccess } from '../common/index.js';
4
+ import React, { useCallback, useState } from 'react';
5
+ import { Message, MessageIconButton, MessageStatsBar } from '../common/index.js';
6
+ import { useCommentAccess } from '../InterpretationsProvider/hooks.js';
6
7
  import { CommentDeleteButton } from './CommentDeleteButton.js';
7
8
  import { CommentUpdateForm } from './CommentUpdateForm.js';
8
9
  const Comment = ({
9
10
  comment,
10
- currentUser,
11
- interpretationId,
12
- onThreadUpdated,
13
11
  canComment
14
12
  }) => {
15
13
  const [isUpdateMode, setIsUpdateMode] = useState(false);
16
- const commentAccess = getCommentAccess(comment, canComment, currentUser);
14
+ const [commentText, setCommentText] = useState(comment.text);
15
+ const onUpdateComplete = useCallback(newText => {
16
+ setCommentText(newText);
17
+ setIsUpdateMode(false);
18
+ }, []);
19
+ const commentAccess = useCommentAccess(comment, canComment);
17
20
  return isUpdateMode ? /*#__PURE__*/React.createElement(CommentUpdateForm, {
18
- close: () => setIsUpdateMode(false),
19
- commentId: comment.id,
20
- interpretationId: interpretationId,
21
- onComplete: () => onThreadUpdated(false),
22
- text: comment.text,
23
- currentUser: currentUser
21
+ onComplete: onUpdateComplete,
22
+ id: comment.id,
23
+ text: comment.text
24
24
  }) : /*#__PURE__*/React.createElement(Message, {
25
- text: comment.text,
25
+ text: commentText,
26
26
  created: comment.created,
27
27
  username: comment.createdBy.displayName
28
28
  }, commentAccess.edit && /*#__PURE__*/React.createElement(MessageStatsBar, null, /*#__PURE__*/React.createElement(MessageIconButton, {
@@ -30,16 +30,11 @@ const Comment = ({
30
30
  tooltipContent: i18n.t('Edit'),
31
31
  onClick: () => setIsUpdateMode(true)
32
32
  }), commentAccess.delete && /*#__PURE__*/React.createElement(CommentDeleteButton, {
33
- commentId: comment.id,
34
- interpretationId: interpretationId,
35
- onComplete: () => onThreadUpdated(true)
33
+ id: comment.id
36
34
  })));
37
35
  };
38
36
  Comment.propTypes = {
39
37
  comment: PropTypes.object.isRequired,
40
- currentUser: PropTypes.object.isRequired,
41
- interpretationId: PropTypes.string.isRequired,
42
- onThreadUpdated: PropTypes.func.isRequired,
43
38
  canComment: PropTypes.bool
44
39
  };
45
40
  export { Comment };
@@ -1,58 +1,47 @@
1
- import { useDataMutation } from '@dhis2/app-runtime';
2
1
  import i18n from '@dhis2/d2-i18n';
3
2
  import { Button } from '@dhis2/ui';
4
3
  import PropTypes from 'prop-types';
5
- import React, { useRef, useState } from 'react';
4
+ import React, { useCallback, useState } from 'react';
6
5
  import { RichTextEditor } from '../../RichText/index.js';
7
6
  import { MessageEditorContainer, MessageButtonStrip, MessageInput } from '../common/index.js';
7
+ import { useAddCommentToActiveInterpretation, useInterpretationsCurrentUser } from '../InterpretationsProvider/hooks.js';
8
8
  export const CommentAddForm = ({
9
- interpretationId,
10
- currentUser,
11
- onSave,
12
9
  focusRef
13
10
  }) => {
11
+ const currentUser = useInterpretationsCurrentUser();
14
12
  const [showRichTextEditor, setShowRichTextEditor] = useState(false);
15
- const [commentText, setCommentText] = useState('');
16
- const saveMutationRef = useRef({
17
- resource: `interpretations/${interpretationId}/comments`,
18
- type: 'create',
19
- data: ({
20
- commentText
21
- }) => commentText
22
- });
13
+ const [text, setText] = useState('');
14
+ const closeForm = useCallback(() => {
15
+ setShowRichTextEditor(false);
16
+ setText('');
17
+ }, []);
23
18
  const [save, {
24
- loading
25
- }] = useDataMutation(saveMutationRef.current, {
26
- onComplete: () => {
27
- setShowRichTextEditor(false);
28
- setCommentText('');
29
- onSave();
30
- }
19
+ loading,
20
+ error
21
+ }] = useAddCommentToActiveInterpretation({
22
+ text,
23
+ onComplete: closeForm
31
24
  });
32
25
  const inputPlaceholder = i18n.t('Write a reply');
33
26
  return /*#__PURE__*/React.createElement(MessageEditorContainer, {
34
- currentUser: currentUser
27
+ currentUserName: currentUser.name
35
28
  }, showRichTextEditor ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(RichTextEditor, {
36
29
  inputPlaceholder: inputPlaceholder,
37
- onChange: setCommentText,
38
- value: commentText,
30
+ onChange: setText,
31
+ value: text,
39
32
  ref: focusRef,
40
- disabled: loading
33
+ disabled: loading,
34
+ errorText: error ? i18n.t('Could not post reply') : ''
41
35
  }), /*#__PURE__*/React.createElement(MessageButtonStrip, null, /*#__PURE__*/React.createElement(Button, {
42
36
  primary: true,
43
37
  small: true,
44
- onClick: () => save({
45
- commentText
46
- }),
38
+ onClick: save,
47
39
  loading: loading
48
40
  }, i18n.t('Post reply')), /*#__PURE__*/React.createElement(Button, {
49
41
  secondary: true,
50
42
  small: true,
51
43
  disabled: loading,
52
- onClick: () => {
53
- setCommentText('');
54
- setShowRichTextEditor(false);
55
- }
44
+ onClick: closeForm
56
45
  }, i18n.t('Cancel')))) : /*#__PURE__*/React.createElement(MessageInput, {
57
46
  onFocus: () => setShowRichTextEditor(true),
58
47
  placeholder: inputPlaceholder,
@@ -60,8 +49,5 @@ export const CommentAddForm = ({
60
49
  }));
61
50
  };
62
51
  CommentAddForm.propTypes = {
63
- currentUser: PropTypes.object.isRequired,
64
- focusRef: PropTypes.object.isRequired,
65
- interpretationId: PropTypes.string.isRequired,
66
- onSave: PropTypes.func
52
+ focusRef: PropTypes.object.isRequired
67
53
  };
@@ -1,58 +1,34 @@
1
1
  import _JSXStyle from "styled-jsx/style";
2
- import { useDataMutation } from '@dhis2/app-runtime';
3
2
  import i18n from '@dhis2/d2-i18n';
4
3
  import { IconDelete16, colors } from '@dhis2/ui';
5
4
  import PropTypes from 'prop-types';
6
- import React, { useState } from 'react';
5
+ import React from 'react';
7
6
  import { MessageIconButton } from '../common/index.js';
8
- const mutation = {
9
- resource: 'interpretations',
10
- id: ({
11
- interpretationId,
12
- commentId
13
- }) => `${interpretationId}/comments/${commentId}`,
14
- type: 'delete'
15
- };
7
+ import { useDeleteCommentFromActiveInterpretation } from '../InterpretationsProvider/hooks.js';
16
8
  const CommentDeleteButton = ({
17
- commentId,
18
- interpretationId,
19
- onComplete
9
+ id
20
10
  }) => {
21
- const [deleteError, setDeleteError] = useState(null);
22
11
  const [remove, {
23
- loading
24
- }] = useDataMutation(mutation, {
25
- onComplete: () => {
26
- setDeleteError(null);
27
- onComplete();
28
- },
29
- onError: () => setDeleteError(i18n.t('Delete failed')),
30
- variables: {
31
- commentId,
32
- interpretationId
33
- }
12
+ loading,
13
+ error
14
+ }] = useDeleteCommentFromActiveInterpretation({
15
+ id
34
16
  });
35
- const onDelete = () => {
36
- setDeleteError(null);
37
- remove();
38
- };
39
17
  return /*#__PURE__*/React.createElement("div", {
40
18
  className: _JSXStyle.dynamic([["945681082", [colors.red500]]]) + " " + "delete-button-container"
41
19
  }, /*#__PURE__*/React.createElement(MessageIconButton, {
42
20
  tooltipContent: i18n.t('Delete'),
43
21
  iconComponent: IconDelete16,
44
- onClick: onDelete,
22
+ onClick: remove,
45
23
  disabled: loading
46
- }), deleteError && /*#__PURE__*/React.createElement("span", {
24
+ }), error && /*#__PURE__*/React.createElement("span", {
47
25
  className: _JSXStyle.dynamic([["945681082", [colors.red500]]]) + " " + "delete-error"
48
- }, deleteError), /*#__PURE__*/React.createElement(_JSXStyle, {
26
+ }, i18n.t('Could not delete comment')), /*#__PURE__*/React.createElement(_JSXStyle, {
49
27
  id: "945681082",
50
28
  dynamic: [colors.red500]
51
29
  }, [".delete-button-container.__jsx-style-dynamic-selector{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:4px;}", `.delete-error.__jsx-style-dynamic-selector{color:${colors.red500};font-size:12px;line-height:12px;}`]));
52
30
  };
53
31
  CommentDeleteButton.propTypes = {
54
- commentId: PropTypes.string.isRequired,
55
- interpretationId: PropTypes.string.isRequired,
56
- onComplete: PropTypes.func.isRequired
32
+ id: PropTypes.string.isRequired
57
33
  };
58
34
  export { CommentDeleteButton };
@@ -1,42 +1,31 @@
1
1
  import _JSXStyle from "styled-jsx/style";
2
- import { useDataMutation } from '@dhis2/app-runtime';
3
2
  import i18n from '@dhis2/d2-i18n';
4
3
  import { Button, spacers, colors } from '@dhis2/ui';
5
4
  import PropTypes from 'prop-types';
6
- import React, { useState, useRef } from 'react';
5
+ import React, { useState } from 'react';
7
6
  import { RichTextEditor } from '../../RichText/index.js';
8
7
  import { MessageEditorContainer, MessageButtonStrip } from '../common/index.js';
8
+ import { useInterpretationsCurrentUser, useUpdateCommentForActiveInterpretation } from '../InterpretationsProvider/hooks.js';
9
9
  export const CommentUpdateForm = ({
10
- interpretationId,
11
- commentId,
12
- currentUser,
10
+ id,
13
11
  text,
14
- close,
15
12
  onComplete
16
13
  }) => {
14
+ const currentUser = useInterpretationsCurrentUser();
17
15
  const [commentText, setCommentText] = useState(text || '');
18
- const updateMutationRef = useRef({
19
- resource: `interpretations/${interpretationId}/comments/${commentId}`,
20
- type: 'update',
21
- partial: false,
22
- data: ({
23
- commentText
24
- }) => commentText
25
- });
26
16
  const [update, {
27
17
  loading,
28
18
  error
29
- }] = useDataMutation(updateMutationRef.current, {
30
- onComplete: () => {
31
- onComplete();
32
- close();
33
- }
19
+ }] = useUpdateCommentForActiveInterpretation({
20
+ id,
21
+ text: commentText,
22
+ onComplete
34
23
  });
35
24
  const errorText = error ? i18n.t('Could not update comment') : '';
36
25
  return /*#__PURE__*/React.createElement("div", {
37
26
  className: _JSXStyle.dynamic([["2690082310", [spacers.dp8, spacers.dp8, colors.grey100]]]) + " " + "message"
38
27
  }, /*#__PURE__*/React.createElement(MessageEditorContainer, {
39
- currentUser: currentUser
28
+ currentUserName: currentUser.name
40
29
  }, /*#__PURE__*/React.createElement(RichTextEditor, {
41
30
  inputPlaceholder: i18n.t('Enter comment text'),
42
31
  onChange: setCommentText,
@@ -47,24 +36,19 @@ export const CommentUpdateForm = ({
47
36
  loading: loading,
48
37
  primary: true,
49
38
  small: true,
50
- onClick: () => update({
51
- commentText
52
- })
39
+ onClick: update
53
40
  }, i18n.t('Update')), /*#__PURE__*/React.createElement(Button, {
54
41
  disabled: loading,
55
42
  secondary: true,
56
43
  small: true,
57
- onClick: close
44
+ onClick: onComplete
58
45
  }, i18n.t('Cancel')))), /*#__PURE__*/React.createElement(_JSXStyle, {
59
46
  id: "2690082310",
60
47
  dynamic: [spacers.dp8, spacers.dp8, colors.grey100]
61
48
  }, [`.message.__jsx-style-dynamic-selector{padding:0 ${spacers.dp8} ${spacers.dp8};background-color:${colors.grey100};border-radius:5px;}`]));
62
49
  };
63
50
  CommentUpdateForm.propTypes = {
64
- close: PropTypes.func.isRequired,
65
- commentId: PropTypes.string.isRequired,
66
- currentUser: PropTypes.object.isRequired,
67
- interpretationId: PropTypes.string.isRequired,
51
+ id: PropTypes.string.isRequired,
68
52
  onComplete: PropTypes.func.isRequired,
69
53
  text: PropTypes.string
70
54
  };