@dhis2/analytics 23.11.1 → 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 (74) hide show
  1. package/CHANGELOG.md +7 -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/index.js +16 -0
  37. package/build/cjs/locales/en/translations.json +32 -1
  38. package/build/es/components/Interpretations/InterpretationModal/Comment.js +45 -0
  39. package/build/es/components/Interpretations/InterpretationModal/CommentAddForm.js +70 -0
  40. package/build/es/components/Interpretations/InterpretationModal/CommentDeleteButton.js +47 -0
  41. package/build/es/components/Interpretations/InterpretationModal/CommentUpdateForm.js +73 -0
  42. package/build/es/components/Interpretations/InterpretationModal/InterpretationModal.js +165 -0
  43. package/build/es/components/Interpretations/InterpretationModal/InterpretationThread.js +79 -0
  44. package/build/es/components/Interpretations/InterpretationModal/index.js +1 -0
  45. package/build/es/components/Interpretations/InterpretationModal/useModalContentWidth.js +28 -0
  46. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationForm.js +71 -0
  47. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationList.js +78 -0
  48. package/build/es/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +112 -0
  49. package/build/es/components/Interpretations/InterpretationsUnit/index.js +1 -0
  50. package/build/es/components/Interpretations/common/Interpretation/Interpretation.js +87 -0
  51. package/build/es/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js +43 -0
  52. package/build/es/components/Interpretations/common/Interpretation/InterpretationSharingLink.js +33 -0
  53. package/build/es/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js +85 -0
  54. package/build/es/components/Interpretations/common/Interpretation/index.js +2 -0
  55. package/build/es/components/Interpretations/common/Interpretation/useLike.js +45 -0
  56. package/build/es/components/Interpretations/common/Message/Message.js +41 -0
  57. package/build/es/components/Interpretations/common/Message/MessageButtonStrip.js +21 -0
  58. package/build/es/components/Interpretations/common/Message/MessageEditorContainer.js +30 -0
  59. package/build/es/components/Interpretations/common/Message/MessageIconButton.js +54 -0
  60. package/build/es/components/Interpretations/common/Message/MessageInput.js +16 -0
  61. package/build/es/components/Interpretations/common/Message/MessageStatsBar.js +21 -0
  62. package/build/es/components/Interpretations/common/Message/index.js +6 -0
  63. package/build/es/components/Interpretations/common/RichTextEditor/RichTextEditor.js +240 -0
  64. package/build/es/components/Interpretations/common/RichTextEditor/index.js +1 -0
  65. package/build/es/components/Interpretations/common/RichTextEditor/markdownHandler.js +128 -0
  66. package/build/es/components/Interpretations/common/RichTextEditor/styles/RichTextEditor.style.js +9 -0
  67. package/build/es/components/Interpretations/common/UserMention/UserList.js +33 -0
  68. package/build/es/components/Interpretations/common/UserMention/UserMentionWrapper.js +202 -0
  69. package/build/es/components/Interpretations/common/UserMention/styles/UserMentionWrapper.style.js +17 -0
  70. package/build/es/components/Interpretations/common/UserMention/useUserSearchResults.js +63 -0
  71. package/build/es/components/Interpretations/common/index.js +3 -0
  72. package/build/es/index.js +2 -0
  73. package/build/es/locales/en/translations.json +32 -1
  74. package/package.json +2 -1
