@dhis2/analytics 27.0.1 → 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.
|
@@ -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;
|
|
@@ -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
|
};
|