@dhis2/analytics 26.1.0 → 26.1.2
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.
- package/build/cjs/__demo__/InterpretationsUnit.stories.js +41 -0
- package/build/cjs/components/AboutAOUnit/AboutAOUnit.js +6 -3
- package/build/cjs/components/Interpretations/InterpretationModal/InterpretationModal.js +15 -15
- package/build/cjs/components/Interpretations/InterpretationModal/InterpretationThread.js +14 -12
- package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationForm.js +4 -1
- package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationList.js +5 -1
- package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +7 -2
- package/build/cjs/components/Interpretations/common/Message/Message.js +12 -8
- package/build/cjs/components/Interpretations/common/RichTextEditor/RichTextEditor.js +5 -2
- package/build/cjs/components/Interpretations/common/__tests__/getInterpretationAccess.spec.js +172 -3
- package/build/cjs/components/Interpretations/common/getInterpretationAccess.js +15 -3
- package/build/cjs/locales/en/translations.json +1 -0
- package/build/cjs/locales/nb/translations.json +1 -1
- package/build/es/__demo__/InterpretationsUnit.stories.js +38 -0
- package/build/es/components/AboutAOUnit/AboutAOUnit.js +7 -4
- package/build/es/components/Interpretations/InterpretationModal/InterpretationModal.js +15 -15
- package/build/es/components/Interpretations/InterpretationModal/InterpretationThread.js +14 -12
- package/build/es/components/Interpretations/InterpretationsUnit/InterpretationForm.js +4 -1
- package/build/es/components/Interpretations/InterpretationsUnit/InterpretationList.js +5 -1
- package/build/es/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +7 -2
- package/build/es/components/Interpretations/common/Message/Message.js +12 -8
- package/build/es/components/Interpretations/common/RichTextEditor/RichTextEditor.js +5 -2
- package/build/es/components/Interpretations/common/__tests__/getInterpretationAccess.spec.js +172 -3
- package/build/es/components/Interpretations/common/getInterpretationAccess.js +15 -3
- package/build/es/locales/en/translations.json +1 -0
- package/build/es/locales/nb/translations.json +1 -1
- package/package.json +1 -1
- /package/build/cjs/modules/pivotTable/__tests__/{addToTotalIfNumber.js → addToTotalIfNumber.spec.js} +0 -0
- /package/build/es/modules/pivotTable/__tests__/{addToTotalIfNumber.js → addToTotalIfNumber.spec.js} +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _appRuntime = require("@dhis2/app-runtime");
|
|
4
|
+
var _react = require("@storybook/react");
|
|
5
|
+
var _react2 = _interopRequireDefault(require("react"));
|
|
6
|
+
var _index = require("../components/Interpretations/InterpretationsUnit/index.js");
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
(0, _react.storiesOf)('IntepretationsUnit', module).add('Default', () => {
|
|
9
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
10
|
+
data: {
|
|
11
|
+
interpretations: {
|
|
12
|
+
interpretations: []
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}, /*#__PURE__*/_react2.default.createElement(_index.InterpretationsUnit, {
|
|
16
|
+
currentUser: {
|
|
17
|
+
name: 'Tom Wakiki'
|
|
18
|
+
},
|
|
19
|
+
id: "abcd",
|
|
20
|
+
onReplyIconClick: Function.prototype,
|
|
21
|
+
type: "eventVisualization",
|
|
22
|
+
visualizationHasTimeDimension: true
|
|
23
|
+
}));
|
|
24
|
+
});
|
|
25
|
+
(0, _react.storiesOf)('IntepretationsUnit', module).add('With no time dimensions warning', () => {
|
|
26
|
+
return /*#__PURE__*/_react2.default.createElement(_appRuntime.CustomDataProvider, {
|
|
27
|
+
data: {
|
|
28
|
+
interpretations: {
|
|
29
|
+
interpretations: []
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}, /*#__PURE__*/_react2.default.createElement(_index.InterpretationsUnit, {
|
|
33
|
+
currentUser: {
|
|
34
|
+
name: 'Tom Wakiki'
|
|
35
|
+
},
|
|
36
|
+
id: "abcd",
|
|
37
|
+
onReplyIconClick: Function.prototype,
|
|
38
|
+
type: "eventVisualization",
|
|
39
|
+
visualizationHasTimeDimension: false
|
|
40
|
+
}));
|
|
41
|
+
});
|
|
@@ -60,6 +60,9 @@ const AboutAOUnit = /*#__PURE__*/(0, _react.forwardRef)((_ref3, ref) => {
|
|
|
60
60
|
renderId
|
|
61
61
|
} = _ref3;
|
|
62
62
|
const [isExpanded, setIsExpanded] = (0, _react.useState)(true);
|
|
63
|
+
const {
|
|
64
|
+
fromServerDate
|
|
65
|
+
} = (0, _appRuntime.useTimeZoneConversion)();
|
|
63
66
|
const queries = (0, _react.useMemo)(() => getQueries(type), [type]);
|
|
64
67
|
const {
|
|
65
68
|
data,
|
|
@@ -166,16 +169,16 @@ const AboutAOUnit = /*#__PURE__*/(0, _react.forwardRef)((_ref3, ref) => {
|
|
|
166
169
|
}, /*#__PURE__*/_react.default.createElement(_ui.IconClock16, {
|
|
167
170
|
color: _ui.colors.grey700
|
|
168
171
|
}), _d2I18n.default.t('Last updated {{time}}', {
|
|
169
|
-
time: (0, _moment.default)(data.ao.lastUpdated).fromNow()
|
|
172
|
+
time: (0, _moment.default)(fromServerDate(data.ao.lastUpdated)).fromNow()
|
|
170
173
|
})), /*#__PURE__*/_react.default.createElement("p", {
|
|
171
174
|
className: `jsx-${_AboutAOUnitStyle.default.__hash}` + " " + "detailLine"
|
|
172
175
|
}, /*#__PURE__*/_react.default.createElement(_ui.IconUser16, {
|
|
173
176
|
color: _ui.colors.grey700
|
|
174
177
|
}), (_data$ao$createdBy = data.ao.createdBy) !== null && _data$ao$createdBy !== void 0 && _data$ao$createdBy.displayName ? _d2I18n.default.t('Created {{time}} by {{author}}', {
|
|
175
|
-
time: (0, _moment.default)(data.ao.created).fromNow(),
|
|
178
|
+
time: (0, _moment.default)(fromServerDate(data.ao.created)).fromNow(),
|
|
176
179
|
author: data.ao.createdBy.displayName
|
|
177
180
|
}) : _d2I18n.default.t('Created {{time}}', {
|
|
178
|
-
time: (0, _moment.default)(data.ao.created).fromNow()
|
|
181
|
+
time: (0, _moment.default)(fromServerDate(data.ao.created)).fromNow()
|
|
179
182
|
})), /*#__PURE__*/_react.default.createElement("p", {
|
|
180
183
|
className: `jsx-${_AboutAOUnitStyle.default.__hash}` + " " + "detailLine"
|
|
181
184
|
}, /*#__PURE__*/_react.default.createElement(_ui.IconView16, {
|
|
@@ -18,17 +18,17 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
19
|
const modalCSS = {
|
|
20
20
|
styles: /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
21
|
-
id: "
|
|
22
|
-
}, ["aside.jsx-
|
|
23
|
-
className: "jsx-
|
|
21
|
+
id: "2559940363"
|
|
22
|
+
}, ["aside.jsx-2559940363{max-width:calc(100vw - 128px) !important;max-height:calc(100vh - 128px) !important;width:auto !important;height:calc(100vh - 128px) !important;overflow-y:hidden;}", "aside.hidden.jsx-2559940363{display:none;}", "aside.jsx-2559940363>div>div{height:100%;}"]),
|
|
23
|
+
className: "jsx-2559940363"
|
|
24
24
|
};
|
|
25
25
|
function getModalContentCSS(width) {
|
|
26
26
|
return {
|
|
27
27
|
styles: /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
28
|
-
id: "
|
|
28
|
+
id: "2099285089",
|
|
29
29
|
dynamic: [width]
|
|
30
|
-
}, [`div.__jsx-style-dynamic-selector{width:${width}px;}`]),
|
|
31
|
-
className: _style.default.dynamic([["
|
|
30
|
+
}, [`div.__jsx-style-dynamic-selector{width:${width}px;overflow-y:visible;}`]),
|
|
31
|
+
className: _style.default.dynamic([["2099285089", [width]]])
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
const query = {
|
|
@@ -109,23 +109,23 @@ const InterpretationModal = _ref2 => {
|
|
|
109
109
|
}),
|
|
110
110
|
dataTest: "interpretation-modal"
|
|
111
111
|
}, /*#__PURE__*/_react.default.createElement("h1", {
|
|
112
|
-
className: _style.default.dynamic([["
|
|
112
|
+
className: _style.default.dynamic([["2014146191", [_ui.colors.grey900, _ui.spacers.dp24, _ui.spacers.dp4, _ui.spacers.dp4]]]) + " " + "title"
|
|
113
113
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
114
|
-
className: _style.default.dynamic([["
|
|
114
|
+
className: _style.default.dynamic([["2014146191", [_ui.colors.grey900, _ui.spacers.dp24, _ui.spacers.dp4, _ui.spacers.dp4]]]) + " " + "ellipsis"
|
|
115
115
|
}, _d2I18n.default.t('Viewing interpretation: {{- visualisationName}}', {
|
|
116
116
|
visualisationName: visualization.displayName || visualization.name,
|
|
117
117
|
nsSeparator: '^^'
|
|
118
118
|
}))), /*#__PURE__*/_react.default.createElement(_ui.ModalContent, {
|
|
119
119
|
className: modalContentCSS.className
|
|
120
120
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
121
|
-
className: _style.default.dynamic([["
|
|
121
|
+
className: _style.default.dynamic([["2014146191", [_ui.colors.grey900, _ui.spacers.dp24, _ui.spacers.dp4, _ui.spacers.dp4]]]) + " " + "container"
|
|
122
122
|
}, error && /*#__PURE__*/_react.default.createElement(_ui.NoticeBox, {
|
|
123
123
|
error: true,
|
|
124
124
|
title: _d2I18n.default.t('Could not load interpretation')
|
|
125
125
|
}, error.message || _d2I18n.default.t('The interpretation couldn’t be displayed. Try again or contact your system administrator.')), shouldRenderModalContent && /*#__PURE__*/_react.default.createElement("div", {
|
|
126
|
-
className: _style.default.dynamic([["
|
|
126
|
+
className: _style.default.dynamic([["2014146191", [_ui.colors.grey900, _ui.spacers.dp24, _ui.spacers.dp4, _ui.spacers.dp4]]]) + " " + "row"
|
|
127
127
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
128
|
-
className: _style.default.dynamic([["
|
|
128
|
+
className: _style.default.dynamic([["2014146191", [_ui.colors.grey900, _ui.spacers.dp24, _ui.spacers.dp4, _ui.spacers.dp4]]]) + " " + "visualisation-wrap"
|
|
129
129
|
}, /*#__PURE__*/_react.default.createElement(VisualizationPlugin, {
|
|
130
130
|
filters: {
|
|
131
131
|
relativePeriodDate: interpretation.created
|
|
@@ -133,9 +133,9 @@ const InterpretationModal = _ref2 => {
|
|
|
133
133
|
visualization: visualization,
|
|
134
134
|
onResponsesReceived: onResponsesReceived,
|
|
135
135
|
displayProperty: (_currentUser$settings = currentUser.settings) === null || _currentUser$settings === void 0 ? void 0 : _currentUser$settings.keyAnalysisDisplayProperty,
|
|
136
|
-
className: _style.default.dynamic([["
|
|
136
|
+
className: _style.default.dynamic([["2014146191", [_ui.colors.grey900, _ui.spacers.dp24, _ui.spacers.dp4, _ui.spacers.dp4]]])
|
|
137
137
|
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
138
|
-
className: _style.default.dynamic([["
|
|
138
|
+
className: _style.default.dynamic([["2014146191", [_ui.colors.grey900, _ui.spacers.dp24, _ui.spacers.dp4, _ui.spacers.dp4]]]) + " " + "thread-wrap"
|
|
139
139
|
}, /*#__PURE__*/_react.default.createElement(_InterpretationThread.InterpretationThread, {
|
|
140
140
|
currentUser: currentUser,
|
|
141
141
|
fetching: fetching,
|
|
@@ -148,9 +148,9 @@ const InterpretationModal = _ref2 => {
|
|
|
148
148
|
disabled: fetching,
|
|
149
149
|
onClick: handleClose
|
|
150
150
|
}, _d2I18n.default.t('Hide interpretation'))), modalCSS.styles, modalContentCSS.styles, /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
151
|
-
id: "
|
|
151
|
+
id: "2014146191",
|
|
152
152
|
dynamic: [_ui.colors.grey900, _ui.spacers.dp24, _ui.spacers.dp4, _ui.spacers.dp4]
|
|
153
|
-
}, [`.title.__jsx-style-dynamic-selector{color:${_ui.colors.grey900};margin:0px;padding:${_ui.spacers.dp24} 0 ${_ui.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;min-width:0;}", `.thread-wrap.__jsx-style-dynamic-selector{padding-right:${_ui.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;
|
|
153
|
+
}, [`.title.__jsx-style-dynamic-selector{color:${_ui.colors.grey900};margin:0px;padding:${_ui.spacers.dp24} 0 ${_ui.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;height:100%;}", ".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;height:100%;}", ".visualisation-wrap.__jsx-style-dynamic-selector{-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;min-width:0;}", `.thread-wrap.__jsx-style-dynamic-selector{padding-right:${_ui.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;}`])));
|
|
154
154
|
};
|
|
155
155
|
exports.InterpretationModal = InterpretationModal;
|
|
156
156
|
InterpretationModal.propTypes = {
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.InterpretationThread = void 0;
|
|
7
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _appRuntime = require("@dhis2/app-runtime");
|
|
8
9
|
var _ui = require("@dhis2/ui");
|
|
9
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
11
|
var _moment = _interopRequireDefault(require("moment"));
|
|
@@ -26,6 +27,9 @@ const InterpretationThread = _ref => {
|
|
|
26
27
|
onThreadUpdated,
|
|
27
28
|
downloadMenuComponent: DownloadMenu
|
|
28
29
|
} = _ref;
|
|
30
|
+
const {
|
|
31
|
+
fromServerDate
|
|
32
|
+
} = (0, _appRuntime.useTimeZoneConversion)();
|
|
29
33
|
const focusRef = (0, _react.useRef)();
|
|
30
34
|
(0, _react.useEffect)(() => {
|
|
31
35
|
if (initialFocus && focusRef.current) {
|
|
@@ -36,20 +40,18 @@ const InterpretationThread = _ref => {
|
|
|
36
40
|
}, [initialFocus]);
|
|
37
41
|
const interpretationAccess = (0, _index.getInterpretationAccess)(interpretation, currentUser);
|
|
38
42
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
39
|
-
className: "jsx-
|
|
43
|
+
className: "jsx-1846557365" + " " + ((0, _classnames.default)('container', {
|
|
40
44
|
fetching
|
|
41
45
|
}) || "")
|
|
42
46
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
43
|
-
className: "jsx-
|
|
44
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
45
|
-
className: "jsx-615306698" + " " + 'title'
|
|
47
|
+
className: "jsx-1846557365" + " " + 'title'
|
|
46
48
|
}, /*#__PURE__*/_react.default.createElement(_ui.IconClock16, {
|
|
47
49
|
color: _ui.colors.grey700
|
|
48
|
-
}), (0, _moment.default)(interpretation.created).format('LLL')), DownloadMenu && /*#__PURE__*/_react.default.createElement(DownloadMenu, {
|
|
50
|
+
}), (0, _moment.default)(fromServerDate(interpretation.created)).format('LLL')), DownloadMenu && /*#__PURE__*/_react.default.createElement(DownloadMenu, {
|
|
49
51
|
relativePeriodDate: interpretation.created,
|
|
50
|
-
className: "jsx-
|
|
52
|
+
className: "jsx-1846557365"
|
|
51
53
|
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
52
|
-
className: "jsx-
|
|
54
|
+
className: "jsx-1846557365" + " " + 'thread'
|
|
53
55
|
}, /*#__PURE__*/_react.default.createElement(_index.Interpretation, {
|
|
54
56
|
currentUser: currentUser,
|
|
55
57
|
interpretation: interpretation,
|
|
@@ -61,7 +63,7 @@ const InterpretationThread = _ref => {
|
|
|
61
63
|
onDeleted: onInterpretationDeleted,
|
|
62
64
|
isInThread: true
|
|
63
65
|
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
64
|
-
className: "jsx-
|
|
66
|
+
className: "jsx-1846557365" + " " + 'comments'
|
|
65
67
|
}, interpretation.comments.map(comment => /*#__PURE__*/_react.default.createElement(_Comment.Comment, {
|
|
66
68
|
key: comment.id,
|
|
67
69
|
comment: comment,
|
|
@@ -69,14 +71,14 @@ const InterpretationThread = _ref => {
|
|
|
69
71
|
interpretationId: interpretation.id,
|
|
70
72
|
onThreadUpdated: onThreadUpdated,
|
|
71
73
|
canComment: interpretationAccess.comment
|
|
72
|
-
}))), interpretationAccess.comment && /*#__PURE__*/_react.default.createElement(_CommentAddForm.CommentAddForm, {
|
|
74
|
+
})))), interpretationAccess.comment && /*#__PURE__*/_react.default.createElement(_CommentAddForm.CommentAddForm, {
|
|
73
75
|
currentUser: currentUser,
|
|
74
76
|
interpretationId: interpretation.id,
|
|
75
77
|
onSave: () => onThreadUpdated(true),
|
|
76
78
|
focusRef: focusRef
|
|
77
|
-
})
|
|
78
|
-
id: "
|
|
79
|
-
}, [".thread.jsx-
|
|
79
|
+
}), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
80
|
+
id: "1846557365"
|
|
81
|
+
}, [".thread.jsx-1846557365{margin-top:var(--spacers-dp16);overflow-y:auto;-webkit-scroll-behavior:smooth;-moz-scroll-behavior:smooth;-ms-scroll-behavior:smooth;scroll-behavior:smooth;}", ".container.jsx-1846557365{position:relative;overflow:auto;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-1846557365::before{content:'';position:absolute;inset:0px;background-color:rgba(255,255,255,0.8);}", ".container.fetching.jsx-1846557365::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-1846557365;animation:1s linear 0s infinite normal none running rotation-jsx-1846557365;}", ".title.jsx-1846557365{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-1846557365{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-1846557365{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-1846557365{0%{-webkit-transform:rotate(0);-ms-transform:rotate(0);transform:rotate(0);}100%{-webkit-transform:rotate(360deg);-ms-transform:rotate(360deg);transform:rotate(360deg);}}"]));
|
|
80
82
|
};
|
|
81
83
|
exports.InterpretationThread = InterpretationThread;
|
|
82
84
|
InterpretationThread.propTypes = {
|
|
@@ -19,6 +19,7 @@ const InterpretationForm = _ref => {
|
|
|
19
19
|
id,
|
|
20
20
|
currentUser,
|
|
21
21
|
disabled,
|
|
22
|
+
showNoTimeDimensionHelpText,
|
|
22
23
|
onSave
|
|
23
24
|
} = _ref;
|
|
24
25
|
const [showRichTextEditor, setShowRichTextEditor] = (0, _react.useState)(false);
|
|
@@ -50,7 +51,8 @@ const InterpretationForm = _ref => {
|
|
|
50
51
|
disabled: saveMutationInProgress,
|
|
51
52
|
inputPlaceholder: inputPlaceholder,
|
|
52
53
|
onChange: setInterpretationText,
|
|
53
|
-
value: interpretationText
|
|
54
|
+
value: interpretationText,
|
|
55
|
+
helpText: showNoTimeDimensionHelpText ? _d2I18n.default.t('Other people viewing this interpretation in the future may see more data.') : undefined
|
|
54
56
|
}), /*#__PURE__*/_react.default.createElement(_index.MessageButtonStrip, null, /*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
55
57
|
primary: true,
|
|
56
58
|
small: true,
|
|
@@ -77,6 +79,7 @@ InterpretationForm.propTypes = {
|
|
|
77
79
|
currentUser: _propTypes.default.object,
|
|
78
80
|
disabled: _propTypes.default.bool,
|
|
79
81
|
id: _propTypes.default.string,
|
|
82
|
+
showNoTimeDimensionHelpText: _propTypes.default.bool,
|
|
80
83
|
type: _propTypes.default.string,
|
|
81
84
|
onSave: _propTypes.default.func
|
|
82
85
|
};
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.InterpretationList = void 0;
|
|
7
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _appRuntime = require("@dhis2/app-runtime");
|
|
8
9
|
var _ui = require("@dhis2/ui");
|
|
9
10
|
var _moment = _interopRequireDefault(require("moment"));
|
|
10
11
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
@@ -31,6 +32,9 @@ const InterpretationList = _ref => {
|
|
|
31
32
|
refresh,
|
|
32
33
|
disabled
|
|
33
34
|
} = _ref;
|
|
35
|
+
const {
|
|
36
|
+
fromServerDate
|
|
37
|
+
} = (0, _appRuntime.useTimeZoneConversion)();
|
|
34
38
|
const interpretationsByDate = interpretations.reduce((groupedInterpretations, interpretation) => {
|
|
35
39
|
const date = interpretation.created.split('T')[0];
|
|
36
40
|
if (date in groupedInterpretations) {
|
|
@@ -53,7 +57,7 @@ const InterpretationList = _ref => {
|
|
|
53
57
|
}), /*#__PURE__*/_react.default.createElement("time", {
|
|
54
58
|
dateTime: date,
|
|
55
59
|
className: _style.default.dynamic([["4058400613", [_ui.spacers.dp8, _ui.spacers.dp8, _ui.spacers.dp16, _ui.colors.grey800, _ui.spacers.dp12, _ui.spacers.dp12, _ui.spacers.dp32, _ui.spacers.dp4]]]) + " " + "date-header"
|
|
56
|
-
}, (0, _moment.default)(date).format('ll'))), /*#__PURE__*/_react.default.createElement("ol", {
|
|
60
|
+
}, (0, _moment.default)(fromServerDate(date)).format('ll'))), /*#__PURE__*/_react.default.createElement("ol", {
|
|
57
61
|
className: _style.default.dynamic([["4058400613", [_ui.spacers.dp8, _ui.spacers.dp8, _ui.spacers.dp16, _ui.colors.grey800, _ui.spacers.dp12, _ui.spacers.dp12, _ui.spacers.dp32, _ui.spacers.dp4]]]) + " " + "interpretation-list"
|
|
58
62
|
}, interpretationsByDate[date].sort(sortByCreatedDateDesc).map(interpretation => /*#__PURE__*/_react.default.createElement(_index.Interpretation, {
|
|
59
63
|
key: interpretation.id,
|
|
@@ -36,12 +36,14 @@ const InterpretationsUnit = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) =>
|
|
|
36
36
|
currentUser,
|
|
37
37
|
type,
|
|
38
38
|
id,
|
|
39
|
+
visualizationHasTimeDimension,
|
|
39
40
|
onInterpretationClick,
|
|
40
41
|
onReplyIconClick,
|
|
41
42
|
disabled,
|
|
42
43
|
renderId
|
|
43
44
|
} = _ref2;
|
|
44
45
|
const [isExpanded, setIsExpanded] = (0, _react.useState)(true);
|
|
46
|
+
const showNoTimeDimensionHelpText = type === 'eventVisualization' && !visualizationHasTimeDimension;
|
|
45
47
|
const {
|
|
46
48
|
data,
|
|
47
49
|
loading,
|
|
@@ -93,7 +95,8 @@ const InterpretationsUnit = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) =>
|
|
|
93
95
|
type: type,
|
|
94
96
|
id: id,
|
|
95
97
|
onSave: onCompleteAction,
|
|
96
|
-
disabled: disabled
|
|
98
|
+
disabled: disabled,
|
|
99
|
+
showNoTimeDimensionHelpText: showNoTimeDimensionHelpText
|
|
97
100
|
}), /*#__PURE__*/_react.default.createElement(_InterpretationList.InterpretationList, {
|
|
98
101
|
currentUser: currentUser,
|
|
99
102
|
interpretations: data.interpretations.interpretations,
|
|
@@ -109,7 +112,8 @@ const InterpretationsUnit = /*#__PURE__*/(0, _react.forwardRef)((_ref2, ref) =>
|
|
|
109
112
|
exports.InterpretationsUnit = InterpretationsUnit;
|
|
110
113
|
InterpretationsUnit.displayName = 'InterpretationsUnit';
|
|
111
114
|
InterpretationsUnit.defaultProps = {
|
|
112
|
-
onInterpretationClick: Function.prototype
|
|
115
|
+
onInterpretationClick: Function.prototype,
|
|
116
|
+
visualizationHasTimeDimension: true
|
|
113
117
|
};
|
|
114
118
|
InterpretationsUnit.propTypes = {
|
|
115
119
|
currentUser: _propTypes.default.object.isRequired,
|
|
@@ -117,6 +121,7 @@ InterpretationsUnit.propTypes = {
|
|
|
117
121
|
type: _propTypes.default.string.isRequired,
|
|
118
122
|
disabled: _propTypes.default.bool,
|
|
119
123
|
renderId: _propTypes.default.number,
|
|
124
|
+
visualizationHasTimeDimension: _propTypes.default.bool,
|
|
120
125
|
onInterpretationClick: _propTypes.default.func,
|
|
121
126
|
onReplyIconClick: _propTypes.default.func
|
|
122
127
|
};
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Message = void 0;
|
|
7
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _appRuntime = require("@dhis2/app-runtime");
|
|
8
9
|
var _d2UiRichText = require("@dhis2/d2-ui-rich-text");
|
|
9
10
|
var _ui = require("@dhis2/ui");
|
|
10
11
|
var _moment = _interopRequireDefault(require("moment"));
|
|
@@ -18,24 +19,27 @@ const Message = _ref => {
|
|
|
18
19
|
created,
|
|
19
20
|
username
|
|
20
21
|
} = _ref;
|
|
22
|
+
const {
|
|
23
|
+
fromServerDate
|
|
24
|
+
} = (0, _appRuntime.useTimeZoneConversion)();
|
|
21
25
|
return /*#__PURE__*/_react.default.createElement("li", {
|
|
22
|
-
className: _style.default.dynamic([["
|
|
26
|
+
className: _style.default.dynamic([["3500389795", [_ui.spacers.dp8, _ui.colors.grey100, _ui.spacers.dp8, _ui.colors.grey900, _ui.colors.grey600, _ui.colors.grey900, _ui.spacers.dp8]]]) + " " + "container"
|
|
23
27
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
24
|
-
className: _style.default.dynamic([["
|
|
28
|
+
className: _style.default.dynamic([["3500389795", [_ui.spacers.dp8, _ui.colors.grey100, _ui.spacers.dp8, _ui.colors.grey900, _ui.colors.grey600, _ui.colors.grey900, _ui.spacers.dp8]]]) + " " + "header"
|
|
25
29
|
}, /*#__PURE__*/_react.default.createElement(_ui.UserAvatar, {
|
|
26
30
|
name: username,
|
|
27
31
|
extrasmall: true
|
|
28
32
|
}), username, /*#__PURE__*/_react.default.createElement("time", {
|
|
29
33
|
dateTime: created,
|
|
30
|
-
className: _style.default.dynamic([["
|
|
31
|
-
}, (0, _moment.default)(created).format('lll'))), /*#__PURE__*/_react.default.createElement("div", {
|
|
32
|
-
className: _style.default.dynamic([["
|
|
34
|
+
className: _style.default.dynamic([["3500389795", [_ui.spacers.dp8, _ui.colors.grey100, _ui.spacers.dp8, _ui.colors.grey900, _ui.colors.grey600, _ui.colors.grey900, _ui.spacers.dp8]]])
|
|
35
|
+
}, (0, _moment.default)(fromServerDate(created)).format('lll'))), /*#__PURE__*/_react.default.createElement("div", {
|
|
36
|
+
className: _style.default.dynamic([["3500389795", [_ui.spacers.dp8, _ui.colors.grey100, _ui.spacers.dp8, _ui.colors.grey900, _ui.colors.grey600, _ui.colors.grey900, _ui.spacers.dp8]]]) + " " + "content"
|
|
33
37
|
}, /*#__PURE__*/_react.default.createElement(_d2UiRichText.Parser, null, text)), /*#__PURE__*/_react.default.createElement("div", {
|
|
34
|
-
className: _style.default.dynamic([["
|
|
38
|
+
className: _style.default.dynamic([["3500389795", [_ui.spacers.dp8, _ui.colors.grey100, _ui.spacers.dp8, _ui.colors.grey900, _ui.colors.grey600, _ui.colors.grey900, _ui.spacers.dp8]]]) + " " + "footer"
|
|
35
39
|
}, children), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
36
|
-
id: "
|
|
40
|
+
id: "3500389795",
|
|
37
41
|
dynamic: [_ui.spacers.dp8, _ui.colors.grey100, _ui.spacers.dp8, _ui.colors.grey900, _ui.colors.grey600, _ui.colors.grey900, _ui.spacers.dp8]
|
|
38
|
-
}, [`.container.__jsx-style-dynamic-selector{padding:${_ui.spacers.dp8};background-color:${_ui.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:${_ui.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:${_ui.colors.grey900};}`, `.header.__jsx-style-dynamic-selector time.__jsx-style-dynamic-selector{font-size:12px;color:${_ui.colors.grey600};}`, `.content.__jsx-style-dynamic-selector{font-size:14px;line-height:19px;color:${_ui.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:${_ui.spacers.dp8};}`]));
|
|
42
|
+
}, [`.container.__jsx-style-dynamic-selector{padding:${_ui.spacers.dp8};background-color:${_ui.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:${_ui.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:${_ui.colors.grey900};}`, `.header.__jsx-style-dynamic-selector time.__jsx-style-dynamic-selector{font-size:12px;color:${_ui.colors.grey600};}`, `.content.__jsx-style-dynamic-selector{font-size:14px;line-height:19px;color:${_ui.colors.grey900};word-break:break-word;}`, ".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:${_ui.spacers.dp8};}`]));
|
|
39
43
|
};
|
|
40
44
|
exports.Message = Message;
|
|
41
45
|
Message.propTypes = {
|
|
@@ -182,7 +182,8 @@ const RichTextEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref5, externalRef)
|
|
|
182
182
|
disabled,
|
|
183
183
|
inputPlaceholder,
|
|
184
184
|
onChange,
|
|
185
|
-
errorText
|
|
185
|
+
errorText,
|
|
186
|
+
helpText
|
|
186
187
|
} = _ref5;
|
|
187
188
|
const [previewMode, setPreviewMode] = (0, _react.useState)(false);
|
|
188
189
|
const internalRef = (0, _react.useRef)();
|
|
@@ -215,7 +216,8 @@ const RichTextEditor = /*#__PURE__*/(0, _react.forwardRef)((_ref5, externalRef)
|
|
|
215
216
|
className: `jsx-${_RichTextEditorStyle.mainClasses.__hash}` + " " + "preview"
|
|
216
217
|
}, /*#__PURE__*/_react.default.createElement(_d2UiRichText.Parser, null, value)) : /*#__PURE__*/_react.default.createElement(_ui.Field, {
|
|
217
218
|
error: !!errorText,
|
|
218
|
-
validationText: errorText
|
|
219
|
+
validationText: errorText,
|
|
220
|
+
helpText: helpText
|
|
219
221
|
}, /*#__PURE__*/_react.default.createElement(_UserMentionWrapper.UserMentionWrapper, {
|
|
220
222
|
onUserSelect: onChange,
|
|
221
223
|
inputReference: textareaRef
|
|
@@ -238,5 +240,6 @@ RichTextEditor.propTypes = {
|
|
|
238
240
|
onChange: _propTypes.default.func.isRequired,
|
|
239
241
|
disabled: _propTypes.default.bool,
|
|
240
242
|
errorText: _propTypes.default.string,
|
|
243
|
+
helpText: _propTypes.default.string,
|
|
241
244
|
inputPlaceholder: _propTypes.default.string
|
|
242
245
|
};
|
package/build/cjs/components/Interpretations/common/__tests__/getInterpretationAccess.spec.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _getInterpretationAccess = require("../getInterpretationAccess.js");
|
|
4
|
-
const
|
|
4
|
+
const superuserD2CurrentUser = {
|
|
5
5
|
id: 'iamsuper',
|
|
6
6
|
authorities: new Set(['ALL'])
|
|
7
7
|
};
|
|
8
|
-
const
|
|
8
|
+
const userJoeD2CurrentUser = {
|
|
9
9
|
id: 'johndoe',
|
|
10
10
|
authorities: new Set(['Some'])
|
|
11
11
|
};
|
|
12
|
-
const
|
|
12
|
+
const userJaneD2CurrentUser = {
|
|
13
13
|
id: 'jane',
|
|
14
14
|
authorities: new Set(['Some'])
|
|
15
15
|
};
|
|
16
|
+
const superuser = {
|
|
17
|
+
id: 'iamsuper',
|
|
18
|
+
authorities: ['ALL']
|
|
19
|
+
};
|
|
20
|
+
const userJoe = {
|
|
21
|
+
id: 'johndoe',
|
|
22
|
+
authorities: ['Some']
|
|
23
|
+
};
|
|
24
|
+
const userJane = {
|
|
25
|
+
id: 'jane',
|
|
26
|
+
authorities: ['Some']
|
|
27
|
+
};
|
|
16
28
|
describe('interpretation and comment access', () => {
|
|
17
29
|
describe('getInterpretationAccess', () => {
|
|
18
30
|
it('returns true for all accesses for superuser', () => {
|
|
@@ -90,6 +102,163 @@ describe('interpretation and comment access', () => {
|
|
|
90
102
|
delete: false
|
|
91
103
|
});
|
|
92
104
|
});
|
|
105
|
+
it('throws an error for all accesses when no currentUser provided', () => {
|
|
106
|
+
const interpretation = {
|
|
107
|
+
access: {
|
|
108
|
+
write: false,
|
|
109
|
+
manage: false
|
|
110
|
+
},
|
|
111
|
+
createdBy: userJane
|
|
112
|
+
};
|
|
113
|
+
expect(() => (0, _getInterpretationAccess.getInterpretationAccess)(interpretation)).toThrow('"hasAuthority" requires "authorities" to be an array or set of authorities (strings)');
|
|
114
|
+
});
|
|
115
|
+
it('throws an error when currentUser is missing authorities', () => {
|
|
116
|
+
const interpretation = {
|
|
117
|
+
access: {
|
|
118
|
+
write: false,
|
|
119
|
+
manage: false
|
|
120
|
+
},
|
|
121
|
+
createdBy: userJane
|
|
122
|
+
};
|
|
123
|
+
expect(() => (0, _getInterpretationAccess.getInterpretationAccess)(interpretation, {
|
|
124
|
+
id: 'usernoauthorties'
|
|
125
|
+
})).toThrow('"hasAuthority" requires "authorities" to be an array or set of authorities (strings)');
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('getInterpretationAccess using D2.currentUser', () => {
|
|
129
|
+
it('returns true for all accesses for superuser', () => {
|
|
130
|
+
const interpretation = {
|
|
131
|
+
access: {
|
|
132
|
+
write: true,
|
|
133
|
+
manage: true
|
|
134
|
+
},
|
|
135
|
+
createdBy: userJoeD2CurrentUser
|
|
136
|
+
};
|
|
137
|
+
expect((0, _getInterpretationAccess.getInterpretationAccess)(interpretation, superuserD2CurrentUser)).toMatchObject({
|
|
138
|
+
share: true,
|
|
139
|
+
comment: true,
|
|
140
|
+
edit: true,
|
|
141
|
+
delete: true
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
it('returns true for all accesses for creator', () => {
|
|
145
|
+
const interpretation = {
|
|
146
|
+
access: {
|
|
147
|
+
write: true,
|
|
148
|
+
manage: true
|
|
149
|
+
},
|
|
150
|
+
createdBy: userJoeD2CurrentUser
|
|
151
|
+
};
|
|
152
|
+
expect((0, _getInterpretationAccess.getInterpretationAccess)(interpretation, userJoeD2CurrentUser)).toMatchObject({
|
|
153
|
+
share: true,
|
|
154
|
+
comment: true,
|
|
155
|
+
edit: true,
|
|
156
|
+
delete: true
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
it('returns false for edit/delete if user is not creator/superuser', () => {
|
|
160
|
+
const interpretation = {
|
|
161
|
+
access: {
|
|
162
|
+
write: true,
|
|
163
|
+
manage: true
|
|
164
|
+
},
|
|
165
|
+
createdBy: userJaneD2CurrentUser
|
|
166
|
+
};
|
|
167
|
+
expect((0, _getInterpretationAccess.getInterpretationAccess)(interpretation, userJoeD2CurrentUser)).toMatchObject({
|
|
168
|
+
share: true,
|
|
169
|
+
comment: true,
|
|
170
|
+
edit: false,
|
|
171
|
+
delete: false
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
it('returns false for comment/edit/delete if user is not creator/superuser and no write access', () => {
|
|
175
|
+
const interpretation = {
|
|
176
|
+
access: {
|
|
177
|
+
write: false,
|
|
178
|
+
manage: true
|
|
179
|
+
},
|
|
180
|
+
createdBy: userJaneD2CurrentUser
|
|
181
|
+
};
|
|
182
|
+
expect((0, _getInterpretationAccess.getInterpretationAccess)(interpretation, userJoeD2CurrentUser)).toMatchObject({
|
|
183
|
+
share: true,
|
|
184
|
+
comment: false,
|
|
185
|
+
edit: false,
|
|
186
|
+
delete: false
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
it('returns false for share/comment/edit/delete if user is not creator/superuser and no write or manage access', () => {
|
|
190
|
+
const interpretation = {
|
|
191
|
+
access: {
|
|
192
|
+
write: false,
|
|
193
|
+
manage: false
|
|
194
|
+
},
|
|
195
|
+
createdBy: userJaneD2CurrentUser
|
|
196
|
+
};
|
|
197
|
+
expect((0, _getInterpretationAccess.getInterpretationAccess)(interpretation, userJoeD2CurrentUser)).toMatchObject({
|
|
198
|
+
share: false,
|
|
199
|
+
comment: false,
|
|
200
|
+
edit: false,
|
|
201
|
+
delete: false
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
describe('getCommentAccess using D2.currentUser', () => {
|
|
206
|
+
it('returns true for all accesses for superuser', () => {
|
|
207
|
+
const interpretation = {
|
|
208
|
+
access: {
|
|
209
|
+
write: true
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
const comment = {
|
|
213
|
+
createdBy: userJoeD2CurrentUser
|
|
214
|
+
};
|
|
215
|
+
expect((0, _getInterpretationAccess.getCommentAccess)(comment, interpretation.access.write, superuserD2CurrentUser)).toMatchObject({
|
|
216
|
+
edit: true,
|
|
217
|
+
delete: true
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
it('returns true for all accesses for creator when interpretation has write access', () => {
|
|
221
|
+
const interpretation = {
|
|
222
|
+
access: {
|
|
223
|
+
write: true
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const comment = {
|
|
227
|
+
createdBy: userJoeD2CurrentUser
|
|
228
|
+
};
|
|
229
|
+
expect((0, _getInterpretationAccess.getCommentAccess)(comment, interpretation.access.write, userJoeD2CurrentUser)).toMatchObject({
|
|
230
|
+
edit: true,
|
|
231
|
+
delete: true
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
it('returns true for edit and false for delete for creator when interpretation does not have write access', () => {
|
|
235
|
+
const interpretation = {
|
|
236
|
+
access: {
|
|
237
|
+
write: false
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const comment = {
|
|
241
|
+
createdBy: userJoeD2CurrentUser
|
|
242
|
+
};
|
|
243
|
+
expect((0, _getInterpretationAccess.getCommentAccess)(comment, interpretation.access.write, userJoeD2CurrentUser)).toMatchObject({
|
|
244
|
+
edit: true,
|
|
245
|
+
delete: false
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
it('returns false for edit/delete for user who is not creator or superuser', () => {
|
|
249
|
+
const interpretation = {
|
|
250
|
+
access: {
|
|
251
|
+
write: true
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
const comment = {
|
|
255
|
+
createdBy: userJaneD2CurrentUser
|
|
256
|
+
};
|
|
257
|
+
expect((0, _getInterpretationAccess.getCommentAccess)(comment, interpretation.access.write, userJoeD2CurrentUser)).toMatchObject({
|
|
258
|
+
edit: false,
|
|
259
|
+
delete: false
|
|
260
|
+
});
|
|
261
|
+
});
|
|
93
262
|
});
|
|
94
263
|
describe('getCommentAccess', () => {
|
|
95
264
|
it('returns true for all accesses for superuser', () => {
|
|
@@ -4,9 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getInterpretationAccess = exports.getCommentAccess = void 0;
|
|
7
|
-
|
|
7
|
+
// For backwards compatibility
|
|
8
|
+
// accept both Set (from the old d2.currentUser object) and array
|
|
9
|
+
const hasAuthority = (authorities, authority) => {
|
|
10
|
+
if (!authority || typeof authority !== 'string') {
|
|
11
|
+
throw new Error(`"hasAuthority" requires "authority" to be a populated string but received ${authority}`);
|
|
12
|
+
}
|
|
13
|
+
if (!(Array.isArray(authorities) || typeof (authorities === null || authorities === void 0 ? void 0 : authorities.has) === 'function')) {
|
|
14
|
+
throw new Error(`"hasAuthority" requires "authorities" to be an array or set of authorities (strings)`);
|
|
15
|
+
}
|
|
16
|
+
return Array.isArray(authorities) ? authorities.includes(authority) : authorities.has(authority);
|
|
17
|
+
};
|
|
18
|
+
const isSuperuser = authorities => hasAuthority(authorities, 'ALL');
|
|
19
|
+
const isCreator = (object, currentUser) => (object === null || object === void 0 ? void 0 : object.createdBy.id) === (currentUser === null || currentUser === void 0 ? void 0 : currentUser.id);
|
|
8
20
|
const getInterpretationAccess = (interpretation, currentUser) => {
|
|
9
|
-
const canEditDelete =
|
|
21
|
+
const canEditDelete = isCreator(interpretation, currentUser) || isSuperuser(currentUser === null || currentUser === void 0 ? void 0 : currentUser.authorities);
|
|
10
22
|
return {
|
|
11
23
|
share: interpretation.access.manage,
|
|
12
24
|
comment: interpretation.access.write,
|
|
@@ -16,7 +28,7 @@ const getInterpretationAccess = (interpretation, currentUser) => {
|
|
|
16
28
|
};
|
|
17
29
|
exports.getInterpretationAccess = getInterpretationAccess;
|
|
18
30
|
const getCommentAccess = (comment, hasInterpretationReplyAccess, currentUser) => {
|
|
19
|
-
const canEditDelete =
|
|
31
|
+
const canEditDelete = isCreator(comment, currentUser) || isSuperuser(currentUser === null || currentUser === void 0 ? void 0 : currentUser.authorities);
|
|
20
32
|
return {
|
|
21
33
|
edit: canEditDelete,
|
|
22
34
|
delete: canEditDelete && hasInterpretationReplyAccess
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
"The interpretation couldn’t be displayed. Try again or contact your system administrator.": "The interpretation couldn’t be displayed. Try again or contact your system administrator.",
|
|
117
117
|
"Hide interpretation": "Hide interpretation",
|
|
118
118
|
"Write an interpretation": "Write an interpretation",
|
|
119
|
+
"Other people viewing this interpretation in the future may see more data.": "Other people viewing this interpretation in the future may see more data.",
|
|
119
120
|
"Post interpretation": "Post interpretation",
|
|
120
121
|
"Interpretations": "Interpretations",
|
|
121
122
|
"Reply": "Reply",
|