@@ -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';
@@ -0,0 +1,87 @@
1
+ import i18n from '@dhis2/d2-i18n';
2
+ import { Button, SharingDialog, IconReply16, IconShare16, IconThumbUp16, IconEdit16 } from '@dhis2/ui';
3
+ import PropTypes from 'prop-types';
4
+ import React, { useState } from 'react';
5
+ import { Message, MessageStatsBar, MessageIconButton } from '../index.js';
6
+ import { InterpretationDeleteButton } from './InterpretationDeleteButton.js';
7
+ import { InterpretationUpdateForm } from './InterpretationUpdateForm.js';
8
+ import { useLike } from './useLike.js';
9
+ export const Interpretation = _ref => {
10
+ let {
11
+ interpretation,
12
+ currentUser,
13
+ onClick,
14
+ onUpdated,
15
+ onDeleted,
16
+ disabled,
17
+ onReplyIconClick
18
+ } = _ref;
19
+ const [isUpdateMode, setIsUpdateMode] = useState(false);
20
+ const [showSharingDialog, setShowSharingDialog] = useState(false);
21
+ const {
22
+ toggleLike,
23
+ isLikedByCurrentUser,
24
+ toggleLikeInProgress
25
+ } = useLike({
26
+ interpretation,
27
+ currentUser,
28
+ onComplete: onUpdated
29
+ });
30
+ const shouldShowButton = !!onClick && !disabled;
31
+ return isUpdateMode ? /*#__PURE__*/React.createElement(InterpretationUpdateForm, {
32
+ close: () => setIsUpdateMode(false),
33
+ id: interpretation.id,
34
+ showSharingLink: interpretation.access.manage,
35
+ onComplete: onUpdated,
36
+ text: interpretation.text,
37
+ currentUser: currentUser
38
+ }) : /*#__PURE__*/React.createElement(Message, {
39
+ text: interpretation.text,
40
+ created: interpretation.created,
41
+ username: interpretation.user.displayName
42
+ }, !disabled && /*#__PURE__*/React.createElement(MessageStatsBar, null, /*#__PURE__*/React.createElement(MessageIconButton, {
43
+ tooltipContent: isLikedByCurrentUser ? i18n.t('Unlike') : i18n.t('Like'),
44
+ iconComponent: IconThumbUp16,
45
+ onClick: toggleLike,
46
+ selected: isLikedByCurrentUser,
47
+ count: interpretation.likes,
48
+ disabled: toggleLikeInProgress
49
+ }), /*#__PURE__*/React.createElement(MessageIconButton, {
50
+ tooltipContent: i18n.t('Reply'),
51
+ iconComponent: IconReply16,
52
+ onClick: () => onReplyIconClick(interpretation.id),
53
+ count: interpretation.comments.length
54
+ }), interpretation.access.manage && /*#__PURE__*/React.createElement(MessageIconButton, {
55
+ iconComponent: IconShare16,
56
+ tooltipContent: i18n.t('Share'),
57
+ onClick: () => setShowSharingDialog(true)
58
+ }), showSharingDialog && /*#__PURE__*/React.createElement(SharingDialog, {
59
+ open: true,
60
+ type: 'interpretation',
61
+ id: interpretation.id,
62
+ onClose: () => setShowSharingDialog(false)
63
+ }), interpretation.access.update && /*#__PURE__*/React.createElement(MessageIconButton, {
64
+ iconComponent: IconEdit16,
65
+ tooltipContent: i18n.t('Edit'),
66
+ onClick: () => setIsUpdateMode(true)
67
+ }), interpretation.access.delete && /*#__PURE__*/React.createElement(InterpretationDeleteButton, {
68
+ id: interpretation.id,
69
+ onComplete: onDeleted
70
+ })), shouldShowButton && /*#__PURE__*/React.createElement(Button, {
71
+ secondary: true,
72
+ small: true,
73
+ onClick: (_, event) => {
74
+ event.stopPropagation();
75
+ onClick(interpretation.id);
76
+ }
77
+ }, i18n.t('See interpretation')));
78
+ };
79
+ Interpretation.propTypes = {
80
+ currentUser: PropTypes.object.isRequired,
81
+ interpretation: PropTypes.object.isRequired,
82
+ onDeleted: PropTypes.func.isRequired,
83
+ onReplyIconClick: PropTypes.func.isRequired,
84
+ onUpdated: PropTypes.func.isRequired,
85
+ disabled: PropTypes.bool,
86
+ onClick: PropTypes.func
87
+ };
@@ -0,0 +1,43 @@
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 '../index.js';
7
+ const mutation = {
8
+ resource: 'interpretations',
9
+ id: _ref => {
10
+ let {
11
+ id
12
+ } = _ref;
13
+ return id;
14
+ },
15
+ type: 'delete'
16
+ };
17
+
18
+ const InterpretationDeleteButton = _ref2 => {
19
+ let {
20
+ id,
21
+ onComplete
22
+ } = _ref2;
23
+ const [remove, {
24
+ loading
25
+ }] = useDataMutation(mutation, {
26
+ onComplete,
27
+ variables: {
28
+ id
29
+ }
30
+ });
31
+ return /*#__PURE__*/React.createElement(MessageIconButton, {
32
+ tooltipContent: i18n.t('Delete'),
33
+ iconComponent: IconDelete16,
34
+ onClick: remove,
35
+ disabled: loading
36
+ });
37
+ };
38
+
39
+ InterpretationDeleteButton.propTypes = {
40
+ id: PropTypes.string.isRequired,
41
+ onComplete: PropTypes.func.isRequired
42
+ };
43
+ export { InterpretationDeleteButton };
@@ -0,0 +1,33 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import i18n from '@dhis2/d2-i18n';
3
+ import { SharingDialog, colors, spacers } from '@dhis2/ui';
4
+ import PropTypes from 'prop-types';
5
+ import React, { useState } from 'react';
6
+
7
+ const InterpretationSharingLink = _ref => {
8
+ let {
9
+ type,
10
+ id
11
+ } = _ref;
12
+ const [showSharingDialog, setShowSharingDialog] = useState(false);
13
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
14
+ className: _JSXStyle.dynamic([["3990725326", [spacers.dp4, spacers.dp8, colors.grey800]]]) + " " + "container"
15
+ }, /*#__PURE__*/React.createElement("span", {
16
+ onClick: () => setShowSharingDialog(true),
17
+ className: _JSXStyle.dynamic([["3990725326", [spacers.dp4, spacers.dp8, colors.grey800]]]) + " " + "link"
18
+ }, i18n.t('Manage sharing'))), showSharingDialog && /*#__PURE__*/React.createElement(SharingDialog, {
19
+ open: true,
20
+ type: type,
21
+ id: id,
22
+ onClose: () => setShowSharingDialog(false)
23
+ }), /*#__PURE__*/React.createElement(_JSXStyle, {
24
+ id: "3990725326",
25
+ dynamic: [spacers.dp4, spacers.dp8, colors.grey800]
26
+ }, [".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;-webkit-box-pack:end;-webkit-justify-content:flex-end;-ms-flex-pack:end;justify-content:flex-end;gap:".concat(spacers.dp4, ";margin-top:").concat(spacers.dp8, ";font-size:13px;color:").concat(colors.grey800, ";cursor:pointer;}"), ".link.__jsx-style-dynamic-selector{-webkit-text-decoration:underline;text-decoration:underline;}"]));
27
+ };
28
+
29
+ InterpretationSharingLink.propTypes = {
30
+ id: PropTypes.string,
31
+ type: PropTypes.string
32
+ };
33
+ export { InterpretationSharingLink };
@@ -0,0 +1,85 @@
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 } from 'react';
7
+ import { MessageEditorContainer, RichTextEditor, MessageButtonStrip, InterpretationSharingLink } from '../index.js';
8
+ const mutation = {
9
+ resource: 'interpretations',
10
+ type: 'update',
11
+ partial: false,
12
+ id: _ref => {
13
+ let {
14
+ id
15
+ } = _ref;
16
+ return id;
17
+ },
18
+ data: _ref2 => {
19
+ let {
20
+ interpretationText
21
+ } = _ref2;
22
+ return interpretationText;
23
+ }
24
+ };
25
+ export const InterpretationUpdateForm = _ref3 => {
26
+ let {
27
+ close,
28
+ currentUser,
29
+ id,
30
+ onComplete,
31
+ showSharingLink,
32
+ text
33
+ } = _ref3;
34
+ const [interpretationText, setInterpretationText] = useState(text || '');
35
+ const [update, {
36
+ loading,
37
+ error
38
+ }] = useDataMutation(mutation, {
39
+ onComplete: () => {
40
+ onComplete();
41
+ close();
42
+ },
43
+ variables: {
44
+ id
45
+ }
46
+ });
47
+ const errorText = error ? error.message || i18n.t('Could not update interpretation') : '';
48
+ return /*#__PURE__*/React.createElement("div", {
49
+ className: _JSXStyle.dynamic([["2690082310", [spacers.dp8, spacers.dp8, colors.grey100]]]) + " " + "message"
50
+ }, /*#__PURE__*/React.createElement(MessageEditorContainer, {
51
+ currentUser: currentUser
52
+ }, /*#__PURE__*/React.createElement(RichTextEditor, {
53
+ inputPlaceholder: i18n.t('Enter interpretation text'),
54
+ onChange: setInterpretationText,
55
+ value: interpretationText,
56
+ disabled: loading,
57
+ errorText: errorText
58
+ }), showSharingLink && /*#__PURE__*/React.createElement(InterpretationSharingLink, {
59
+ id: id,
60
+ type: "interpretation"
61
+ }), /*#__PURE__*/React.createElement(MessageButtonStrip, null, /*#__PURE__*/React.createElement(Button, {
62
+ loading: loading,
63
+ primary: true,
64
+ small: true,
65
+ onClick: () => update({
66
+ interpretationText
67
+ })
68
+ }, i18n.t('Update')), /*#__PURE__*/React.createElement(Button, {
69
+ disabled: loading,
70
+ secondary: true,
71
+ small: true,
72
+ onClick: close
73
+ }, i18n.t('Cancel')))), /*#__PURE__*/React.createElement(_JSXStyle, {
74
+ id: "2690082310",
75
+ dynamic: [spacers.dp8, spacers.dp8, colors.grey100]
76
+ }, [".message.__jsx-style-dynamic-selector{padding:0 ".concat(spacers.dp8, " ").concat(spacers.dp8, ";background-color:").concat(colors.grey100, ";border-radius:5px;}")]));
77
+ };
78
+ InterpretationUpdateForm.propTypes = {
79
+ close: PropTypes.func.isRequired,
80
+ currentUser: PropTypes.object.isRequired,
81
+ id: PropTypes.string.isRequired,
82
+ onComplete: PropTypes.func.isRequired,
83
+ showSharingLink: PropTypes.bool,
84
+ text: PropTypes.string
85
+ };
@@ -0,0 +1,2 @@
1
+ export { Interpretation } from './Interpretation.js';
2
+ export { InterpretationSharingLink } from './InterpretationSharingLink.js';
@@ -0,0 +1,45 @@
1
+ import { useDataMutation } from '@dhis2/app-runtime';
2
+ import { useEffect, useRef, useState } from 'react';
3
+
4
+ const useLike = _ref => {
5
+ let {
6
+ interpretation,
7
+ currentUser,
8
+ onComplete
9
+ } = _ref;
10
+ const resource = "interpretations/".concat(interpretation.id, "/like");
11
+ const likeMutationRef = useRef({
12
+ resource,
13
+ type: 'create'
14
+ });
15
+ const unlikeMutationRef = useRef({
16
+ resource,
17
+ type: 'delete'
18
+ });
19
+ const [like, {
20
+ loading: likeLoading
21
+ }] = useDataMutation(likeMutationRef.current, {
22
+ onComplete
23
+ });
24
+ const [unlike, {
25
+ loading: unlikeLoading
26
+ }] = useDataMutation(unlikeMutationRef.current, {
27
+ onComplete
28
+ });
29
+ const [isLikedByCurrentUser, setIsLikedByCurrentUser] = useState(false);
30
+
31
+ const toggleLike = () => {
32
+ isLikedByCurrentUser ? unlike() : like();
33
+ };
34
+
35
+ useEffect(() => {
36
+ setIsLikedByCurrentUser(interpretation.likedBy.some(likedBy => likedBy.id === currentUser.id));
37
+ }, [currentUser, interpretation]);
38
+ return {
39
+ isLikedByCurrentUser,
40
+ toggleLike,
41
+ toggleLikeInProgress: likeLoading || unlikeLoading
42
+ };
43
+ };
44
+
45
+ export { useLike };
@@ -0,0 +1,41 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { Parser as RichTextParser } from '@dhis2/d2-ui-rich-text';
3
+ import { UserAvatar, spacers, colors } from '@dhis2/ui';
4
+ import moment from 'moment';
5
+ import PropTypes from 'prop-types';
6
+ import React from 'react';
7
+
8
+ const Message = _ref => {
9
+ let {
10
+ children,
11
+ text,
12
+ created,
13
+ username
14
+ } = _ref;
15
+ return /*#__PURE__*/React.createElement("li", {
16
+ className: _JSXStyle.dynamic([["2436588813", [spacers.dp8, colors.grey100, spacers.dp8, colors.grey900, colors.grey600, colors.grey900, spacers.dp8]]]) + " " + "container"
17
+ }, /*#__PURE__*/React.createElement("div", {
18
+ className: _JSXStyle.dynamic([["2436588813", [spacers.dp8, colors.grey100, spacers.dp8, colors.grey900, colors.grey600, colors.grey900, spacers.dp8]]]) + " " + "header"
19
+ }, /*#__PURE__*/React.createElement(UserAvatar, {
20
+ name: username,
21
+ extrasmall: true
22
+ }), username, /*#__PURE__*/React.createElement("time", {
23
+ dateTime: created,
24
+ className: _JSXStyle.dynamic([["2436588813", [spacers.dp8, colors.grey100, spacers.dp8, colors.grey900, colors.grey600, colors.grey900, spacers.dp8]]])
25
+ }, moment(created).format('lll'))), /*#__PURE__*/React.createElement("div", {
26
+ className: _JSXStyle.dynamic([["2436588813", [spacers.dp8, colors.grey100, spacers.dp8, colors.grey900, colors.grey600, colors.grey900, spacers.dp8]]]) + " " + "content"
27
+ }, /*#__PURE__*/React.createElement(RichTextParser, null, text)), /*#__PURE__*/React.createElement("div", {
28
+ className: _JSXStyle.dynamic([["2436588813", [spacers.dp8, colors.grey100, spacers.dp8, colors.grey900, colors.grey600, colors.grey900, spacers.dp8]]]) + " " + "footer"
29
+ }, children), /*#__PURE__*/React.createElement(_JSXStyle, {
30
+ id: "2436588813",
31
+ dynamic: [spacers.dp8, colors.grey100, spacers.dp8, colors.grey900, colors.grey600, colors.grey900, spacers.dp8]
32
+ }, [".container.__jsx-style-dynamic-selector{padding:".concat(spacers.dp8, ";background-color:").concat(colors.grey100, ";border-radius:5px;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.dp8, ";}"), ".header.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:6px;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;font-size:13px;line-height:16px;color:".concat(colors.grey900, ";}"), ".header.__jsx-style-dynamic-selector time.__jsx-style-dynamic-selector{font-size:12px;color:".concat(colors.grey600, ";}"), ".content.__jsx-style-dynamic-selector{font-size:14px;line-height:19px;color:".concat(colors.grey900, ";}"), ".content.__jsx-style-dynamic-selector p:first-child{margin:0;}", ".footer.__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;-webkit-align-items:flex-start;-webkit-box-align:flex-start;-ms-flex-align:flex-start;align-items:flex-start;gap:".concat(spacers.dp8, ";}")]));
33
+ };
34
+
35
+ Message.propTypes = {
36
+ children: PropTypes.node.isRequired,
37
+ created: PropTypes.string.isRequired,
38
+ text: PropTypes.string.isRequired,
39
+ username: PropTypes.string.isRequired
40
+ };
41
+ export { Message };
@@ -0,0 +1,21 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { spacers } from '@dhis2/ui';
3
+ import PropTypes from 'prop-types';
4
+ import React from 'react';
5
+
6
+ const MessageButtonStrip = _ref => {
7
+ let {
8
+ children
9
+ } = _ref;
10
+ return /*#__PURE__*/React.createElement("div", {
11
+ className: _JSXStyle.dynamic([["1819118406", [spacers.dp8, spacers.dp8]]]) + " " + "container"
12
+ }, children, /*#__PURE__*/React.createElement(_JSXStyle, {
13
+ id: "1819118406",
14
+ dynamic: [spacers.dp8, spacers.dp8]
15
+ }, [".container.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:".concat(spacers.dp8, ";margin-top:").concat(spacers.dp8, ";}")]));
16
+ };
17
+
18
+ MessageButtonStrip.propTypes = {
19
+ children: PropTypes.node.isRequired
20
+ };
21
+ export { MessageButtonStrip };
@@ -0,0 +1,30 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { UserAvatar, spacers } from '@dhis2/ui';
3
+ import PropTypes from 'prop-types';
4
+ import React from 'react';
5
+
6
+ const MessageEditorContainer = _ref => {
7
+ let {
8
+ children,
9
+ currentUser
10
+ } = _ref;
11
+ return /*#__PURE__*/React.createElement("div", {
12
+ className: _JSXStyle.dynamic([["3807884305", [spacers.dp8, spacers.dp12]]]) + " " + "container"
13
+ }, /*#__PURE__*/React.createElement("div", {
14
+ className: _JSXStyle.dynamic([["3807884305", [spacers.dp8, spacers.dp12]]]) + " " + "avatar"
15
+ }, /*#__PURE__*/React.createElement(UserAvatar, {
16
+ name: currentUser.name,
17
+ medium: true
18
+ })), /*#__PURE__*/React.createElement("div", {
19
+ className: _JSXStyle.dynamic([["3807884305", [spacers.dp8, spacers.dp12]]]) + " " + "editor"
20
+ }, children), /*#__PURE__*/React.createElement(_JSXStyle, {
21
+ id: "3807884305",
22
+ dynamic: [spacers.dp8, spacers.dp12]
23
+ }, [".container.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:".concat(spacers.dp8, ";margin-top:").concat(spacers.dp12, ";}"), ".avatar.__jsx-style-dynamic-selector{-webkit-box-flex:0;-webkit-flex-grow:0;-ms-flex-positive:0;flex-grow:0;}", ".editor.__jsx-style-dynamic-selector{-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;}"]));
24
+ };
25
+
26
+ MessageEditorContainer.propTypes = {
27
+ currentUser: PropTypes.object.isRequired,
28
+ children: PropTypes.node
29
+ };
30
+ export { MessageEditorContainer };
@@ -0,0 +1,54 @@
1
+ import _JSXStyle from "styled-jsx/style";
2
+ import { Tooltip, colors, spacers } from '@dhis2/ui';
3
+ import cx from 'classnames';
4
+ import PropTypes from 'prop-types';
5
+ import React from 'react';
6
+
7
+ const MessageIconButton = _ref => {
8
+ let {
9
+ tooltipContent,
10
+ disabled,
11
+ onClick,
12
+ selected,
13
+ count,
14
+ iconComponent: Icon
15
+ } = _ref;
16
+ return /*#__PURE__*/React.createElement(Tooltip, {
17
+ closeDelay: 200,
18
+ content: tooltipContent
19
+ }, _ref2 => {
20
+ let {
21
+ ref,
22
+ onMouseOver,
23
+ onMouseOut
24
+ } = _ref2;
25
+ return /*#__PURE__*/React.createElement("span", {
26
+ ref: ref,
27
+ onMouseOver: onMouseOver,
28
+ onMouseOut: onMouseOut,
29
+ className: _JSXStyle.dynamic([["3807261824", [spacers.dp4, colors.grey700, colors.teal600, colors.grey900, colors.teal800, colors.teal500, colors.teal700]]]) + " " + "wrapper"
30
+ }, /*#__PURE__*/React.createElement("button", {
31
+ onClick: event => {
32
+ event.stopPropagation();
33
+ onClick();
34
+ },
35
+ disabled: disabled,
36
+ className: _JSXStyle.dynamic([["3807261824", [spacers.dp4, colors.grey700, colors.teal600, colors.grey900, colors.teal800, colors.teal500, colors.teal700]]]) + " " + (cx('button', {
37
+ selected
38
+ }) || "")
39
+ }, count && count, /*#__PURE__*/React.createElement(Icon, null)), /*#__PURE__*/React.createElement(_JSXStyle, {
40
+ id: "3807261824",
41
+ dynamic: [spacers.dp4, colors.grey700, colors.teal600, colors.grey900, colors.teal800, colors.teal500, colors.teal700]
42
+ }, [".wrapper.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;}", ".button.__jsx-style-dynamic-selector{all:unset;cursor:pointer;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;gap:".concat(spacers.dp4, ";-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;font-size:12px;line-height:14px;color:").concat(colors.grey700, ";}"), ".button.selected.__jsx-style-dynamic-selector{color:".concat(colors.teal600, ";font-weight:500;}"), ".button.__jsx-style-dynamic-selector:hover{color:".concat(colors.grey900, ";}"), ".button.selected.__jsx-style-dynamic-selector:hover{color:".concat(colors.teal800, ";}"), ".button.selected.__jsx-style-dynamic-selector svg{color:".concat(colors.teal500, ";}"), ".button.selected.__jsx-style-dynamic-selector:hover svg{color:".concat(colors.teal700, ";}")]));
43
+ });
44
+ };
45
+
46
+ MessageIconButton.propTypes = {
47
+ iconComponent: PropTypes.oneOfType([PropTypes.object, PropTypes.func]).isRequired,
48
+ tooltipContent: PropTypes.string.isRequired,
49
+ count: PropTypes.number,
50
+ disabled: PropTypes.bool,
51
+ selected: PropTypes.bool,
52
+ onClick: PropTypes.func
53
+ };
54
+ export { MessageIconButton };