@sis-cc/dotstatsuite-components 17.26.1 → 17.27.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.
@@ -3,11 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getTableLayoutIds = exports.getLayoutCombinations = exports.getLayoutDimsIds = exports.injectCombinationsInLayout = exports.injectCombination = exports.getLayoutRelationships = exports.getLayoutLevelRelationship = exports.indexCombsRelationships = exports.getCombinationsNotInLayout = undefined;
6
+ exports.getTableLayoutIds = exports.injectRemainingDimensionsInLayout = exports.getLayoutCombinations = exports.getLayoutDimsIds = exports.injectCombinationsInLayout = exports.injectCombination = exports.getLayoutRelationships = exports.getLayoutLevelRelationship = exports.indexCombsRelationships = exports.getCombinationsNotInLayout = undefined;
7
7
 
8
- var _extends2 = require('babel-runtime/helpers/extends');
8
+ var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
9
9
 
10
- var _extends3 = _interopRequireDefault(_extends2);
10
+ var _defineProperty3 = _interopRequireDefault(_defineProperty2);
11
+
12
+ var _extends3 = require('babel-runtime/helpers/extends');
13
+
14
+ var _extends4 = _interopRequireDefault(_extends3);
11
15
 
12
16
  var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
13
17
 
@@ -139,7 +143,7 @@ var injectCombinationsInLayout = exports.injectCombinationsInLayout = function i
139
143
  }
140
144
  var rowsConcepts = R.concat(idsInRows, nowhere);
141
145
  layoutRelationships.rows = R.concat(layoutRelationships.rows, rowsConcepts);
142
- var ids = injectCombination((0, _extends3.default)({}, comb, { concepts: rowsConcepts }))(acc.rows);
146
+ var ids = injectCombination((0, _extends4.default)({}, comb, { concepts: rowsConcepts }))(acc.rows);
143
147
  return R.assoc('rows', ids)(acc);
144
148
  }, layoutIds, notInLayoutCombs);
145
149
  };
@@ -159,7 +163,7 @@ var getLayoutCombinations = exports.getLayoutCombinations = function getLayoutCo
159
163
  }
160
164
  if (R.has(concept, indexedAttributes)) {
161
165
  var attr = R.prop(concept, indexedAttributes);
162
- return attr.series ? (0, _extends3.default)({}, _acc, {
166
+ return attr.series ? (0, _extends4.default)({}, _acc, {
163
167
  relationship: R.concat(_acc.relationship, attr.relationship)
164
168
  }) : _acc;
165
169
  }
@@ -171,10 +175,69 @@ var getLayoutCombinations = exports.getLayoutCombinations = function getLayoutCo
171
175
  if (R.isEmpty(relationship)) {
172
176
  return acc;
173
177
  }
174
- return R.append((0, _extends3.default)({}, comb, { relationship: relationship, concepts: layoutConcepts }), acc);
178
+ return R.append((0, _extends4.default)({}, comb, { relationship: relationship, concepts: layoutConcepts }), acc);
175
179
  }, [], combinations);
176
180
  };
177
181
 
