@dhis2/analytics 27.0.0 → 28.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__/PivotTable.stories.js +116 -92
- package/build/cjs/components/FileMenu/__tests__/utils.spec.js +18 -91
- package/build/cjs/components/FileMenu/utils.js +5 -29
- package/build/cjs/modules/pivotTable/PivotTableEngine.js +20 -3
- package/build/es/__demo__/PivotTable.stories.js +114 -91
- package/build/es/components/FileMenu/__tests__/utils.spec.js +18 -91
- package/build/es/components/FileMenu/utils.js +6 -30
- package/build/es/modules/pivotTable/PivotTableEngine.js +20 -3
- package/package.json +1 -1
|
@@ -87,92 +87,37 @@ describe('utils', () => {
|
|
|
87
87
|
});
|
|
88
88
|
});
|
|
89
89
|
describe('preparePayloadForSave', () => {
|
|
90
|
-
|
|
91
|
-
query: jest.fn()
|
|
92
|
-
};
|
|
93
|
-
beforeEach(() => {
|
|
94
|
-
jest.clearAllMocks();
|
|
95
|
-
});
|
|
96
|
-
it('fetches subscribers and adds them to the visualization', async () => {
|
|
97
|
-
const visualization = {
|
|
98
|
-
id: '123',
|
|
99
|
-
type: 'BAR',
|
|
100
|
-
name: 'Existing Name',
|
|
101
|
-
description: 'Existing Description'
|
|
102
|
-
};
|
|
103
|
-
mockEngine.query.mockResolvedValue({
|
|
104
|
-
ao: {
|
|
105
|
-
subscribers: ['user1', 'user2']
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
const result = await preparePayloadForSave({
|
|
109
|
-
visualization,
|
|
110
|
-
engine: mockEngine
|
|
111
|
-
});
|
|
112
|
-
expect(mockEngine.query).toHaveBeenCalledWith({
|
|
113
|
-
ao: {
|
|
114
|
-
resource: 'visualizations',
|
|
115
|
-
id: expect.any(Function),
|
|
116
|
-
params: {
|
|
117
|
-
fields: 'subscribers'
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}, {
|
|
121
|
-
variables: {
|
|
122
|
-
id: '123'
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
expect(result.subscribers).toEqual(['user1', 'user2']);
|
|
126
|
-
});
|
|
127
|
-
it('sets the name to the provided name', async () => {
|
|
90
|
+
it('sets the name to the provided name', () => {
|
|
128
91
|
const visualization = {
|
|
129
92
|
id: '123',
|
|
130
93
|
type: 'MAP',
|
|
131
94
|
name: 'Existing name'
|
|
132
95
|
};
|
|
133
96
|
const name = 'New Name';
|
|
134
|
-
|
|
135
|
-
ao: {
|
|
136
|
-
subscribers: []
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
const result = await preparePayloadForSave({
|
|
97
|
+
const result = preparePayloadForSave({
|
|
140
98
|
visualization,
|
|
141
|
-
name
|
|
142
|
-
engine: mockEngine
|
|
99
|
+
name
|
|
143
100
|
});
|
|
144
101
|
expect(result.name).toBe(name);
|
|
145
102
|
});
|
|
146
|
-
it('sets the name to the existing name if no new name is provided',
|
|
103
|
+
it('sets the name to the existing name if no new name is provided', () => {
|
|
147
104
|
const visualization = {
|
|
148
105
|
id: '123',
|
|
149
106
|
type: 'LINE_LIST',
|
|
150
107
|
name: 'Existing Name'
|
|
151
108
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
subscribers: []
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
const result = await preparePayloadForSave({
|
|
158
|
-
visualization,
|
|
159
|
-
engine: mockEngine
|
|
109
|
+
const result = preparePayloadForSave({
|
|
110
|
+
visualization
|
|
160
111
|
});
|
|
161
112
|
expect(result.name).toBe('Existing Name');
|
|
162
113
|
});
|
|
163
|
-
it('sets the name to a default value if no name is provided',
|
|
114
|
+
it('sets the name to a default value if no name is provided', () => {
|
|
164
115
|
const visualization = {
|
|
165
116
|
id: '123',
|
|
166
117
|
type: 'BAR'
|
|
167
118
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
subscribers: []
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
const result = await preparePayloadForSave({
|
|
174
|
-
visualization,
|
|
175
|
-
engine: mockEngine
|
|
119
|
+
const result = preparePayloadForSave({
|
|
120
|
+
visualization
|
|
176
121
|
});
|
|
177
122
|
const expectedName = `Untitled Bar, ${new Date().toLocaleDateString(undefined, {
|
|
178
123
|
year: 'numeric',
|
|
@@ -181,55 +126,37 @@ describe('utils', () => {
|
|
|
181
126
|
})}`;
|
|
182
127
|
expect(result.name).toBe(expectedName);
|
|
183
128
|
});
|
|
184
|
-
it('sets the description to the provided description',
|
|
129
|
+
it('sets the description to the provided description', () => {
|
|
185
130
|
const visualization = {
|
|
186
131
|
id: '123',
|
|
187
132
|
type: 'YEAR_OVER_YEAR_LINE',
|
|
188
133
|
description: 'Existing Description'
|
|
189
134
|
};
|
|
190
135
|
const description = 'New Description';
|
|
191
|
-
|
|
192
|
-
ao: {
|
|
193
|
-
subscribers: []
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
const result = await preparePayloadForSave({
|
|
136
|
+
const result = preparePayloadForSave({
|
|
197
137
|
visualization,
|
|
198
|
-
description
|
|
199
|
-
engine: mockEngine
|
|
138
|
+
description
|
|
200
139
|
});
|
|
201
140
|
expect(result.description).toBe(description);
|
|
202
141
|
});
|
|
203
|
-
it('keeps the existing description if no new description is provided',
|
|
142
|
+
it('keeps the existing description if no new description is provided', () => {
|
|
204
143
|
const visualization = {
|
|
205
144
|
id: '123',
|
|
206
145
|
type: 'COLUMN',
|
|
207
146
|
description: 'Existing Description'
|
|
208
147
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
subscribers: []
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
const result = await preparePayloadForSave({
|
|
215
|
-
visualization,
|
|
216
|
-
engine: mockEngine
|
|
148
|
+
const result = preparePayloadForSave({
|
|
149
|
+
visualization
|
|
217
150
|
});
|
|
218
151
|
expect(result.description).toBe('Existing Description');
|
|
219
152
|
});
|
|
220
|
-
it('sets the description to undefined if no description is provided and none exists',
|
|
153
|
+
it('sets the description to undefined if no description is provided and none exists', () => {
|
|
221
154
|
const visualization = {
|
|
222
155
|
id: '123',
|
|
223
156
|
type: 'BAR'
|
|
224
157
|
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
subscribers: []
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
const result = await preparePayloadForSave({
|
|
231
|
-
visualization,
|
|
232
|
-
engine: mockEngine
|
|
158
|
+
const result = preparePayloadForSave({
|
|
159
|
+
visualization
|
|
233
160
|
});
|
|
234
161
|
expect(result.description).toBeUndefined();
|
|
235
162
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import i18n from '@dhis2/d2-i18n';
|
|
2
|
-
import { getDisplayNameByVisType
|
|
2
|
+
import { getDisplayNameByVisType } from '../../modules/visTypes.js';
|
|
3
3
|
export const FILE_TYPE_EVENT_REPORT = 'eventReport';
|
|
4
4
|
export const FILE_TYPE_VISUALIZATION = 'visualization';
|
|
5
5
|
export const FILE_TYPE_MAP = 'map';
|
|
@@ -54,38 +54,12 @@ export const preparePayloadForSaveAs = _ref => {
|
|
|
54
54
|
visualization.description = description !== undefined ? description : visualization.description;
|
|
55
55
|
return visualization;
|
|
56
56
|
};
|
|
57
|
-
const
|
|
58
|
-
ao: {
|
|
59
|
-
resource: getApiEndpointByVisType(type),
|
|
60
|
-
id: _ref2 => {
|
|
61
|
-
let {
|
|
62
|
-
id
|
|
63
|
-
} = _ref2;
|
|
64
|
-
return id;
|
|
65
|
-
},
|
|
66
|
-
params: {
|
|
67
|
-
fields: 'subscribers'
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
const apiFetchAOSubscribers = (dataEngine, id, type) => {
|
|
72
|
-
return dataEngine.query(getSubscriberQuery(type), {
|
|
73
|
-
variables: {
|
|
74
|
-
id
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
export const preparePayloadForSave = async _ref3 => {
|
|
57
|
+
export const preparePayloadForSave = _ref2 => {
|
|
79
58
|
let {
|
|
80
59
|
visualization,
|
|
81
60
|
name,
|
|
82
|
-
description
|
|
83
|
-
|
|
84
|
-
} = _ref3;
|
|
85
|
-
const {
|
|
86
|
-
ao
|
|
87
|
-
} = await apiFetchAOSubscribers(engine, visualization.id, visualization.type);
|
|
88
|
-
visualization.subscribers = ao.subscribers;
|
|
61
|
+
description
|
|
62
|
+
} = _ref2;
|
|
89
63
|
visualization.name = name || visualization.name || i18n.t('Untitled {{visualizationType}}, {{date}}', {
|
|
90
64
|
visualizationType: getDisplayNameByVisType(visualization.type),
|
|
91
65
|
date: new Date().toLocaleDateString(undefined, {
|
|
@@ -95,5 +69,7 @@ export const preparePayloadForSave = async _ref3 => {
|
|
|
95
69
|
})
|
|
96
70
|
});
|
|
97
71
|
visualization.description = description !== undefined ? description : visualization.description;
|
|
72
|
+
delete visualization.displayName;
|
|
73
|
+
delete visualization.displayDescription;
|
|
98
74
|
return visualization;
|
|
99
75
|
};
|
|
@@ -243,10 +243,10 @@ export class PivotTableEngine {
|
|
|
243
243
|
rawValue = parseValue(rawValue);
|
|
244
244
|
switch (this.visualization.numberType) {
|
|
245
245
|
case NUMBER_TYPE_ROW_PERCENTAGE:
|
|
246
|
-
renderedValue = rawValue / this.percentageTotals[row].value;
|
|
246
|
+
rawCell.pctValue = renderedValue = rawValue / this.percentageTotals[row].value;
|
|
247
247
|
break;
|
|
248
248
|
case NUMBER_TYPE_COLUMN_PERCENTAGE:
|
|
249
|
-
renderedValue = rawValue / this.percentageTotals[column].value;
|
|
249
|
+
rawCell.pctValue = renderedValue = rawValue / this.percentageTotals[column].value;
|
|
250
250
|
break;
|
|
251
251
|
default:
|
|
252
252
|
break;
|
|
@@ -258,6 +258,19 @@ export class PivotTableEngine {
|
|
|
258
258
|
rawCell.rawValue = rawValue;
|
|
259
259
|
rawCell.renderedValue = renderedValue;
|
|
260
260
|
}
|
|
261
|
+
|
|
262
|
+
// show the original value in the tooltip
|
|
263
|
+
if ([NUMBER_TYPE_COLUMN_PERCENTAGE, NUMBER_TYPE_ROW_PERCENTAGE].includes(this.visualization.numberType)) {
|
|
264
|
+
rawCell.titleValue = i18n.t('Value: {{value}}', {
|
|
265
|
+
value: renderValue(rawCell.rawValue, valueType,
|
|
266
|
+
// force VALUE for formatting the original value
|
|
267
|
+
{
|
|
268
|
+
...this.visualization,
|
|
269
|
+
numberType: NUMBER_TYPE_VALUE
|
|
270
|
+
}),
|
|
271
|
+
nsSeparator: '^^'
|
|
272
|
+
});
|
|
273
|
+
}
|
|
261
274
|
if ([CELL_TYPE_TOTAL, CELL_TYPE_SUBTOTAL].includes(rawCell.cellType) && rawCell.rawValue === AGGREGATE_TYPE_NA) {
|
|
262
275
|
rawCell.titleValue = i18n.t('Not applicable');
|
|
263
276
|
}
|
|
@@ -950,7 +963,11 @@ export class PivotTableEngine {
|
|
|
950
963
|
if (!valueB || valueB.empty) {
|
|
951
964
|
return 1 * order;
|
|
952
965
|
}
|
|
953
|
-
if (
|
|
966
|
+
if (
|
|
967
|
+
// for percentage strings, use the pctValue (percentage value) in the sort comparison
|
|
968
|
+
[NUMBER_TYPE_ROW_PERCENTAGE, NUMBER_TYPE_COLUMN_PERCENTAGE].includes(this.visualization.numberType)) {
|
|
969
|
+
return (valueA.pctValue - valueB.pctValue) * order;
|
|
970
|
+
} else if (valueA.valueType === VALUE_TYPE_NUMBER && valueB.valueType === VALUE_TYPE_NUMBER) {
|
|
954
971
|
return (valueA.rawValue - valueB.rawValue) * order;
|
|
955
972
|
}
|
|
956
973
|
return valueA.renderedValue.localeCompare(valueB.renderedValue) * order;
|