@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.
- package/build/cjs/__demo__/InterpretationsUnit.stories.js +9 -6
- package/build/cjs/__fixtures__/interpretationsMockData.js +204 -0
- package/build/cjs/components/Interpretations/DashboardItemInterpretations/DashboardInterpretationThread.js +56 -0
- package/build/cjs/components/Interpretations/DashboardItemInterpretations/DashboardItemInterpretations.js +54 -0
- package/build/cjs/components/Interpretations/DashboardItemInterpretations/index.js +12 -0
- package/build/cjs/components/Interpretations/InterpretationModal/Comment.js +12 -17
- package/build/cjs/components/Interpretations/InterpretationModal/CommentAddForm.js +20 -34
- package/build/cjs/components/Interpretations/InterpretationModal/CommentDeleteButton.js +11 -36
- package/build/cjs/components/Interpretations/InterpretationModal/CommentUpdateForm.js +11 -27
- package/build/cjs/components/Interpretations/InterpretationModal/InterpretationModal.js +11 -68
- package/build/cjs/components/Interpretations/InterpretationModal/InterpretationThread.js +11 -24
- package/build/cjs/components/Interpretations/InterpretationsProvider/InterpretationsManager.js +275 -0
- package/build/cjs/components/Interpretations/InterpretationsProvider/InterpretationsProvider.js +28 -0
- package/build/cjs/components/Interpretations/InterpretationsProvider/__tests__/groupInterpretationIdsByDate.spec.js +37 -0
- package/build/cjs/components/Interpretations/InterpretationsProvider/__tests__/hooks.spec.js +565 -0
- package/build/cjs/components/Interpretations/InterpretationsProvider/groupInterpretationIdsByDate.js +16 -0
- package/build/cjs/components/Interpretations/InterpretationsProvider/hooks.js +278 -0
- package/build/cjs/components/Interpretations/InterpretationsProvider/index.js +12 -0
- package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationForm.js +25 -30
- package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationList.js +8 -38
- package/build/cjs/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +22 -73
- package/build/cjs/components/Interpretations/common/Interpretation/Interpretation.js +20 -34
- package/build/cjs/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js +10 -12
- package/build/cjs/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js +13 -24
- package/build/cjs/components/Interpretations/common/Message/MessageEditorContainer.js +3 -3
- package/build/cjs/index.js +72 -63
- package/build/cjs/locales/en/translations.json +10 -1
- package/build/cjs/modules/pivotTable/getHeaderForDisplay.js +1 -1
- package/build/es/__demo__/InterpretationsUnit.stories.js +9 -6
- package/build/es/__fixtures__/interpretationsMockData.js +198 -0
- package/build/es/components/Interpretations/DashboardItemInterpretations/DashboardInterpretationThread.js +48 -0
- package/build/es/components/Interpretations/DashboardItemInterpretations/DashboardItemInterpretations.js +45 -0
- package/build/es/components/Interpretations/DashboardItemInterpretations/index.js +1 -0
- package/build/es/components/Interpretations/InterpretationModal/Comment.js +14 -19
- package/build/es/components/Interpretations/InterpretationModal/CommentAddForm.js +21 -35
- package/build/es/components/Interpretations/InterpretationModal/CommentDeleteButton.js +11 -35
- package/build/es/components/Interpretations/InterpretationModal/CommentUpdateForm.js +12 -28
- package/build/es/components/Interpretations/InterpretationModal/InterpretationModal.js +12 -69
- package/build/es/components/Interpretations/InterpretationModal/InterpretationThread.js +11 -24
- package/build/es/components/Interpretations/InterpretationsProvider/InterpretationsManager.js +268 -0
- package/build/es/components/Interpretations/InterpretationsProvider/InterpretationsProvider.js +19 -0
- package/build/es/components/Interpretations/InterpretationsProvider/__tests__/groupInterpretationIdsByDate.spec.js +35 -0
- package/build/es/components/Interpretations/InterpretationsProvider/__tests__/hooks.spec.js +561 -0
- package/build/es/components/Interpretations/InterpretationsProvider/groupInterpretationIdsByDate.js +9 -0
- package/build/es/components/Interpretations/InterpretationsProvider/hooks.js +258 -0
- package/build/es/components/Interpretations/InterpretationsProvider/index.js +1 -0
- package/build/es/components/Interpretations/InterpretationsUnit/InterpretationForm.js +26 -31
- package/build/es/components/Interpretations/InterpretationsUnit/InterpretationList.js +8 -38
- package/build/es/components/Interpretations/InterpretationsUnit/InterpretationsUnit.js +23 -75
- package/build/es/components/Interpretations/common/Interpretation/Interpretation.js +21 -35
- package/build/es/components/Interpretations/common/Interpretation/InterpretationDeleteButton.js +11 -13
- package/build/es/components/Interpretations/common/Interpretation/InterpretationUpdateForm.js +14 -25
- package/build/es/components/Interpretations/common/Message/MessageEditorContainer.js +3 -3
- package/build/es/index.js +3 -1
- package/build/es/locales/en/translations.json +10 -1
- package/build/es/modules/pivotTable/getHeaderForDisplay.js +1 -1
- package/package.json +1 -1
- package/build/cjs/components/Interpretations/common/Interpretation/useLike.js +0 -56
- package/build/es/components/Interpretations/common/Interpretation/useLike.js +0 -50
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useUpdateInterpretationText = exports.useUpdateCommentForActiveInterpretation = exports.useLike = exports.useInterpretationsManager = exports.useInterpretationsList = exports.useInterpretationsCurrentUser = exports.useInterpretationAccess = exports.useInterpretation = exports.useDeleteInterpretation = exports.useDeleteCommentFromActiveInterpretation = exports.useCreateInterpretation = exports.useCommentAccess = exports.useAddCommentToActiveInterpretation = exports.useActiveInterpretation = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _getInterpretationAccess = require("../common/getInterpretationAccess.js");
|
|
9
|
+
var _InterpretationsProvider = require("./InterpretationsProvider.js");
|
|
10
|
+
const SET_LOADING = 'SET_LOADING';
|
|
11
|
+
const SET_ERROR = 'SET_ERROR';
|
|
12
|
+
const SET_DATA = 'SET_DATA';
|
|
13
|
+
const RESET = 'RESET';
|
|
14
|
+
const initialLoadingState = {
|
|
15
|
+
loading: false,
|
|
16
|
+
error: undefined,
|
|
17
|
+
data: undefined
|
|
18
|
+
};
|
|
19
|
+
function loadingReducer(state, action) {
|
|
20
|
+
switch (action.type) {
|
|
21
|
+
case SET_LOADING:
|
|
22
|
+
return {
|
|
23
|
+
...state,
|
|
24
|
+
loading: true
|
|
25
|
+
};
|
|
26
|
+
case SET_ERROR:
|
|
27
|
+
return {
|
|
28
|
+
...state,
|
|
29
|
+
error: action.payload,
|
|
30
|
+
loading: false
|
|
31
|
+
};
|
|
32
|
+
case SET_DATA:
|
|
33
|
+
return {
|
|
34
|
+
data: action.payload,
|
|
35
|
+
error: undefined,
|
|
36
|
+
loading: false
|
|
37
|
+
};
|
|
38
|
+
case RESET:
|
|
39
|
+
return {
|
|
40
|
+
...initialLoadingState
|
|
41
|
+
};
|
|
42
|
+
default:
|
|
43
|
+
return state;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const useInterpretationsManager = () => {
|
|
47
|
+
const interpretationsManager = (0, _react.useContext)(_InterpretationsProvider.InterpretationsContext);
|
|
48
|
+
if (!interpretationsManager) {
|
|
49
|
+
throw new Error('Called useInterpretationsManager() from outside an InterpretationsProvider');
|
|
50
|
+
}
|
|
51
|
+
return interpretationsManager;
|
|
52
|
+
};
|
|
53
|
+
exports.useInterpretationsManager = useInterpretationsManager;
|
|
54
|
+
const useInterpretationsCurrentUser = () => {
|
|
55
|
+
const interpretationsManager = useInterpretationsManager();
|
|
56
|
+
return interpretationsManager.getCurrentUser();
|
|
57
|
+
};
|
|
58
|
+
exports.useInterpretationsCurrentUser = useInterpretationsCurrentUser;
|
|
59
|
+
const useInterpretationsList = (type, id) => {
|
|
60
|
+
const prevTypeRef = (0, _react.useRef)(null);
|
|
61
|
+
const prevIdRef = (0, _react.useRef)(null);
|
|
62
|
+
const interpretationsManager = useInterpretationsManager();
|
|
63
|
+
const [state, dispatch] = (0, _react.useReducer)(loadingReducer, initialLoadingState);
|
|
64
|
+
const fetchList = (0, _react.useCallback)(async () => {
|
|
65
|
+
dispatch({
|
|
66
|
+
type: SET_LOADING
|
|
67
|
+
});
|
|
68
|
+
try {
|
|
69
|
+
const data = await interpretationsManager.loadInterpretationsForVisualization(type, id);
|
|
70
|
+
dispatch({
|
|
71
|
+
type: SET_DATA,
|
|
72
|
+
payload: data
|
|
73
|
+
});
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error(error);
|
|
76
|
+
dispatch({
|
|
77
|
+
type: SET_ERROR,
|
|
78
|
+
payload: error
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}, [interpretationsManager, type, id, dispatch]);
|
|
82
|
+
|
|
83
|
+
// Ensure manager updates get propagated to the state
|
|
84
|
+
(0, _react.useEffect)(() => {
|
|
85
|
+
const unsubscribe = interpretationsManager.subscribeToInterpretationsListUpdates(interpretationIdsByDate => {
|
|
86
|
+
dispatch({
|
|
87
|
+
type: SET_DATA,
|
|
88
|
+
payload: interpretationIdsByDate
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return unsubscribe;
|
|
92
|
+
}, [interpretationsManager]);
|
|
93
|
+
|
|
94
|
+
// Fetch when mounting or after a reset
|
|
95
|
+
(0, _react.useEffect)(() => {
|
|
96
|
+
if (type && id && !state.loading && !state.data && !state.error) {
|
|
97
|
+
fetchList();
|
|
98
|
+
}
|
|
99
|
+
}, [fetchList, state, type, id]);
|
|
100
|
+
|
|
101
|
+
// Handle active item changes and clearance
|
|
102
|
+
(0, _react.useEffect)(() => {
|
|
103
|
+
const prevType = prevTypeRef.current;
|
|
104
|
+
const prevId = prevIdRef.current;
|
|
105
|
+
const isTypeChange = prevType && type && prevType !== type;
|
|
106
|
+
const isIdChange = prevId && id && prevId !== id;
|
|
107
|
+
const isTypeClearance = prevType && !type;
|
|
108
|
+
const isIdClearance = prevId && !id;
|
|
109
|
+
if (isTypeChange || isIdChange || isTypeClearance || isIdClearance) {
|
|
110
|
+
dispatch({
|
|
111
|
+
type: RESET
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (isTypeClearance || isIdClearance) {
|
|
115
|
+
interpretationsManager.clearInterpretations();
|
|
116
|
+
}
|
|
117
|
+
prevTypeRef.current = type;
|
|
118
|
+
prevIdRef.current = id;
|
|
119
|
+
}, [interpretationsManager, type, id]);
|
|
120
|
+
return state;
|
|
121
|
+
};
|
|
122
|
+
exports.useInterpretationsList = useInterpretationsList;
|
|
123
|
+
const useActiveInterpretation = id => {
|
|
124
|
+
const prevIdRef = (0, _react.useRef)(null);
|
|
125
|
+
const interpretationsManager = useInterpretationsManager();
|
|
126
|
+
const [state, dispatch] = (0, _react.useReducer)(loadingReducer, initialLoadingState);
|
|
127
|
+
const fetchInterpretation = (0, _react.useCallback)(async () => {
|
|
128
|
+
dispatch({
|
|
129
|
+
type: SET_LOADING
|
|
130
|
+
});
|
|
131
|
+
try {
|
|
132
|
+
const data = await interpretationsManager.loadActiveInterpretation(id);
|
|
133
|
+
dispatch({
|
|
134
|
+
type: SET_DATA,
|
|
135
|
+
payload: data
|
|
136
|
+
});
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error(error);
|
|
139
|
+
dispatch({
|
|
140
|
+
type: SET_ERROR,
|
|
141
|
+
payload: error
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}, [interpretationsManager, id, dispatch]);
|
|
145
|
+
|
|
146
|
+
// Ensure manager updates get propagated to the state
|
|
147
|
+
(0, _react.useEffect)(() => {
|
|
148
|
+
const unsubscribe = interpretationsManager.subscribeToInterpretationUpdates(id, interpretation => {
|
|
149
|
+
dispatch({
|
|
150
|
+
type: SET_DATA,
|
|
151
|
+
payload: interpretation
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
return unsubscribe;
|
|
155
|
+
}, [interpretationsManager, id]);
|
|
156
|
+
|
|
157
|
+
// Fetch when mounting or after a reset
|
|
158
|
+
(0, _react.useEffect)(() => {
|
|
159
|
+
if (id && !state.loading && !state.data && !state.error) {
|
|
160
|
+
fetchInterpretation();
|
|
161
|
+
}
|
|
162
|
+
}, [fetchInterpretation, state, id]);
|
|
163
|
+
|
|
164
|
+
// Handle active item changes and clearance
|
|
165
|
+
(0, _react.useEffect)(() => {
|
|
166
|
+
const prevId = prevIdRef.current;
|
|
167
|
+
const isIdChange = prevId && id && prevId !== id;
|
|
168
|
+
const isIdClearance = prevId && !id;
|
|
169
|
+
if (isIdChange || isIdClearance) {
|
|
170
|
+
dispatch({
|
|
171
|
+
type: RESET
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (isIdClearance) {
|
|
175
|
+
interpretationsManager.clearActiveInterpretation();
|
|
176
|
+
}
|
|
177
|
+
prevIdRef.current = id;
|
|
178
|
+
}, [id, interpretationsManager]);
|
|
179
|
+
return state;
|
|
180
|
+
};
|
|
181
|
+
exports.useActiveInterpretation = useActiveInterpretation;
|
|
182
|
+
const useInterpretation = id => {
|
|
183
|
+
const interpretationsManager = useInterpretationsManager();
|
|
184
|
+
const [interpretation, setInterpretation] = (0, _react.useState)(interpretationsManager.getInterpretation(id));
|
|
185
|
+
(0, _react.useEffect)(() => {
|
|
186
|
+
const unsubscribe = interpretationsManager.subscribeToInterpretationUpdates(id, newInterpretation => {
|
|
187
|
+
setInterpretation(newInterpretation);
|
|
188
|
+
});
|
|
189
|
+
return unsubscribe;
|
|
190
|
+
}, [interpretationsManager, id]);
|
|
191
|
+
return interpretation;
|
|
192
|
+
};
|
|
193
|
+
exports.useInterpretation = useInterpretation;
|
|
194
|
+
const useLike = id => {
|
|
195
|
+
const interpretationsManager = useInterpretationsManager();
|
|
196
|
+
const [{
|
|
197
|
+
loading: toggleLikeInProgress,
|
|
198
|
+
data: interpretation
|
|
199
|
+
}, dispatch] = (0, _react.useReducer)(loadingReducer, {
|
|
200
|
+
...initialLoadingState,
|
|
201
|
+
data: interpretationsManager.getInterpretation(id)
|
|
202
|
+
});
|
|
203
|
+
const toggleLike = (0, _react.useCallback)(async () => {
|
|
204
|
+
dispatch({
|
|
205
|
+
type: SET_LOADING
|
|
206
|
+
});
|
|
207
|
+
try {
|
|
208
|
+
const data = await interpretationsManager.toggleInterpretationLike(id);
|
|
209
|
+
dispatch({
|
|
210
|
+
type: SET_DATA,
|
|
211
|
+
payload: data
|
|
212
|
+
});
|
|
213
|
+
} catch (error) {
|
|
214
|
+
console.error(error);
|
|
215
|
+
dispatch({
|
|
216
|
+
type: SET_ERROR,
|
|
217
|
+
payload: error
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}, [id, interpretationsManager]);
|
|
221
|
+
const isLikedByCurrentUser = (0, _react.useMemo)(() => {
|
|
222
|
+
const currentUser = interpretationsManager.getCurrentUser();
|
|
223
|
+
return interpretation.likedBy.some(likedBy => likedBy.id === currentUser.id);
|
|
224
|
+
}, [interpretation, interpretationsManager]);
|
|
225
|
+
return {
|
|
226
|
+
isLikedByCurrentUser,
|
|
227
|
+
toggleLike,
|
|
228
|
+
toggleLikeInProgress
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
exports.useLike = useLike;
|
|
232
|
+
const useInterpretationAccess = interpretation => {
|
|
233
|
+
const currentUser = useInterpretationsCurrentUser();
|
|
234
|
+
const access = (0, _react.useMemo)(() => (0, _getInterpretationAccess.getInterpretationAccess)(interpretation, currentUser), [interpretation, currentUser]);
|
|
235
|
+
return access;
|
|
236
|
+
};
|
|
237
|
+
exports.useInterpretationAccess = useInterpretationAccess;
|
|
238
|
+
const useCommentAccess = (comment, canComment) => {
|
|
239
|
+
const currentUser = useInterpretationsCurrentUser();
|
|
240
|
+
const access = (0, _react.useMemo)(() => (0, _getInterpretationAccess.getCommentAccess)(comment, canComment, currentUser), [comment, canComment, currentUser]);
|
|
241
|
+
return access;
|
|
242
|
+
};
|
|
243
|
+
exports.useCommentAccess = useCommentAccess;
|
|
244
|
+
const useInterpretationsManagerMutation = (methodName, options = {}) => {
|
|
245
|
+
const interpretationsManager = useInterpretationsManager();
|
|
246
|
+
const [state, dispatch] = (0, _react.useReducer)(loadingReducer, initialLoadingState);
|
|
247
|
+
const doAsyncCallback = (0, _react.useCallback)(async () => {
|
|
248
|
+
dispatch({
|
|
249
|
+
type: SET_LOADING
|
|
250
|
+
});
|
|
251
|
+
try {
|
|
252
|
+
const data = await interpretationsManager[methodName](options);
|
|
253
|
+
dispatch({
|
|
254
|
+
type: SET_DATA,
|
|
255
|
+
payload: data
|
|
256
|
+
});
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error(error);
|
|
259
|
+
dispatch({
|
|
260
|
+
type: SET_ERROR,
|
|
261
|
+
payload: error
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}, [interpretationsManager, methodName, options]);
|
|
265
|
+
return [doAsyncCallback, state];
|
|
266
|
+
};
|
|
267
|
+
const useCreateInterpretation = options => useInterpretationsManagerMutation('createInterpretation', options);
|
|
268
|
+
exports.useCreateInterpretation = useCreateInterpretation;
|
|
269
|
+
const useUpdateInterpretationText = options => useInterpretationsManagerMutation('updateInterpretationText', options);
|
|
270
|
+
exports.useUpdateInterpretationText = useUpdateInterpretationText;
|
|
271
|
+
const useDeleteInterpretation = options => useInterpretationsManagerMutation('deleteInterpretation', options);
|
|
272
|
+
exports.useDeleteInterpretation = useDeleteInterpretation;
|
|
273
|
+
const useAddCommentToActiveInterpretation = options => useInterpretationsManagerMutation('addCommentToActiveInterpretation', options);
|
|
274
|
+
exports.useAddCommentToActiveInterpretation = useAddCommentToActiveInterpretation;
|
|
275
|
+
const useUpdateCommentForActiveInterpretation = options => useInterpretationsManagerMutation('updateCommentForActiveInterpretation', options);
|
|
276
|
+
exports.useUpdateCommentForActiveInterpretation = useUpdateCommentForActiveInterpretation;
|
|
277
|
+
const useDeleteCommentFromActiveInterpretation = options => useInterpretationsManagerMutation('deleteCommentFromActiveInterpretation', options);
|
|
278
|
+
exports.useDeleteCommentFromActiveInterpretation = useDeleteCommentFromActiveInterpretation;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "InterpretationsProvider", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _InterpretationsProvider.InterpretationsProvider;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _InterpretationsProvider = require("./InterpretationsProvider.js");
|
|
@@ -4,64 +4,61 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.InterpretationForm = void 0;
|
|
7
|
-
var _appRuntime = require("@dhis2/app-runtime");
|
|
8
7
|
var _d2I18n = _interopRequireDefault(require("@dhis2/d2-i18n"));
|
|
9
8
|
var _ui = require("@dhis2/ui");
|
|
10
9
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
11
|
var _index = require("../../RichText/index.js");
|
|
13
12
|
var _index2 = require("../common/index.js");
|
|
13
|
+
var _hooks = require("../InterpretationsProvider/hooks.js");
|
|
14
14
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
15
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
16
|
const InterpretationForm = ({
|
|
17
17
|
type,
|
|
18
18
|
id,
|
|
19
|
-
currentUser,
|
|
20
19
|
disabled,
|
|
21
|
-
showNoTimeDimensionHelpText
|
|
22
|
-
onSave
|
|
20
|
+
showNoTimeDimensionHelpText
|
|
23
21
|
}) => {
|
|
24
22
|
const [showRichTextEditor, setShowRichTextEditor] = (0, _react.useState)(false);
|
|
25
|
-
const [
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}) => interpretationText
|
|
32
|
-
});
|
|
23
|
+
const [text, setText] = (0, _react.useState)('');
|
|
24
|
+
const onComplete = (0, _react.useCallback)(() => {
|
|
25
|
+
setShowRichTextEditor(false);
|
|
26
|
+
setText('');
|
|
27
|
+
}, []);
|
|
28
|
+
const currentUser = (0, _hooks.useInterpretationsCurrentUser)();
|
|
33
29
|
const [save, {
|
|
34
|
-
loading
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
loading,
|
|
31
|
+
error
|
|
32
|
+
}] = (0, _hooks.useCreateInterpretation)({
|
|
33
|
+
type,
|
|
34
|
+
id,
|
|
35
|
+
text,
|
|
36
|
+
onComplete
|
|
41
37
|
});
|
|
42
38
|
const inputPlaceholder = _d2I18n.default.t('Write an interpretation');
|
|
43
39
|
return /*#__PURE__*/_react.default.createElement(_index2.MessageEditorContainer, {
|
|
44
|
-
|
|
40
|
+
currentUserName: currentUser.name,
|
|
45
41
|
dataTest: "interpretation-form"
|
|
46
42
|
}, showRichTextEditor ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_index.RichTextEditor, {
|
|
47
|
-
disabled:
|
|
43
|
+
disabled: loading,
|
|
48
44
|
inputPlaceholder: inputPlaceholder,
|
|
49
|
-
onChange:
|
|
50
|
-
value:
|
|
45
|
+
onChange: setText,
|
|
46
|
+
value: text,
|
|
47
|
+
errorText: error ? _d2I18n.default.t('Could not post interpretation') : '',
|
|
51
48
|
helpText: showNoTimeDimensionHelpText ? _d2I18n.default.t('Other people viewing this interpretation in the future may see more data.') : undefined
|
|
52
49
|
}), /*#__PURE__*/_react.default.createElement(_index2.MessageButtonStrip, null, /*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
53
50
|
primary: true,
|
|
54
51
|
small: true,
|
|
55
|
-
loading:
|
|
52
|
+
loading: loading,
|
|
56
53
|
onClick: () => save({
|
|
57
|
-
interpretationText
|
|
54
|
+
interpretationText: text
|
|
58
55
|
})
|
|
59
56
|
}, _d2I18n.default.t('Post interpretation')), /*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
60
57
|
secondary: true,
|
|
61
58
|
small: true,
|
|
62
|
-
disabled:
|
|
59
|
+
disabled: loading,
|
|
63
60
|
onClick: () => {
|
|
64
|
-
|
|
61
|
+
setText('');
|
|
65
62
|
setShowRichTextEditor(false);
|
|
66
63
|
}
|
|
67
64
|
}, _d2I18n.default.t('Cancel')))) : /*#__PURE__*/_react.default.createElement(_ui.Input, {
|
|
@@ -72,10 +69,8 @@ const InterpretationForm = ({
|
|
|
72
69
|
};
|
|
73
70
|
exports.InterpretationForm = InterpretationForm;
|
|
74
71
|
InterpretationForm.propTypes = {
|
|
75
|
-
currentUser: _propTypes.default.object,
|
|
76
72
|
disabled: _propTypes.default.bool,
|
|
77
73
|
id: _propTypes.default.string,
|
|
78
74
|
showNoTimeDimensionHelpText: _propTypes.default.bool,
|
|
79
|
-
type: _propTypes.default.string
|
|
80
|
-
onSave: _propTypes.default.func
|
|
75
|
+
type: _propTypes.default.string
|
|
81
76
|
};
|
|
@@ -12,43 +12,20 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
12
12
|
var _react = _interopRequireDefault(require("react"));
|
|
13
13
|
var _index = require("../common/index.js");
|
|
14
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
const sortByCreatedDateDesc = (a, b) => {
|
|
16
|
-
const dateA = a.created;
|
|
17
|
-
const dateB = b.created;
|
|
18
|
-
if (dateA < dateB) {
|
|
19
|
-
return 1;
|
|
20
|
-
}
|
|
21
|
-
if (dateA > dateB) {
|
|
22
|
-
return -1;
|
|
23
|
-
}
|
|
24
|
-
return 0;
|
|
25
|
-
};
|
|
26
15
|
const InterpretationList = ({
|
|
27
|
-
|
|
28
|
-
interpretations,
|
|
16
|
+
interpretationIdsByDate,
|
|
29
17
|
onInterpretationClick,
|
|
30
|
-
onLikeToggled,
|
|
31
18
|
onReplyIconClick,
|
|
32
|
-
refresh,
|
|
33
19
|
disabled,
|
|
34
20
|
dashboardRedirectUrl
|
|
35
21
|
}) => {
|
|
36
22
|
const {
|
|
37
23
|
fromServerDate
|
|
38
24
|
} = (0, _appRuntime.useTimeZoneConversion)();
|
|
39
|
-
const interpretationsByDate = interpretations.reduce((groupedInterpretations, interpretation) => {
|
|
40
|
-
const date = interpretation.created.split('T')[0];
|
|
41
|
-
if (date in groupedInterpretations) {
|
|
42
|
-
groupedInterpretations[date].push(interpretation);
|
|
43
|
-
} else {
|
|
44
|
-
groupedInterpretations[date] = [interpretation];
|
|
45
|
-
}
|
|
46
|
-
return groupedInterpretations;
|
|
47
|
-
}, {});
|
|
48
25
|
return /*#__PURE__*/_react.default.createElement("ol", {
|
|
49
26
|
"data-test": "interpretations-list",
|
|
50
27
|
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-groups"
|
|
51
|
-
}, Object.keys(
|
|
28
|
+
}, Object.keys(interpretationIdsByDate).map(date => /*#__PURE__*/_react.default.createElement("li", {
|
|
52
29
|
key: date,
|
|
53
30
|
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]]])
|
|
54
31
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -60,17 +37,13 @@ const InterpretationList = ({
|
|
|
60
37
|
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"
|
|
61
38
|
}, (0, _moment.default)(fromServerDate(date)).format('ll'))), /*#__PURE__*/_react.default.createElement("ol", {
|
|
62
39
|
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"
|
|
63
|
-
},
|
|
64
|
-
key:
|
|
65
|
-
|
|
66
|
-
currentUser: currentUser,
|
|
67
|
-
onClick: onInterpretationClick,
|
|
68
|
-
onLikeToggled: onLikeToggled,
|
|
40
|
+
}, interpretationIdsByDate[date].map(interpretationId => /*#__PURE__*/_react.default.createElement(_index.Interpretation, {
|
|
41
|
+
key: interpretationId,
|
|
42
|
+
id: interpretationId,
|
|
69
43
|
onReplyIconClick: onReplyIconClick,
|
|
70
|
-
|
|
71
|
-
onUpdated: refresh,
|
|
44
|
+
dashboardRedirectUrl: dashboardRedirectUrl,
|
|
72
45
|
disabled: disabled,
|
|
73
|
-
|
|
46
|
+
onClick: onInterpretationClick
|
|
74
47
|
}))))), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
75
48
|
id: "4058400613",
|
|
76
49
|
dynamic: [_ui.spacers.dp8, _ui.spacers.dp8, _ui.spacers.dp16, _ui.colors.grey800, _ui.spacers.dp12, _ui.spacers.dp12, _ui.spacers.dp32, _ui.spacers.dp4]
|
|
@@ -78,11 +51,8 @@ const InterpretationList = ({
|
|
|
78
51
|
};
|
|
79
52
|
exports.InterpretationList = InterpretationList;
|
|
80
53
|
InterpretationList.propTypes = {
|
|
81
|
-
|
|
82
|
-
interpretations: _propTypes.default.array.isRequired,
|
|
83
|
-
refresh: _propTypes.default.func.isRequired,
|
|
54
|
+
interpretationIdsByDate: _propTypes.default.objectOf(_propTypes.default.arrayOf(_propTypes.default.string)).isRequired,
|
|
84
55
|
onInterpretationClick: _propTypes.default.func.isRequired,
|
|
85
|
-
onLikeToggled: _propTypes.default.func.isRequired,
|
|
86
56
|
onReplyIconClick: _propTypes.default.func.isRequired,
|
|
87
57
|
dashboardRedirectUrl: _propTypes.default.string,
|
|
88
58
|
disabled: _propTypes.default.bool
|
|
@@ -5,126 +5,75 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.InterpretationsUnit = void 0;
|
|
7
7
|
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
-
var _appRuntime = require("@dhis2/app-runtime");
|
|
9
8
|
var _d2I18n = _interopRequireDefault(require("@dhis2/d2-i18n"));
|
|
10
9
|
var _ui = require("@dhis2/ui");
|
|
11
10
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
12
11
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
12
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _hooks = require("../InterpretationsProvider/hooks.js");
|
|
14
14
|
var _InterpretationForm = require("./InterpretationForm.js");
|
|
15
15
|
var _InterpretationList = require("./InterpretationList.js");
|
|
16
16
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
17
17
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
const
|
|
19
|
-
interpretations: {
|
|
20
|
-
resource: 'interpretations',
|
|
21
|
-
params: ({
|
|
22
|
-
type,
|
|
23
|
-
id
|
|
24
|
-
}) => ({
|
|
25
|
-
fields: ['access[write,manage]', 'id', 'createdBy[id,displayName]', 'created', 'text', 'comments[id]', 'likes', 'likedBy[id]'],
|
|
26
|
-
filter: `${type}.id:eq:${id}`
|
|
27
|
-
})
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
const InterpretationsUnit = exports.InterpretationsUnit = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
31
|
-
currentUser,
|
|
18
|
+
const InterpretationsUnit = ({
|
|
32
19
|
type,
|
|
33
20
|
id,
|
|
34
21
|
visualizationHasTimeDimension = true,
|
|
35
|
-
onInterpretationClick
|
|
22
|
+
onInterpretationClick,
|
|
36
23
|
onReplyIconClick,
|
|
37
24
|
disabled,
|
|
38
|
-
renderId,
|
|
39
25
|
dashboardRedirectUrl
|
|
40
|
-
}
|
|
26
|
+
}) => {
|
|
41
27
|
const [isExpanded, setIsExpanded] = (0, _react.useState)(true);
|
|
42
|
-
const [interpretations, setInterpretations] = (0, _react.useState)([]);
|
|
43
28
|
const showNoTimeDimensionHelpText = type === 'eventVisualization' && !visualizationHasTimeDimension;
|
|
44
29
|
const {
|
|
30
|
+
data: interpretationIdsByDate,
|
|
45
31
|
loading,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} = (0, _appRuntime.useDataQuery)(interpretationsQuery, {
|
|
49
|
-
lazy: true,
|
|
50
|
-
onComplete: data => setInterpretations(data.interpretations.interpretations)
|
|
51
|
-
});
|
|
52
|
-
const onCompleteAction = (0, _react.useCallback)(() => {
|
|
53
|
-
refetch({
|
|
54
|
-
type,
|
|
55
|
-
id
|
|
56
|
-
});
|
|
57
|
-
}, [type, id, refetch]);
|
|
58
|
-
(0, _react.useImperativeHandle)(ref, () => ({
|
|
59
|
-
refresh: onCompleteAction
|
|
60
|
-
}), [onCompleteAction]);
|
|
61
|
-
(0, _react.useEffect)(() => {
|
|
62
|
-
if (id) {
|
|
63
|
-
refetch({
|
|
64
|
-
type,
|
|
65
|
-
id
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}, [type, id, renderId, refetch]);
|
|
69
|
-
const onLikeToggled = ({
|
|
70
|
-
id,
|
|
71
|
-
likedBy
|
|
72
|
-
}) => {
|
|
73
|
-
const interpretation = interpretations.find(interp => interp.id === id);
|
|
74
|
-
interpretation.likedBy = likedBy;
|
|
75
|
-
interpretation.likes = likedBy.length;
|
|
76
|
-
};
|
|
32
|
+
error
|
|
33
|
+
} = (0, _hooks.useInterpretationsList)(type, id);
|
|
77
34
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
78
|
-
className: _style.default.dynamic([["
|
|
35
|
+
className: _style.default.dynamic([["2008120072", [_ui.spacers.dp16, _ui.colors.grey400, _ui.colors.white, _ui.spacers.dp32, _ui.colors.grey900]]]) + " " + ((0, _classnames.default)('container', {
|
|
79
36
|
expanded: isExpanded
|
|
80
37
|
}) || "")
|
|
81
|
-
},
|
|
82
|
-
className: _style.default.dynamic([["4120713286", [_ui.spacers.dp16, _ui.colors.grey400, _ui.colors.white, _ui.spacers.dp32, _ui.colors.grey900]]]) + " " + "fetching-loader"
|
|
83
|
-
}, /*#__PURE__*/_react.default.createElement(_ui.CircularLoader, {
|
|
84
|
-
small: true
|
|
85
|
-
})), /*#__PURE__*/_react.default.createElement("div", {
|
|
38
|
+
}, /*#__PURE__*/_react.default.createElement("button", {
|
|
86
39
|
onClick: () => setIsExpanded(!isExpanded),
|
|
87
|
-
className: _style.default.dynamic([["
|
|
40
|
+
className: _style.default.dynamic([["2008120072", [_ui.spacers.dp16, _ui.colors.grey400, _ui.colors.white, _ui.spacers.dp32, _ui.colors.grey900]]]) + " " + "header"
|
|
88
41
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
89
|
-
className: _style.default.dynamic([["
|
|
42
|
+
className: _style.default.dynamic([["2008120072", [_ui.spacers.dp16, _ui.colors.grey400, _ui.colors.white, _ui.spacers.dp32, _ui.colors.grey900]]]) + " " + "title"
|
|
90
43
|
}, _d2I18n.default.t('Interpretations')), isExpanded ? /*#__PURE__*/_react.default.createElement(_ui.IconChevronUp24, {
|
|
91
44
|
color: _ui.colors.grey700
|
|
92
45
|
}) : /*#__PURE__*/_react.default.createElement(_ui.IconChevronDown24, {
|
|
93
46
|
color: _ui.colors.grey700
|
|
94
47
|
})), isExpanded && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, loading && /*#__PURE__*/_react.default.createElement("div", {
|
|
95
|
-
className: _style.default.dynamic([["
|
|
48
|
+
className: _style.default.dynamic([["2008120072", [_ui.spacers.dp16, _ui.colors.grey400, _ui.colors.white, _ui.spacers.dp32, _ui.colors.grey900]]]) + " " + "loader"
|
|
96
49
|
}, /*#__PURE__*/_react.default.createElement(_ui.CircularLoader, {
|
|
97
50
|
small: true
|
|
98
|
-
})),
|
|
99
|
-
|
|
51
|
+
})), error && /*#__PURE__*/_react.default.createElement(_ui.NoticeBox, {
|
|
52
|
+
error: true,
|
|
53
|
+
title: _d2I18n.default.t('Error loading interpretations')
|
|
54
|
+
}, error.message || _d2I18n.default.t('Could not load interpretations')), interpretationIdsByDate && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_InterpretationForm.InterpretationForm, {
|
|
100
55
|
type: type,
|
|
101
56
|
id: id,
|
|
102
|
-
onSave: onCompleteAction,
|
|
103
57
|
disabled: disabled,
|
|
104
58
|
showNoTimeDimensionHelpText: showNoTimeDimensionHelpText
|
|
105
59
|
}), /*#__PURE__*/_react.default.createElement(_InterpretationList.InterpretationList, {
|
|
106
|
-
|
|
107
|
-
interpretations: interpretations,
|
|
60
|
+
interpretationIdsByDate: interpretationIdsByDate,
|
|
108
61
|
onInterpretationClick: onInterpretationClick,
|
|
109
|
-
onLikeToggled: onLikeToggled,
|
|
110
62
|
onReplyIconClick: onReplyIconClick,
|
|
111
|
-
refresh: onCompleteAction,
|
|
112
63
|
disabled: disabled,
|
|
113
64
|
dashboardRedirectUrl: dashboardRedirectUrl
|
|
114
65
|
}))), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
115
|
-
id: "
|
|
66
|
+
id: "2008120072",
|
|
116
67
|
dynamic: [_ui.spacers.dp16, _ui.colors.grey400, _ui.colors.white, _ui.spacers.dp32, _ui.colors.grey900]
|
|
117
|
-
}, [`.container.__jsx-style-dynamic-selector{position:relative;padding:${_ui.spacers.dp16};border-bottom:1px solid ${_ui.colors.grey400};background-color:${_ui.colors.white};}`,
|
|
118
|
-
}
|
|
119
|
-
InterpretationsUnit
|
|
68
|
+
}, [`.container.__jsx-style-dynamic-selector{position:relative;padding:${_ui.spacers.dp16};border-bottom:1px solid ${_ui.colors.grey400};background-color:${_ui.colors.white};}`, `.expanded.__jsx-style-dynamic-selector{padding-bottom:${_ui.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{all:unset;inline-size:100%;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:${_ui.colors.grey900};}`]));
|
|
69
|
+
};
|
|
70
|
+
exports.InterpretationsUnit = InterpretationsUnit;
|
|
120
71
|
InterpretationsUnit.propTypes = {
|
|
121
|
-
currentUser: _propTypes.default.object.isRequired,
|
|
122
72
|
id: _propTypes.default.string.isRequired,
|
|
123
73
|
type: _propTypes.default.string.isRequired,
|
|
74
|
+
onInterpretationClick: _propTypes.default.func.isRequired,
|
|
124
75
|
dashboardRedirectUrl: _propTypes.default.string,
|
|
125
76
|
disabled: _propTypes.default.bool,
|
|
126
|
-
renderId: _propTypes.default.number,
|
|
127
77
|
visualizationHasTimeDimension: _propTypes.default.bool,
|
|
128
|
-
onInterpretationClick: _propTypes.default.func,
|
|
129
78
|
onReplyIconClick: _propTypes.default.func
|
|
130
79
|
};
|