182
+ var extractConcepts = function extractConcepts(ids, indexedCombinations) {
183
+ var getRelationship = function getRelationship(id) {
184
+ if (R.has(id, indexedCombinations)) {
185
+ return R.append(id, R.path([id, 'relationship'], indexedCombinations));
186
+ }
187
+ return [id];
188
+ };
189
+ var indexedRels = R.reduce(function (acc, id) {
190
+ return R.assoc(id, getRelationship(id), acc);
191
+ }, {}, ids);
192
+
193
+ var relationship = [R.head(ids)];
194
+ while (!R.isEmpty(indexedRels)) {
195
+ var related = R.pickBy(function (rels) {
196
+ return !R.isEmpty(R.intersection(relationship, rels));
197
+ }, indexedRels);
198
+ if (R.isEmpty(related)) {
199
+ break;
200
+ }
201
+ indexedRels = R.omit(R.keys(related), indexedRels);
202
+ relationship = R.concat(relationship, R.unnest(R.values(related)));
203
+ }
204
+ var set = new _set2.default(relationship);
205
+ return R.partition(function (id) {
206
+ return set.has(id);
207
+ }, ids);
208
+ };
209
+
210
+ var injectRemainingDimensionsInLayout = exports.injectRemainingDimensionsInLayout = function injectRemainingDimensionsInLayout(layoutIds, remainingDims, indexedCombinations) {
211
+ var _layout = layoutIds;
212
+ var _remaining = remainingDims;
213
+
214
+ if (R.isEmpty(_layout.rows)) {
215
+ if (R.isEmpty(_remaining)) {
216
+ var toTakeIn = R.isEmpty(_layout.sections) ? 'header' : 'sections';
217
+
218
+ var _extractConcepts = extractConcepts(R.prop(toTakeIn, _layout), indexedCombinations),
219
+ _extractConcepts2 = (0, _slicedToArray3.default)(_extractConcepts, 2),
220
+ extracted = _extractConcepts2[0],
221
+ remains = _extractConcepts2[1];
222
+
223
+ _layout = (0, _extends4.default)({}, _layout, (0, _defineProperty3.default)({ rows: extracted }, toTakeIn, remains));
224
+ } else {
225
+ _layout = R.over(R.lensProp('rows'), R.append(R.head(_remaining)))(_layout);
226
+ _remaining = R.tail(_remaining);
227
+ }
228
+ }
229
+ if (!R.isEmpty(_remaining)) {
230
+ var hasNoHeader = R.isEmpty(_layout.header);
231
+ var firstRemaining = R.head(_remaining);
232
+ _remaining = hasNoHeader ? R.tail(_remaining) : _remaining;
233
+ _layout = (0, _extends4.default)({}, _layout, {
234
+ sections: R.concat(_layout.sections, _remaining),
235
+ header: hasNoHeader ? [firstRemaining] : _layout.header
236
+ });
237
+ }
238
+ return _layout;
239
+ };
240
+
178
241
  var getTableLayoutIds = exports.getTableLayoutIds = function getTableLayoutIds(defaultLayoutIds, dimensions, attributes, combinations) {
179
242
  var layoutDimsIds = getLayoutDimsIds(dimensions);
180
243
  var layoutCombinations = getLayoutCombinations(combinations, layoutDimsIds, attributes);
@@ -221,20 +284,5 @@ var getTableLayoutIds = exports.getTableLayoutIds = function getTableLayoutIds(d
221
284
  nextLayout = _R$reduce4.nextLayout,
222
285
  remaining = _R$reduce4.remaining;
223
286
 
224
- var _remaining = remaining;
225
- return R.pipe(R.when(function (l) {
226
- return R.isEmpty(l.rows) && !R.isEmpty(_remaining);
227
- }, function (l) {
228
- var nextL = R.over(R.lensProp('rows'), R.append(R.head(_remaining)))(l);
229
- _remaining = R.tail(_remaining);
230
- return nextL;
231
- }), R.when(function (l) {
232
- return R.isEmpty(l.header) && !R.isEmpty(_remaining);
233
- }, function (l) {
234
- var nextL = R.over(R.lensProp('header'), R.append(R.head(_remaining)))(l);
235
- _remaining = R.tail(_remaining);
236
- return nextL;
237
- }), R.when(R.always(!R.isEmpty(_remaining)), function (l) {
238
- return R.over(R.lensProp('sections'), R.flip(R.concat)(_remaining))(l);;
239
- }))(nextLayout);
287
+ return injectRemainingDimensionsInLayout(nextLayout, remaining, indexedCombinations);
240
288
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sis-cc/dotstatsuite-components",
3
3
  "description": "Set components based on React.",
4
- "version": "17.26.1",
4
+ "version": "17.27.0",
5
5
  "main": "lib/index.js",
6
6
  "author": "OECD",
7
7
  "license": "MIT",
@@ -123,6 +123,58 @@ export const getLayoutCombinations = (combinations, layoutDimsIds, attributes) =
123
123
  );
124
124
  };
125
125
 
