@fibery/views 1.1.1 → 1.1.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/lib/views.js +0 -855
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Operations on view objects",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Fibery",
package/lib/views.js DELETED
@@ -1,855 +0,0 @@
1
- var immutableUpdate = require('immutability-helper');
2
- var _ = require('lodash');
3
- var visitors = require('@fibery/expression-utils/visitors');
4
- var utils = require('@fibery/expression-utils/utils');
5
-
6
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
-
8
- var immutableUpdate__default = /*#__PURE__*/_interopDefaultLegacy(immutableUpdate);
9
- var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
10
-
11
- function _extends() {
12
- _extends = Object.assign || function (target) {
13
- for (var i = 1; i < arguments.length; i++) {
14
- var source = arguments[i];
15
-
16
- for (var key in source) {
17
- if (Object.prototype.hasOwnProperty.call(source, key)) {
18
- target[key] = source[key];
19
- }
20
- }
21
- }
22
-
23
- return target;
24
- };
25
-
26
- return _extends.apply(this, arguments);
27
- }
28
-
29
- const deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = (schema, queryExpression) => {
30
- const {
31
- "q/from": fromExpression,
32
- "q/where": whereExpression,
33
- "q/order-by": orderByExpression
34
- } = queryExpression;
35
-
36
- if (schema.typeObjectsByName.hasOwnProperty(fromExpression)) {
37
- const typeObject = schema.typeObjectsByName[fromExpression];
38
- return ___default["default"].pickBy(_extends({}, queryExpression, whereExpression ? {
39
- "q/where": visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(whereExpression)
40
- } : null, orderByExpression ? {
41
- "q/order-by": visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitOrderByExpression(orderByExpression)
42
- } : null));
43
- }
44
-
45
- return null;
46
- };
47
- const replaceNamesWithIdsInExpression = (schema, fromType, expression) => {
48
- if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
49
- const typeObject = schema.typeObjectsByName[fromType];
50
- return visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(expression);
51
- }
52
-
53
- return expression;
54
- };
55
- const replaceIdsWithNamesInExpression = (schema, fromTypeId, expression) => {
56
- if (schema.typeObjectsById.hasOwnProperty(fromTypeId)) {
57
- const typeObject = schema.typeObjectsById[fromTypeId];
58
- return visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(expression);
59
- }
60
-
61
- return expression;
62
- };
63
- const visitViewUnit = (fromType, unit, visitor) => {
64
- const {
65
- expression
66
- } = unit;
67
-
68
- if (expression) {
69
- return _extends({}, unit, {
70
- expression: visitor.visitExpression(fromType, expression)
71
- });
72
- }
73
-
74
- return unit;
75
- };
76
- const replaceIdsWithNamesInQueryExpression = (schema, queryExpression) => {
77
- const {
78
- "q/from": fromExpression,
79
- "q/where": whereExpression,
80
- "q/order-by": orderByExpression
81
- } = queryExpression;
82
-
83
- if (schema.typeObjectsById.hasOwnProperty(fromExpression)) {
84
- const typeObject = schema.typeObjectsById[fromExpression];
85
- return _extends({}, queryExpression, {
86
- "q/from": typeObject.name
87
- }, whereExpression ? {
88
- "q/where": visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(whereExpression)
89
- } : null, orderByExpression ? {
90
- "q/order-by": visitors.replaceIdsWithNamesVisitor(typeObject).visitOrderByExpression(orderByExpression)
91
- } : null);
92
- }
93
-
94
- return queryExpression;
95
- };
96
- const replaceNamesWithIdsInQueryExpression = (schema, queryExpression) => {
97
- const {
98
- "q/from": fromExpression,
99
- "q/where": whereExpression,
100
- "q/order-by": orderByExpression
101
- } = queryExpression;
102
-
103
- if (schema.typeObjectsByName.hasOwnProperty(fromExpression)) {
104
- const typeObject = schema.typeObjectsByName[fromExpression];
105
- return _extends({}, queryExpression, {
106
- "q/from": typeObject.id
107
- }, whereExpression ? {
108
- "q/where": visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(whereExpression)
109
- } : null, orderByExpression ? {
110
- "q/order-by": visitors.replaceNamesWithIdsVisitor(typeObject).visitOrderByExpression(orderByExpression)
111
- } : null);
112
- }
113
-
114
- return queryExpression;
115
- };
116
- const deleteExpressionWithNotFoundFieldsOrTypesInExpression = (schema, fromType, expression) => {
117
- if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
118
- const typeObject = schema.typeObjectsByName[fromType];
119
- return visitors.deleteExpressionsWithNotFoundFieldsVisitor(typeObject).visitExpression(expression);
120
- }
121
-
122
- return null;
123
- };
124
- const isUnitExpressionValid = unit => {
125
- if (unit.hasOwnProperty("expression")) {
126
- const {
127
- expression
128
- } = unit;
129
- return expression !== null;
130
- }
131
-
132
- return true;
133
- };
134
-
135
- const visitView$3 = (view, visitor) => immutableUpdate__default["default"](view, {
136
- "fibery/meta": {
137
- items: {
138
- $apply: items => items.map(item => {
139
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
140
-
141
- return fromType ? immutableUpdate__default["default"](item, {
142
- query: {
143
- $apply: query => query ? visitor.visitQueryExpression(query) : null
144
- },
145
- contextExpression: {
146
- $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
147
- },
148
- units: {
149
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)) : null
150
- },
151
- colorCoding: {
152
- $apply: colorCodings => {
153
- return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
154
- expression: visitor.visitExpression(fromType, colorCoding.expression)
155
- })).filter(colorCoding => colorCoding.expression !== null);
156
- }
157
- }
158
- }) : item;
159
- }).filter(item => {
160
- const {
161
- query
162
- } = item;
163
- return query ? item : null;
164
- })
165
- }
166
- }
167
- });
168
-
169
- const replaceNamesWithIdsInTableView = (schema, view) => visitView$3(view, {
170
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
171
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query)
172
- });
173
- const replaceIdsWithNamesInTableView = (schema, view) => visitView$3(view, {
174
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
175
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query)
176
- });
177
- const deleteExpressionWithNotFoundFieldsOrTypesInTableView = (schema, view) => visitView$3(view, {
178
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
179
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
180
- });
181
-
182
- const visitView$2 = (view, visitor) => immutableUpdate__default["default"](view, {
183
- "fibery/meta": {
184
- items: {
185
- $apply: items => items.map(item => {
186
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
187
-
188
- return fromType ? immutableUpdate__default["default"](item, {
189
- startExpression: {
190
- $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
191
- },
192
- endExpression: {
193
- $apply: endExpression => endExpression ? visitor.visitExpression(fromType, endExpression) : endExpression
194
- },
195
- contextExpression: {
196
- $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
197
- },
198
- query: {
199
- $apply: query => query ? visitor.visitQueryExpression(query) : null
200
- },
201
- units: {
202
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)) : null
203
- },
204
- colorCoding: {
205
- $apply: colorCodings => {
206
- return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
207
- expression: visitor.visitExpression(fromType, colorCoding.expression)
208
- })).filter(colorCoding => colorCoding.expression !== null);
209
- }
210
- }
211
- }) : item;
212
- }).filter(item => {
213
- const {
214
- query
215
- } = item;
216
- return query ? item : null;
217
- })
218
- }
219
- }
220
- });
221
-
222
- const replaceNamesWithIdsInCalendarView = (schema, view) => {
223
- return visitView$2(view, {
224
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
225
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query)
226
- });
227
- };
228
- const replaceIdsWithNamesInCalendarView = (schema, view) => {
229
- return visitView$2(view, {
230
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
231
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query)
232
- });
233
- };
234
- const deleteExpressionWithNotFoundFieldsOrTypesInCalendarView = (schema, view) => visitView$2(view, {
235
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
236
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
237
- });
238
-
239
- const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["default"](smartFolder, {
240
- "fibery/meta": {
241
- items: {
242
- $apply: items => {
243
- const isOldSmartFolder = !items.every(item => item.hasOwnProperty("groupBy"));
244
- let removedItems = [];
245
- return items.map((item, index) => {
246
- if (isOldSmartFolder) {
247
- return item;
248
- }
249
-
250
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
251
-
252
- return fromType ? immutableUpdate__default["default"](item, {
253
- groupBy: {
254
- $apply: groupBy => {
255
- const removedItemsBeforeCurrent = removedItems.filter(n => n < index);
256
- return groupBy ? visitor.visitGroupByExpression(groupBy, fromType, removedItemsBeforeCurrent.length) : null;
257
- }
258
- }
259
- }) : item;
260
- }).map((item, index) => {
261
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
262
-
263
- return fromType ? immutableUpdate__default["default"](item, {
264
- query: {
265
- $apply: query => {
266
- const visitedQuery = visitor.visitQueryExpression(query);
267
-
268
- if (!visitedQuery) {
269
- removedItems.push(index);
270
- }
271
-
272
- return query ? visitedQuery : null;
273
- }
274
- },
275
- units: {
276
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)) : undefined
277
- },
278
- contextExpression: {
279
- $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
280
- },
281
- colorCoding: {
282
- $apply: colorCodings => {
283
- return colorCodings ? colorCodings.map(colorCoding => _extends({}, colorCoding, {
284
- expression: visitor.visitExpression(fromType, colorCoding.expression)
285
- })).filter(colorCoding => colorCoding.expression !== null) : undefined;
286
- }
287
- }
288
- }) : item;
289
- }).filter(item => {
290
- const {
291
- query
292
- } = item;
293
- return query ? item : null;
294
- });
295
- }
296
- }
297
- }
298
- });
299
-
300
- const deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression = (schema, groupByExpression, fromType, removedItems) => {
301
- if (!groupByExpression) {
302
- return null;
303
- }
304
-
305
- const [[index, {
306
- expression
307
- }]] = Object.entries(groupByExpression);
308
- const visitedExpression = deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression);
309
-
310
- if (visitedExpression) {
311
- return {
312
- [`${parseInt(index) - removedItems}`]: {
313
- expression: visitedExpression
314
- }
315
- };
316
- }
317
-
318
- return null;
319
- };
320
-
321
- const replaceIdsWithNamesInGroupByExpression = (schema, groupByExpression, fromType) => {
322
- if (!groupByExpression) {
323
- return null;
324
- }
325
-
326
- const [[index, {
327
- expression
328
- }]] = Object.entries(groupByExpression);
329
-
330
- if (schema.typeObjectsById.hasOwnProperty(fromType)) {
331
- const typeObject = schema.typeObjectsById[fromType];
332
- return {
333
- [index]: {
334
- expression: visitors.replaceIdsWithNamesVisitor(typeObject).visitExpression(expression)
335
- }
336
- };
337
- }
338
-
339
- return null;
340
- };
341
- const replaceNamesWithIdsInGroupByExpression = (schema, groupByExpression, fromType) => {
342
- if (!groupByExpression) {
343
- return null;
344
- }
345
-
346
- const [[index, {
347
- expression
348
- }]] = Object.entries(groupByExpression);
349
-
350
- if (schema.typeObjectsByName.hasOwnProperty(fromType)) {
351
- const typeObject = schema.typeObjectsByName[fromType];
352
- return {
353
- [index]: {
354
- expression: visitors.replaceNamesWithIdsVisitor(typeObject).visitExpression(expression)
355
- }
356
- };
357
- }
358
-
359
- return null;
360
- };
361
- const replaceNamesWithIdsInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
362
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
363
- visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType),
364
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
365
- });
366
- const replaceIdsWithNamesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
367
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
368
- visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType),
369
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
370
- });
371
- const deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
372
- visitQueryExpression: query => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, query),
373
- visitGroupByExpression: (groupBy, fromType, removedItems) => deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression(schema, groupBy, fromType, removedItems),
374
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
375
- });
376
-
377
- const visitAxis$1 = (axis, visitor) => {
378
- if (!axis) {
379
- return axis;
380
- }
381
-
382
- const fromType = ___default["default"].get(axis, ["query", "q/from"]);
383
-
384
- const firstOrNull = x => ___default["default"].first(x) || null;
385
-
386
- const axisResult = _extends({}, axis, {
387
- query: axis.query && visitor.visitQueryExpression(axis.query),
388
- contextExpression: axis.contextExpression && visitor.visitExpression(fromType, axis.contextExpression),
389
- units: axis.units && axis.units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)),
390
- groupByExpression: axis.groupByExpression && firstOrNull(visitor.visitExpression(fromType, [axis.groupByExpression]))
391
- });
392
-
393
- if (!axisResult.query) {
394
- return null;
395
- }
396
-
397
- if (!axisResult.units) {
398
- delete axisResult.units;
399
- }
400
-
401
- return axisResult;
402
- };
403
-
404
- const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view, {
405
- "fibery/meta": {
406
- y: {
407
- $apply: y => visitAxis$1(y, visitor)
408
- },
409
- items: {
410
- $apply: items => items.map(item => {
411
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
412
-
413
- return fromType ? immutableUpdate__default["default"](item, {
414
- yExpression: {
415
- $apply: yExpression => yExpression ? visitor.visitExpression(fromType, yExpression) : yExpression
416
- },
417
- startExpression: {
418
- $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
419
- },
420
- endExpression: {
421
- $apply: endExpression => endExpression ? visitor.visitExpression(fromType, endExpression) : endExpression
422
- },
423
- contextExpression: {
424
- $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
425
- },
426
- query: {
427
- $apply: query => query ? visitor.visitQueryExpression(query) : null
428
- },
429
- units: {
430
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)) : null
431
- },
432
- colorCoding: {
433
- $apply: colorCodings => {
434
- return colorCodings && colorCodings.map(colorCoding => _extends({}, colorCoding, {
435
- expression: visitor.visitExpression(fromType, colorCoding.expression)
436
- })).filter(colorCoding => colorCoding.expression !== null);
437
- }
438
- }
439
- }) : item;
440
- }).filter(item => {
441
- const {
442
- query
443
- } = item;
444
- return query ? item : null;
445
- })
446
- },
447
- milestones: {
448
- $apply: milestones => {
449
- if (!milestones) {
450
- return milestones;
451
- }
452
-
453
- return milestones.map(item => {
454
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
455
-
456
- return fromType ? immutableUpdate__default["default"](item, {
457
- dateExpression: {
458
- $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
459
- },
460
- query: {
461
- $apply: query => query ? visitor.visitQueryExpression(query) : null
462
- }
463
- }) : item;
464
- }).filter(item => {
465
- const {
466
- query
467
- } = item;
468
- return query ? item : null;
469
- });
470
- }
471
- }
472
- }
473
- });
474
-
475
- const replaceNamesWithIdsInTimelineView = (schema, view) => {
476
- return visitView$1(view, {
477
- visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
478
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
479
- });
480
- };
481
- const replaceIdsWithNamesInTimelineView = (schema, view) => {
482
- return visitView$1(view, {
483
- visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
484
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
485
- });
486
- };
487
-
488
- const ensureAxisAndItemExpressionInvariant$1 = view => {
489
- const actions = [];
490
-
491
- const y = ___default["default"].get(view, ["fibery/meta", "y"]);
492
-
493
- const yQuery = ___default["default"].get(view, ["fibery/meta", "y", "query"]);
494
-
495
- const yGroupByExpression = ___default["default"].get(view, ["fibery/meta", "y", "groupByExpression"]);
496
-
497
- const items = ___default["default"].get(view, ["fibery/meta", "items"]);
498
-
499
- if (yQuery === null && yGroupByExpression !== null) {
500
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y", "groupByExpression"], null));
501
- }
502
-
503
- if (y === null) {
504
- const resetActions = items.map(item => () => item.yExpression = null);
505
- actions.push(...resetActions);
506
- }
507
-
508
- if (y !== null && ___default["default"].some(items, ({
509
- yExpression
510
- }) => yExpression === null)) {
511
- const resetActions = items.map(item => () => item.yExpression = null);
512
- actions.push(...resetActions);
513
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
514
- }
515
-
516
- if (y !== null && ___default["default"].isEmpty(items)) {
517
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
518
- }
519
-
520
- actions.forEach(action => action());
521
- return view;
522
- };
523
-
524
- const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view) => {
525
- const viewNew = visitView$1(view, {
526
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
527
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
528
- });
529
- return ensureAxisAndItemExpressionInvariant$1(viewNew);
530
- };
531
-
532
- const visitQueryExpressionHolder = (queryHolder, visitor) => {
533
- if (queryHolder) {
534
- const {
535
- query
536
- } = queryHolder;
537
-
538
- if (query) {
539
- const queryNew = visitor.visitQueryExpression(query);
540
- return queryNew ? _extends({}, queryHolder, {
541
- query: queryNew
542
- }) : null;
543
- }
544
-
545
- return queryHolder;
546
- }
547
-
548
- return queryHolder;
549
- };
550
-
551
- const visitAxisUnits = (axis, fromType, visitor) => {
552
- return fromType ? immutableUpdate__default["default"](axis, {
553
- contextExpression: {
554
- $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
555
- },
556
- units: {
557
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)) : undefined
558
- }
559
- }) : axis;
560
- };
561
-
562
- const visitAxis = (axis, visitor) => {
563
- if (axis && axis.hasOwnProperty("query")) {
564
- const fromType = ___default["default"].get(axis, ["query", "q/from"]);
565
-
566
- const axisWithVisitedQuery = visitQueryExpressionHolder(axis, visitor);
567
-
568
- if (axisWithVisitedQuery) {
569
- return visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
570
- }
571
-
572
- return axisWithVisitedQuery;
573
- }
574
-
575
- if (axis && axis.hasOwnProperty("enums")) {
576
- const axisNew = immutableUpdate__default["default"](axis, {
577
- enums: {
578
- $apply: enums => visitor.visitEnums(enums)
579
- }
580
- });
581
- const {
582
- enums
583
- } = axisNew;
584
- return enums ? axisNew : null;
585
- }
586
-
587
- return axis;
588
- };
589
-
590
- const ensureAxisAndItemExpressionInvariant = view => {
591
- const actions = [];
592
-
593
- const x = ___default["default"].get(view, ["fibery/meta", "x"]);
594
-
595
- const y = ___default["default"].get(view, ["fibery/meta", "y"]);
596
-
597
- const items = ___default["default"].get(view, ["fibery/meta", "items"]);
598
-
599
- if (x === null) {
600
- const resetActions = items.map(item => () => item.xExpression = null);
601
- actions.push(...resetActions);
602
- }
603
-
604
- if (x !== null && ___default["default"].some(items, ({
605
- xExpression
606
- }) => xExpression === null)) {
607
- const resetActions = items.map(item => () => item.xExpression = null);
608
- actions.push(...resetActions);
609
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
610
- }
611
-
612
- if (y === null) {
613
- const resetActions = items.map(item => () => item.yExpression = null);
614
- actions.push(...resetActions);
615
- }
616
-
617
- if (y !== null && ___default["default"].some(items, ({
618
- yExpression
619
- }) => yExpression === null)) {
620
- const resetActions = items.map(item => () => item.yExpression = null);
621
- actions.push(...resetActions);
622
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
623
- }
624
-
625
- if (x !== null && ___default["default"].isEmpty(items)) {
626
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
627
- }
628
-
629
- if (y !== null && ___default["default"].isEmpty(items)) {
630
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
631
- }
632
-
633
- if (x !== null && ___default["default"].some(items, ({
634
- xExpression
635
- }) => !utils.isAxisFieldExpression(xExpression))) {
636
- const resetActions = items.map(item => () => item.xExpression = null);
637
- actions.push(...resetActions);
638
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "x"], null));
639
- }
640
-
641
- if (y !== null && ___default["default"].some(items, ({
642
- yExpression
643
- }) => !utils.isAxisFieldExpression(yExpression))) {
644
- const resetActions = items.map(item => () => item.yExpression = null);
645
- actions.push(...resetActions);
646
- actions.push(() => ___default["default"].set(view, ["fibery/meta", "y"], null));
647
- }
648
-
649
- actions.forEach(action => action());
650
- return view;
651
- };
652
-
653
- const visitView = (view, visitor) => immutableUpdate__default["default"](view, {
654
- "fibery/meta": {
655
- x: {
656
- $apply: x => visitAxis(x, visitor)
657
- },
658
- y: {
659
- $apply: y => visitAxis(y, visitor)
660
- },
661
- items: {
662
- $apply: items => items.map(item => {
663
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
664
-
665
- return fromType ? immutableUpdate__default["default"](item, {
666
- xExpression: {
667
- $apply: xExpression => xExpression ? visitor.visitExpression(fromType, xExpression) : xExpression
668
- },
669
- yExpression: {
670
- $apply: yExpression => yExpression ? visitor.visitExpression(fromType, yExpression) : yExpression
671
- },
672
- contextExpression: {
673
- $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
674
- },
675
- query: {
676
- $apply: query => query ? visitor.visitQueryExpression(query) : null
677
- },
678
- units: {
679
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)) : null
680
- },
681
- colorCoding: {
682
- $apply: colorCodings => {
683
- return colorCodings ? colorCodings.map(colorCoding => _extends({}, colorCoding, {
684
- expression: visitor.visitExpression(fromType, colorCoding.expression)
685
- })).filter(colorCoding => colorCoding.expression !== null) : undefined;
686
- }
687
- }
688
- }) : item;
689
- }).filter(item => {
690
- const {
691
- query
692
- } = item;
693
- return query ? item : null;
694
- })
695
- }
696
- }
697
- });
698
-
699
- const replaceNamesWithIdsViewVisitor = schema => {
700
- const visitor = {
701
- visitQueryExpression: queryExpression => replaceNamesWithIdsInQueryExpression(schema, queryExpression),
702
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
703
- visitEnums: enums => ___default["default"].entries(enums).reduce((result, [type, queryHolder]) => {
704
- if (schema.typeObjectsByName.hasOwnProperty(type)) {
705
- const typeObject = schema.typeObjectsByName[type];
706
-
707
- const fromType = ___default["default"].get(queryHolder, ["query", "q/from"]);
708
-
709
- const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
710
- result[typeObject.id] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
711
- } else {
712
- result[type] = queryHolder;
713
- }
714
-
715
- return result;
716
- }, {})
717
- };
718
- return visitor;
719
- };
720
-
721
- const replaceIdsWithNamesViewVisitor = schema => {
722
- const visitor = {
723
- visitQueryExpression: queryExpression => replaceIdsWithNamesInQueryExpression(schema, queryExpression),
724
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
725
- visitEnums: enums => ___default["default"].entries(enums).reduce((result, [typeId, queryHolder]) => {
726
- if (schema.typeObjectsById.hasOwnProperty(typeId)) {
727
- const typeObject = schema.typeObjectsById[typeId];
728
-
729
- const fromType = ___default["default"].get(queryHolder, ["query", "q/from"]);
730
-
731
- const axisWithVisitedQuery = visitQueryExpressionHolder(queryHolder, visitor);
732
- result[typeObject.name] = visitAxisUnits(axisWithVisitedQuery, fromType, visitor);
733
- } else {
734
- result[typeId] = queryHolder;
735
- }
736
-
737
- return result;
738
- }, {})
739
- };
740
- return visitor;
741
- };
742
-
743
- const deleteExpressionWithNotFoundFieldsOrTypesViewVisitor = schema => {
744
- const visitor = {
745
- visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
746
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression),
747
- visitEnums: enums => {
748
- const enumsNew = ___default["default"].entries(enums).reduce((result, [type, queryHolder]) => {
749
- if (schema.typeObjectsByName.hasOwnProperty(type)) {
750
- const typeObject = schema.typeObjectsByName[type];
751
- const queryHolderResult = visitQueryExpressionHolder(queryHolder, visitor);
752
-
753
- if (queryHolderResult) {
754
- result[typeObject.name] = queryHolderResult;
755
- }
756
-
757
- return result;
758
- }
759
-
760
- return result;
761
- }, {});
762
-
763
- return ___default["default"].isEmpty(enumsNew) ? null : enumsNew;
764
- }
765
- };
766
- return visitor;
767
- };
768
-
769
- const replaceIdsWithNamesInBoardView = (schema, view) => visitView(view, replaceIdsWithNamesViewVisitor(schema));
770
- const replaceNamesWithIdsInBoardView = (schema, view) => visitView(view, replaceNamesWithIdsViewVisitor(schema));
771
- const deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView = (schema, view) => {
772
- const viewNew = visitView(view, deleteExpressionWithNotFoundFieldsOrTypesViewVisitor(schema));
773
- return ensureAxisAndItemExpressionInvariant(viewNew);
774
- };
775
-
776
- const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view) => {
777
- switch (view["fibery/type"]) {
778
- case "board":
779
- return deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView(schema, view);
780
-
781
- case "list":
782
- return deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder(schema, view);
783
-
784
- case "timeline":
785
- return deleteExpressionWithNotFoundFieldsOrTypesInTimelineView(schema, view);
786
-
787
- case "calendar":
788
- return deleteExpressionWithNotFoundFieldsOrTypesInCalendarView(schema, view);
789
-
790
- case "table":
791
- return deleteExpressionWithNotFoundFieldsOrTypesInTableView(schema, view);
792
-
793
- default:
794
- return view;
795
- }
796
- };
797
- const replaceNamesWithIdsInView = (schema, view) => {
798
- switch (view["fibery/type"]) {
799
- case "board":
800
- return replaceNamesWithIdsInBoardView(schema, view);
801
-
802
- case "list":
803
- return replaceNamesWithIdsInSmartFolder(schema, view);
804
-
805
- case "table":
806
- return replaceNamesWithIdsInTableView(schema, view);
807
-
808
- case "timeline":
809
- return replaceNamesWithIdsInTimelineView(schema, view);
810
-
811
- case "calendar":
812
- return replaceNamesWithIdsInCalendarView(schema, view);
813
-
814
- default:
815
- return view;
816
- }
817
- };
818
- const replaceIdsWithNamesInView = (schema, view) => {
819
- switch (view["fibery/type"]) {
820
- case "board":
821
- return replaceIdsWithNamesInBoardView(schema, view);
822
-
823
- case "list":
824
- return replaceIdsWithNamesInSmartFolder(schema, view);
825
-
826
- case "table":
827
- return replaceIdsWithNamesInTableView(schema, view);
828
-
829
- case "timeline":
830
- return replaceIdsWithNamesInTimelineView(schema, view);
831
-
832
- case "calendar":
833
- return replaceIdsWithNamesInCalendarView(schema, view);
834
-
835
- default:
836
- return view;
837
- }
838
- };
839
- const getViewCardTypes = ({
840
- "fibery/meta": {
841
- items
842
- }
843
- }) => items.map(({
844
- query: {
845
- "q/from": type
846
- }
847
- }) => type);
848
-
849
- exports.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder;
850
- exports.deleteExpressionWithNotFoundFieldsOrTypesInView = deleteExpressionWithNotFoundFieldsOrTypesInView;
851
- exports.getViewCardTypes = getViewCardTypes;
852
- exports.replaceIdsWithNamesInSmartFolder = replaceIdsWithNamesInSmartFolder;
853
- exports.replaceIdsWithNamesInView = replaceIdsWithNamesInView;
854
- exports.replaceNamesWithIdsInSmartFolder = replaceNamesWithIdsInSmartFolder;
855
- exports.replaceNamesWithIdsInView = replaceNamesWithIdsInView;