@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
|
@@ -89,92 +89,37 @@ describe('utils', () => {
|
|
|
89
89
|
});
|
|
90
90
|
});
|
|
91
91
|
describe('preparePayloadForSave', () => {
|
|
92
|
-
|
|
93
|
-
query: jest.fn()
|
|
94
|
-
};
|
|
95
|
-
beforeEach(() => {
|
|
96
|
-
jest.clearAllMocks();
|
|
97
|
-
});
|
|
98
|
-
it('fetches subscribers and adds them to the visualization', async () => {
|
|
99
|
-
const visualization = {
|
|
100
|
-
id: '123',
|
|
101
|
-
type: 'BAR',
|
|
102
|
-
name: 'Existing Name',
|
|
103
|
-
description: 'Existing Description'
|
|
104
|
-
};
|
|
105
|
-
mockEngine.query.mockResolvedValue({
|
|
106
|
-
ao: {
|
|
107
|
-
subscribers: ['user1', 'user2']
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
const result = await (0, _utils.preparePayloadForSave)({
|
|
111
|
-
visualization,
|
|
112
|
-
engine: mockEngine
|
|
113
|
-
});
|
|
114
|
-
expect(mockEngine.query).toHaveBeenCalledWith({
|
|
115
|
-
ao: {
|
|
116
|
-
resource: 'visualizations',
|
|
117
|
-
id: expect.any(Function),
|
|
118
|
-
params: {
|
|
119
|
-
fields: 'subscribers'
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}, {
|
|
123
|
-
variables: {
|
|
124
|
-
id: '123'
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
expect(result.subscribers).toEqual(['user1', 'user2']);
|
|
128
|
-
});
|
|
129
|
-
it('sets the name to the provided name', async () => {
|
|
92
|
+
it('sets the name to the provided name', () => {
|
|
130
93
|
const visualization = {
|
|
131
94
|
id: '123',
|
|
132
95
|
type: 'MAP',
|
|
133
96
|
name: 'Existing name'
|
|
134
97
|
};
|
|
135
98
|
const name = 'New Name';
|
|
136
|
-
|
|
137
|
-
ao: {
|
|
138
|
-
subscribers: []
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
const result = await (0, _utils.preparePayloadForSave)({
|
|
99
|
+
const result = (0, _utils.preparePayloadForSave)({
|
|
142
100
|
visualization,
|
|
143
|
-
name
|
|
144
|
-
engine: mockEngine
|
|
101
|
+
name
|
|
145
102
|
});
|
|
146
103
|
expect(result.name).toBe(name);
|
|
147
104
|
});
|
|
148
|
-
it('sets the name to the existing name if no new name is provided',
|
|
105
|
+
it('sets the name to the existing name if no new name is provided', () => {
|
|
149
106
|
const visualization = {
|
|
150
107
|
id: '123',
|
|
151
108
|
type: 'LINE_LIST',
|
|
152
109
|
name: 'Existing Name'
|
|
153
110
|
};
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
subscribers: []
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
const result = await (0, _utils.preparePayloadForSave)({
|
|
160
|
-
visualization,
|
|
161
|
-
engine: mockEngine
|
|
111
|
+
const result = (0, _utils.preparePayloadForSave)({
|
|
112
|
+
visualization
|
|
162
113
|
});
|
|
163
114
|
expect(result.name).toBe('Existing Name');
|
|
164
115
|
});
|
|
165
|
-
it('sets the name to a default value if no name is provided',
|
|
116
|
+
it('sets the name to a default value if no name is provided', () => {
|
|
166
117
|
const visualization = {
|
|
167
118
|
id: '123',
|
|
168
119
|
type: 'BAR'
|
|
169
120
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
subscribers: []
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
const result = await (0, _utils.preparePayloadForSave)({
|
|
176
|
-
visualization,
|
|
177
|
-
engine: mockEngine
|
|
121
|
+
const result = (0, _utils.preparePayloadForSave)({
|
|
122
|
+
visualization
|
|
178
123
|
});
|
|
179
124
|
const expectedName = `Untitled Bar, ${new Date().toLocaleDateString(undefined, {
|
|
180
125
|
year: 'numeric',
|
|
@@ -183,55 +128,37 @@ describe('utils', () => {
|
|
|
183
128
|
})}`;
|
|
184
129
|
expect(result.name).toBe(expectedName);
|
|
185
130
|
});
|
|
186
|
-
it('sets the description to the provided description',
|
|
131
|
+
it('sets the description to the provided description', () => {
|
|
187
132
|
const visualization = {
|
|
188
133
|
id: '123',
|
|
189
134
|
type: 'YEAR_OVER_YEAR_LINE',
|
|
190
135
|
description: 'Existing Description'
|
|
191
136
|
};
|
|
192
137
|
const description = 'New Description';
|
|
193
|
-
|
|
194
|
-
ao: {
|
|
195
|
-
subscribers: []
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
const result = await (0, _utils.preparePayloadForSave)({
|
|
138
|
+
const result = (0, _utils.preparePayloadForSave)({
|
|
199
139
|
visualization,
|
|
200
|
-
description
|
|
201
|
-
engine: mockEngine
|
|
140
|
+
description
|
|
202
141
|
});
|
|
203
142
|
expect(result.description).toBe(description);
|
|
204
143
|
});
|
|
205
|
-
it('keeps the existing description if no new description is provided',
|
|
144
|
+
it('keeps the existing description if no new description is provided', () => {
|
|
206
145
|
const visualization = {
|
|
207
146
|
id: '123',
|
|
208
147
|
type: 'COLUMN',
|
|
209
148
|
description: 'Existing Description'
|
|
210
149
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
subscribers: []
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
const result = await (0, _utils.preparePayloadForSave)({
|
|
217
|
-
visualization,
|
|
218
|
-
engine: mockEngine
|
|
150
|
+
const result = (0, _utils.preparePayloadForSave)({
|
|
151
|
+
visualization
|
|
219
152
|
});
|
|
220
153
|
expect(result.description).toBe('Existing Description');
|
|
221
154
|
});
|
|
222
|
-
it('sets the description to undefined if no description is provided and none exists',
|
|
155
|
+
it('sets the description to undefined if no description is provided and none exists', () => {
|
|
223
156
|
const visualization = {
|
|
224
157
|
id: '123',
|
|
225
158
|
type: 'BAR'
|
|
226
159
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
subscribers: []
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
const result = await (0, _utils.preparePayloadForSave)({
|
|
233
|
-
visualization,
|
|
234
|
-
engine: mockEngine
|
|
160
|
+
const result = (0, _utils.preparePayloadForSave)({
|
|
161
|
+
visualization
|
|
235
162
|
});
|
|
236
163
|
expect(result.description).toBeUndefined();
|
|
237
164
|
});
|
|
@@ -65,38 +65,12 @@ const preparePayloadForSaveAs = _ref => {
|
|
|
65
65
|
return visualization;
|
|
66
66
|
};
|
|
67
67
|
exports.preparePayloadForSaveAs = preparePayloadForSaveAs;
|
|
68
|
-
const
|
|
69
|
-
ao: {
|
|
70
|
-
resource: (0, _visTypes.getApiEndpointByVisType)(type),
|
|
71
|
-
id: _ref2 => {
|
|
72
|
-
let {
|
|
73
|
-
id
|
|
74
|
-
} = _ref2;
|
|
75
|
-
return id;
|
|
76
|
-
},
|
|
77
|
-
params: {
|
|
78
|
-
fields: 'subscribers'
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
const apiFetchAOSubscribers = (dataEngine, id, type) => {
|
|
83
|
-
return dataEngine.query(getSubscriberQuery(type), {
|
|
84
|
-
variables: {
|
|
85
|
-
id
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
const preparePayloadForSave = async _ref3 => {
|
|
68
|
+
const preparePayloadForSave = _ref2 => {
|
|
90
69
|
let {
|
|
91
70
|
visualization,
|
|
92
71
|
name,
|
|
93
|
-
description
|
|
94
|
-
|
|
95
|
-
} = _ref3;
|
|
96
|
-
const {
|
|
97
|
-
ao
|
|
98
|
-
} = await apiFetchAOSubscribers(engine, visualization.id, visualization.type);
|
|
99
|
-
visualization.subscribers = ao.subscribers;
|
|
72
|
+
description
|
|
73
|
+
} = _ref2;
|
|
100
74
|
visualization.name = name || visualization.name || _d2I18n.default.t('Untitled {{visualizationType}}, {{date}}', {
|
|
101
75
|
visualizationType: (0, _visTypes.getDisplayNameByVisType)(visualization.type),
|
|
102
76
|
date: new Date().toLocaleDateString(undefined, {
|
|
@@ -106,6 +80,8 @@ const preparePayloadForSave = async _ref3 => {
|
|
|
106
80
|
})
|
|
107
81
|
});
|
|
108
82
|
visualization.description = description !== undefined ? description : visualization.description;
|
|
83
|
+
delete visualization.displayName;
|
|
84
|
+
delete visualization.displayDescription;
|
|
109
85
|
return visualization;
|
|
110
86
|
};
|
|
111
87
|
exports.preparePayloadForSave = preparePayloadForSave;
|
|
@@ -250,10 +250,10 @@ class PivotTableEngine {
|
|
|
250
250
|
rawValue = (0, _parseValue.parseValue)(rawValue);
|
|
251
251
|
switch (this.visualization.numberType) {
|
|
252
252
|
case _pivotTableConstants.NUMBER_TYPE_ROW_PERCENTAGE:
|
|
253
|
-
renderedValue = rawValue / this.percentageTotals[row].value;
|
|
253
|
+
rawCell.pctValue = renderedValue = rawValue / this.percentageTotals[row].value;
|
|
254
254
|
break;
|
|
255
255
|
case _pivotTableConstants.NUMBER_TYPE_COLUMN_PERCENTAGE:
|
|
256
|
-
renderedValue = rawValue / this.percentageTotals[column].value;
|
|
256
|
+
rawCell.pctValue = renderedValue = rawValue / this.percentageTotals[column].value;
|
|
257
257
|
break;
|
|
258
258
|
default:
|
|
259
259
|
break;
|
|
@@ -265,6 +265,19 @@ class PivotTableEngine {
|
|
|
265
265
|
rawCell.rawValue = rawValue;
|
|
266
266
|
rawCell.renderedValue = renderedValue;
|
|
267
267
|
}
|
|
268
|
+
|
|
269
|
+
// show the original value in the tooltip
|
|
270
|
+
if ([_pivotTableConstants.NUMBER_TYPE_COLUMN_PERCENTAGE, _pivotTableConstants.NUMBER_TYPE_ROW_PERCENTAGE].includes(this.visualization.numberType)) {
|
|
271
|
+
rawCell.titleValue = _d2I18n.default.t('Value: {{value}}', {
|
|
272
|
+
value: (0, _renderValue.renderValue)(rawCell.rawValue, valueType,
|
|
273
|
+
// force VALUE for formatting the original value
|
|
274
|
+
{
|
|
275
|
+
...this.visualization,
|
|
276
|
+
numberType: _pivotTableConstants.NUMBER_TYPE_VALUE
|
|
277
|
+
}),
|
|
278
|
+
nsSeparator: '^^'
|
|
279
|
+
});
|
|
280
|
+
}
|
|
268
281
|
if ([_pivotTableConstants.CELL_TYPE_TOTAL, _pivotTableConstants.CELL_TYPE_SUBTOTAL].includes(rawCell.cellType) && rawCell.rawValue === _pivotTableConstants.AGGREGATE_TYPE_NA) {
|
|
269
282
|
rawCell.titleValue = _d2I18n.default.t('Not applicable');
|
|
270
283
|
}
|
|
@@ -957,7 +970,11 @@ class PivotTableEngine {
|
|
|
957
970
|
if (!valueB || valueB.empty) {
|
|
958
971
|
return 1 * order;
|
|
959
972
|
}
|
|
960
|
-
if (
|
|
973
|
+
if (
|
|
974
|
+
// for percentage strings, use the pctValue (percentage value) in the sort comparison
|
|
975
|
+
[_pivotTableConstants.NUMBER_TYPE_ROW_PERCENTAGE, _pivotTableConstants.NUMBER_TYPE_COLUMN_PERCENTAGE].includes(this.visualization.numberType)) {
|
|
976
|
+
return (valueA.pctValue - valueB.pctValue) * order;
|
|
977
|
+
} else if (valueA.valueType === _valueTypes.VALUE_TYPE_NUMBER && valueB.valueType === _valueTypes.VALUE_TYPE_NUMBER) {
|
|
961
978
|
return (valueA.rawValue - valueB.rawValue) * order;
|
|
962
979
|
}
|
|
963
980
|
return valueA.renderedValue.localeCompare(valueB.renderedValue) * order;
|