126
+ const extractConcepts = (ids, indexedCombinations) => {
127
+ const getRelationship = id => {
128
+ if (R.has(id, indexedCombinations)) {
129
+ return R.append(id, R.path([id, 'relationship'], indexedCombinations));
130
+ }
131
+ return [id];
132
+ };
133
+ let indexedRels = R.reduce((acc, id) =>
134
+ R.assoc(id, getRelationship(id), acc)
135
+ , {}, ids);
136
+
137
+ let relationship = [R.head(ids)];
138
+ while (!R.isEmpty(indexedRels)) {
139
+ const related = R.pickBy(rels => !R.isEmpty(R.intersection(relationship, rels)), indexedRels);
140
+ if (R.isEmpty(related)) {
141
+ break;
142
+ }
143
+ indexedRels = R.omit(R.keys(related), indexedRels);
144
+ relationship = R.concat(relationship, R.unnest(R.values(related)));
145
+ }
146
+ const set = new Set(relationship);
147
+ return R.partition(id => set.has(id), ids);
148
+ }
149
+
150
+ export const injectRemainingDimensionsInLayout = (layoutIds, remainingDims, indexedCombinations) => {
151
+ let _layout = layoutIds;
152
+ let _remaining = remainingDims;
153
+
154
+ if (R.isEmpty(_layout.rows)) {
155
+ if (R.isEmpty(_remaining)) {
156
+ const toTakeIn = R.isEmpty(_layout.sections) ? 'header' : 'sections';
157
+ const [extracted, remains] = extractConcepts(R.prop(toTakeIn, _layout), indexedCombinations);
158
+ _layout = ({ ..._layout, rows: extracted, [toTakeIn]: remains });
159
+ }
160
+ else {
161
+ _layout = R.over(R.lensProp('rows'), R.append(R.head(_remaining)))(_layout);
162
+ _remaining = R.tail(_remaining)
163
+ }
164
+ }
165
+ if (!R.isEmpty(_remaining)) {
166
+ const hasNoHeader = R.isEmpty(_layout.header);
167
+ const firstRemaining = R.head(_remaining);
168
+ _remaining = hasNoHeader ? R.tail(_remaining) : _remaining;
169
+ _layout = {
170
+ ..._layout,
171
+ sections: R.concat(_layout.sections, _remaining),
172
+ header: hasNoHeader ? [firstRemaining] : _layout.header,
173
+ };
174
+ }
175
+ return _layout;
176
+ };
177
+
126
178
  export const getTableLayoutIds = (
127
179
  defaultLayoutIds,
128
180
  dimensions,
@@ -184,29 +236,5 @@ export const getTableLayoutIds = (
184
236
  return R.over(R.lensProp('remaining'), R.append(dim.id))(acc);
185
237
  }, { nextLayout: layoutWithCombs, remaining: [] }, dimensions);
186
238
 
187
- let _remaining = remaining;
188
- return R.pipe(
189
- R.when(
190
- l => R.isEmpty(l.rows) && !R.isEmpty(_remaining),
191
- l => {
192
- const nextL = R.over(R.lensProp('rows'), R.append(R.head(_remaining)))(l);
193
- _remaining = R.tail(_remaining)
194
- return nextL;
195
- }
196
- ),
197
- R.when(
198
- l => R.isEmpty(l.header) && !R.isEmpty(_remaining),
199
- l => {
200
- const nextL = R.over(R.lensProp('header'), R.append(R.head(_remaining)))(l);
201
- _remaining = R.tail(_remaining)
202
- return nextL;
203
- }
204
- ),
205
- R.when(
206
- R.always(!R.isEmpty(_remaining)),
207
- l => {
208
- return R.over(R.lensProp('sections'), R.flip(R.concat)(_remaining))(l);;
209
- }
210
- ),
211
- )(nextLayout);
239
+ return injectRemainingDimensionsInLayout(nextLayout, remaining, indexedCombinations);
212
240
  };
@@ -110,4 +110,118 @@ describe('getTableLayoutIds tests', () => {
110
110
  rows: ['COMB2', 'REF_AREA']
111
111
  });
112
112
  });
113
+ it('nothing in rows 2', () => {
114
+ const combinations = [];
115
+ const attributes = [];
116
+ const dimensions = [
117
+ { id: 'D1', header: true },
118
+ { id: 'D2' },
119
+ { id: 'D3', header: true }
120
+ ];
121
+ const layoutIds = {
122
+ sections: ['D1'],
123
+ header: ['D2'],
124
+ rows: ['D3']
125
+ };
126
+
127
+ expect(getTableLayoutIds(layoutIds, dimensions, attributes, combinations)).to.deep.equal({
128
+ header: [],
129
+ sections: [],
130
+ rows: ['D2']
131
+ });
132
+ });
133
+ it('nothing in rows with combinations', () => {
134
+ const combinations = [
135
+ {
136
+ id: 'COMB1',
137
+ concepts: ['D1', 'D2']
138
+ },
139
+ {
140
+ id: 'COMB2',
141
+ concepts: ['A1', 'A2']
142
+ },
143
+ ];
144
+ const attributes = [
145
+ { id: 'A1', series: true, relationship: ['D1', 'D2'] },
146
+ { id: 'A2', series: true, relationship: ['D1', 'D2'] },
147
+ ];
148
+ const dimensions = [
149
+ { id: 'D1' },
150
+ { id: 'D2' },
151
+ { id: 'D3' }
152
+ ];
153
+ const layoutIds = {
154
+ sections: ['D1', 'D2'],
155
+ header: ['D3'],
156
+ rows: []
157
+ };
158
+
159
+ expect(getTableLayoutIds(layoutIds, dimensions, attributes, combinations)).to.deep.equal({
160
+ header: ['D3'],
161
+ sections: [],
162
+ rows: ['COMB1', 'COMB2']
163
+ });
164
+ });
165
+ it('nothing in rows with combinations 2', () => {
166
+ const combinations = [
167
+ {
168
+ id: 'COMB1',
169
+ concepts: ['D1', 'D2']
170
+ },
171
+ {
172
+ id: 'COMB2',
173
+ concepts: ['A1', 'A2']
174
+ },
175
+ ];
176
+ const attributes = [
177
+ { id: 'A1', series: true, relationship: ['D1', 'D2'] },
178
+ { id: 'A2', series: true, relationship: ['D1', 'D2'] },
179
+ ];
180
+ const dimensions = [
181
+ { id: 'D1' },
182
+ { id: 'D2' },
183
+ { id: 'D3' },
184
+ { id: 'D4' }
185
+ ];
186
+ const layoutIds1 = {
187
+ sections: ['COMB1', 'D4', 'COMB2'],
188
+ header: ['D3'],
189
+ rows: []
190
+ };
191
+ const layoutIds2 = {
192
+ sections: ['D4', 'COMB1', 'COMB2'],
193
+ header: ['D3'],
194
+ rows: []
195
+ };
196
+ const layoutIds3 = {
197
+ sections: ['COMB2', 'COMB1', 'D4'],
198
+ header: ['D3'],
199
+ rows: []
200
+ };
201
+ const layoutIds4 = {
202
+ sections: ['COMB1', 'COMB2'],
203
+ header: ['D3'],
204
+ rows: []
205
+ };
206
+ expect(getTableLayoutIds(layoutIds1, dimensions, attributes, combinations)).to.deep.equal({
207
+ header: ['D3'],
208
+ sections: ['D4'],
209
+ rows: ['COMB1', 'COMB2']
210
+ });
211
+ expect(getTableLayoutIds(layoutIds2, dimensions, attributes, combinations)).to.deep.equal({
212
+ header: ['D3'],
213
+ sections: ['COMB1', 'COMB2'],
214
+ rows: ['D4']
215
+ });
216
+ expect(getTableLayoutIds(layoutIds3, dimensions, attributes, combinations)).to.deep.equal({
217
+ header: ['D3'],
218
+ sections: ['D4'],
219
+ rows: ['COMB2', 'COMB1']
220
+ });
221
+ expect(getTableLayoutIds(layoutIds4, dimensions, attributes, combinations)).to.deep.equal({
222
+ header: ['D3'],
223
+ sections: ['COMB1', 'COMB2'],
224
+ rows: ['D4']
225
+ });
226
+ });
113
227
  });