@fibery/views 10.0.0 → 10.1.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/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./src";
package/lib/views.js CHANGED
@@ -127,17 +127,14 @@ const isUnitExpressionValid = unit => {
127
127
  return true;
128
128
  };
129
129
 
130
+ const getField = (schema, fromType, field) => Object.hasOwn(schema.typeObjectsByName, fromType) && Object.hasOwn(schema.typeObjectsByName[fromType].fieldObjectsByName, field) ? schema.typeObjectsByName[fromType].fieldObjectsByName[field] : undefined;
130
131
  const getFieldType = (schema, fromType, field) => {
131
- if (!schema.typeObjectsByName.hasOwnProperty(fromType) || !schema.typeObjectsByName[fromType].fieldObjectsByName.hasOwnProperty(field)) {
132
- return null;
133
- }
134
- return schema.typeObjectsByName[fromType].fieldObjectsByName[field].type;
132
+ var _getField;
133
+ return (_getField = getField(schema, fromType, field)) == null ? void 0 : _getField.type;
135
134
  };
136
135
  const getFieldMeta = (schema, fromType, field) => {
137
- if (!schema.typeObjectsByName.hasOwnProperty(fromType) || !schema.typeObjectsByName[fromType].fieldObjectsByName.hasOwnProperty(field)) {
138
- return null;
139
- }
140
- return schema.typeObjectsByName[fromType].fieldObjectsByName[field].rawMeta;
136
+ var _getField2;
137
+ return (_getField2 = getField(schema, fromType, field)) == null ? void 0 : _getField2.rawMeta;
141
138
  };
142
139
  const getUnitTypeForTextField = fieldMeta => {
143
140
  switch (fieldMeta["ui/type"]) {
@@ -151,7 +148,7 @@ const getUnitTypeForTextField = fieldMeta => {
151
148
  return "text";
152
149
  }
153
150
  };
154
- const fixViewUnit = (schema, fromType, unit, units, view) => {
151
+ const migrateUnit = (schema, fromType, unit, units) => {
155
152
  const {
156
153
  type,
157
154
  expression
@@ -202,24 +199,50 @@ const fixViewUnit = (schema, fromType, unit, units, view) => {
202
199
  };
203
200
  }
204
201
  }
205
- if (type === "progress-bar") {
206
- const [field] = expression;
207
- const fieldMeta = getFieldMeta(schema, fromType, field);
208
- if (!fieldMeta || fieldMeta["ui/number-format"] !== "Percent") {
209
- return REMOVE;
202
+ if (type === "avatar" && !expression) {
203
+ var _schema$typeObjectsBy;
204
+ const isAvatarExntensionEnabled = (_schema$typeObjectsBy = schema.typeObjectsByName[fromType]) == null ? void 0 : _schema$typeObjectsBy.installedMixins.has("avatar/avatar-mixin");
205
+ const hasAvatarExntensionField = getFieldType(schema, fromType, "avatar/avatars") === "fibery/file";
206
+ if (isAvatarExntensionEnabled && hasAvatarExntensionField) {
207
+ return {
208
+ ...unit,
209
+ expression: ["avatar/avatars"]
210
+ };
210
211
  }
211
212
  }
212
- if (type === "rich-text" && (view == null ? void 0 : view["fibery/type"]) === "grid") {
213
- if (unit.checked) {
214
- const snippetsUnits = units == null ? void 0 : units.filter(x => x.type === "rich-text-snippet");
215
- const snippetUnitForField = snippetsUnits == null ? void 0 : snippetsUnits.find(x => ___default["default"].isEqual(x.expression, expression));
216
- if (snippetUnitForField && !snippetUnitForField.checked) {
217
- snippetUnitForField.checked = true;
213
+ return unit;
214
+ };
215
+ const fixViewUnit = (schema, fromType, unit, units, {
216
+ unitDefinitions,
217
+ getDefaultUnitTypeForField
218
+ }) => {
219
+ var _unit$expression;
220
+ const migrated = migrateUnit(schema, fromType, unit);
221
+ const field = (_unit$expression = unit.expression) == null ? void 0 : _unit$expression[0];
222
+ const fieldObject = getField(schema, fromType, field);
223
+ if (fieldObject) {
224
+ const allowedUnits = unitDefinitions.getUnitsForField(fieldObject);
225
+ if (allowedUnits.some(u => u.type === migrated.type)) {
226
+ return migrated;
227
+ } else {
228
+ if (unit.checked) {
229
+ const otherUnitsForField = units.filter(u => u !== unit && u.expression && u.expression[0] === field);
230
+ const hasEnabledUnitForField = otherUnitsForField.some(u => u.checked);
231
+ if (hasEnabledUnitForField) {
232
+ return REMOVE;
233
+ }
234
+ const defaultUnitType = getDefaultUnitTypeForField(fieldObject, allowedUnits);
235
+ const defaultUnit = defaultUnitType && otherUnitsForField.find(u => u.type === defaultUnitType) || otherUnitsForField[0];
236
+ if (defaultUnit) {
237
+ defaultUnit.checked = true;
238
+ return REMOVE;
239
+ }
240
+ } else {
241
+ return REMOVE;
218
242
  }
219
243
  }
220
- return REMOVE;
221
244
  }
222
- return unit;
245
+ return migrated;
223
246
  };
224
247
 
225
248
  const visitQueryExpressionHolder = (queryHolder, visitor) => {
@@ -246,7 +269,7 @@ const visitAxisUnits = (axis, fromType, visitor) => {
246
269
  $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
247
270
  },
248
271
  units: {
249
- $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit).filter(unit => unit !== REMOVE) : undefined
272
+ $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit).filter(unit => unit !== REMOVE) : undefined
250
273
  }
251
274
  }) : axis;
252
275
  };
@@ -351,7 +374,7 @@ const visitView$5 = (view, visitor) => immutableUpdate__default["default"](view,
351
374
  $apply: query => query ? visitor.visitQueryExpression(query) : null
352
375
  },
353
376
  units: {
354
- $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit).filter(unit => unit !== REMOVE) : undefined
377
+ $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit).filter(unit => unit !== REMOVE) : undefined
355
378
  },
356
379
  colorCoding: {
357
380
  $apply: colorCodings => {
@@ -428,12 +451,18 @@ const deleteExpressionWithNotFoundFieldsOrTypesViewVisitor = schema => {
428
451
  };
429
452
  return visitor;
430
453
  };
431
- const fixUserSelectedUnitsViewVisitor = schema => {
454
+ const fixUserSelectedUnitsViewVisitor = (schema, {
455
+ unitDefinitions,
456
+ getDefaultUnitTypeForField
457
+ }) => {
432
458
  return {
433
459
  visitQueryExpression: queryExpression => queryExpression,
434
460
  visitExpression: (fromType, expression) => expression,
435
461
  visitEnums: enums => enums,
436
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
462
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
463
+ unitDefinitions,
464
+ getDefaultUnitTypeForField
465
+ })
437
466
  };
438
467
  };
439
468
  const replaceIdsWithNamesInBoardView = (schema, view) => visitView$5(view, replaceIdsWithNamesViewVisitor(schema));
@@ -442,8 +471,14 @@ const deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView = (schema, v
442
471
  const viewNew = visitView$5(view, deleteExpressionWithNotFoundFieldsOrTypesViewVisitor(schema));
443
472
  return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant$1(viewNew) : viewNew;
444
473
  };
445
- const fixUserSelectedUnitsInBoardView = (schema, view) => {
446
- return visitView$5(view, fixUserSelectedUnitsViewVisitor(schema));
474
+ const fixUserSelectedUnitsInBoardView = (schema, view, {
475
+ unitDefinitions,
476
+ getDefaultUnitTypeForField
477
+ }) => {
478
+ return visitView$5(view, fixUserSelectedUnitsViewVisitor(schema, {
479
+ unitDefinitions,
480
+ getDefaultUnitTypeForField
481
+ }));
447
482
  };
448
483
  const fixContextExpressionWithBrokenPath$7 = (schema, view, defaultContextExpression) => visitView$5(view, {
449
484
  visitQueryExpression: query => query,
@@ -459,6 +494,40 @@ const collectGarbage$7 = view => {
459
494
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
460
495
  });
461
496
  };
497
+ const enableHideWhenEmptyForCovers = view => {
498
+ return immutableUpdate__default["default"](view, {
499
+ "fibery/meta": {
500
+ items: {
501
+ $apply: items => items.map(item => {
502
+ if (!item.coverExpression) {
503
+ return item;
504
+ }
505
+ return {
506
+ ...item,
507
+ coverHideWhenEmpty: true
508
+ };
509
+ })
510
+ }
511
+ }
512
+ });
513
+ };
514
+ const enableHideWhenEmptyForCheckedUnits$5 = view => {
515
+ return visitView$5(view, {
516
+ visitQueryExpression: queryExpression => queryExpression,
517
+ visitGroupByExpression: groupBy => groupBy,
518
+ visitExpression: (fromType, expression) => expression,
519
+ visitEnums: enums => enums,
520
+ visitViewUnit: (fromType, unit) => {
521
+ if (unit.checked) {
522
+ return {
523
+ ...unit,
524
+ hideWhenEmpty: true
525
+ };
526
+ }
527
+ return unit;
528
+ }
529
+ });
530
+ };
462
531
 
463
532
  const visitView$4 = (view, visitor) => immutableUpdate__default["default"](view, {
464
533
  "fibery/meta": {
@@ -479,7 +548,7 @@ const visitView$4 = (view, visitor) => immutableUpdate__default["default"](view,
479
548
  $apply: query => query ? visitor.visitQueryExpression(query) : null
480
549
  },
481
550
  units: {
482
- $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit).filter(unit => unit !== REMOVE) : undefined
551
+ $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit).filter(unit => unit !== REMOVE) : undefined
483
552
  },
484
553
  colorCoding: {
485
554
  $apply: colorCodings => {
@@ -515,11 +584,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInCalendarView = (schema, view) =
515
584
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
516
585
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
517
586
  });
518
- const fixUserSelectedUnitsInCalendarView = (schema, view) => {
587
+ const fixUserSelectedUnitsInCalendarView = (schema, view, {
588
+ unitDefinitions,
589
+ getDefaultUnitTypeForField
590
+ }) => {
519
591
  return visitView$4(view, {
520
592
  visitExpression: (fromType, expression) => expression,
521
593
  visitQueryExpression: query => query,
522
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
594
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
595
+ unitDefinitions,
596
+ getDefaultUnitTypeForField
597
+ })
523
598
  });
524
599
  };
525
600
  const fixContextExpressionWithBrokenPath$6 = (schema, view, defaultContextExpression) => visitView$4(view, {
@@ -534,6 +609,23 @@ const collectGarbage$6 = view => {
534
609
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
535
610
  });
536
611
  };
612
+ const enableHideWhenEmptyForCheckedUnits$4 = view => {
613
+ return visitView$4(view, {
614
+ visitQueryExpression: queryExpression => queryExpression,
615
+ visitGroupByExpression: groupBy => groupBy,
616
+ visitExpression: (fromType, expression) => expression,
617
+ visitEnums: enums => enums,
618
+ visitViewUnit: (fromType, unit) => {
619
+ if (unit.checked) {
620
+ return {
621
+ ...unit,
622
+ hideWhenEmpty: true
623
+ };
624
+ }
625
+ return unit;
626
+ }
627
+ });
628
+ };
537
629
 
538
630
  const visitView$3 = (view, visitor) => immutableUpdate__default["default"](view, {
539
631
  "fibery/meta": {
@@ -551,7 +643,7 @@ const visitView$3 = (view, visitor) => immutableUpdate__default["default"](view,
551
643
  $apply: query => query ? visitor.visitQueryExpression(query) : null
552
644
  },
553
645
  units: {
554
- $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit).filter(unit => unit !== REMOVE) : undefined
646
+ $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit).filter(unit => unit !== REMOVE) : undefined
555
647
  },
556
648
  colorCoding: {
557
649
  $apply: colorCodings => {
@@ -587,11 +679,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInFeedView = (schema, view) => vi
587
679
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
588
680
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
589
681
  });
590
- const fixUserSelectedUnitsInFeedView = (schema, view) => {
682
+ const fixUserSelectedUnitsInFeedView = (schema, view, {
683
+ unitDefinitions,
684
+ getDefaultUnitTypeForField
685
+ }) => {
591
686
  return visitView$3(view, {
592
687
  visitExpression: (fromType, expression) => expression,
593
688
  visitQueryExpression: query => query,
594
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
689
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
690
+ unitDefinitions,
691
+ getDefaultUnitTypeForField
692
+ })
595
693
  });
596
694
  };
597
695
  const fixContextExpressionWithBrokenPath$5 = (schema, view, defaultContextExpression) => visitView$3(view, {
@@ -606,6 +704,23 @@ const collectGarbage$5 = view => {
606
704
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
607
705
  });
608
706
  };
707
+ const enableHideWhenEmptyForCheckedUnits$3 = view => {
708
+ return visitView$3(view, {
709
+ visitQueryExpression: queryExpression => queryExpression,
710
+ visitGroupByExpression: groupBy => groupBy,
711
+ visitExpression: (fromType, expression) => expression,
712
+ visitEnums: enums => enums,
713
+ visitViewUnit: (fromType, unit) => {
714
+ if (unit.checked) {
715
+ return {
716
+ ...unit,
717
+ hideWhenEmpty: true
718
+ };
719
+ }
720
+ return unit;
721
+ }
722
+ });
723
+ };
609
724
 
610
725
  const replaceNamesWithIdsInFormView = (schema, view) => {
611
726
  var _view$fiberyMeta, _view$fiberyMeta2;
@@ -686,7 +801,7 @@ const visitView$2 = (view, visitor) => immutableUpdate__default["default"](view,
686
801
  $apply: query => query ? visitor.visitQueryExpression(query) : null
687
802
  },
688
803
  units: {
689
- $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit).filter(unit => unit !== REMOVE) : undefined
804
+ $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit).filter(unit => unit !== REMOVE) : undefined
690
805
  },
691
806
  colorCoding: {
692
807
  $apply: colorCodings => {
@@ -722,11 +837,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInMapView = (schema, view) => vis
722
837
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
723
838
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
724
839
  });
725
- const fixUserSelectedUnitsInMapView = (schema, view) => {
840
+ const fixUserSelectedUnitsInMapView = (schema, view, {
841
+ unitDefinitions,
842
+ getDefaultUnitTypeForField
843
+ }) => {
726
844
  return visitView$2(view, {
727
845
  visitQueryExpression: query => query,
728
846
  visitExpression: (fromType, expression) => expression,
729
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
847
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
848
+ unitDefinitions,
849
+ getDefaultUnitTypeForField
850
+ })
730
851
  });
731
852
  };
732
853
  const fixContextExpressionWithBrokenPath$4 = (schema, view, defaultContextExpression) => visitView$2(view, {
@@ -741,6 +862,23 @@ const collectGarbage$4 = view => {
741
862
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
742
863
  });
743
864
  };
865
+ const enableHideWhenEmptyForCheckedUnits$2 = view => {
866
+ return visitView$2(view, {
867
+ visitQueryExpression: queryExpression => queryExpression,
868
+ visitGroupByExpression: groupBy => groupBy,
869
+ visitExpression: (fromType, expression) => expression,
870
+ visitEnums: enums => enums,
871
+ visitViewUnit: (fromType, unit) => {
872
+ if (unit.checked) {
873
+ return {
874
+ ...unit,
875
+ hideWhenEmpty: true
876
+ };
877
+ }
878
+ return unit;
879
+ }
880
+ });
881
+ };
744
882
 
745
883
  const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["default"](smartFolder, {
746
884
  "fibery/meta": {
@@ -886,12 +1024,34 @@ const fixContextExpressionWithBrokenPath$3 = (schema, view, defaultContextExpres
886
1024
  visitExpression: (fromType, expression) => expression,
887
1025
  visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
888
1026
  });
889
- const fixUserSelectedUnitsInSmartFolder = (schema, view) => {
1027
+ const fixUserSelectedUnitsInSmartFolder = (schema, view, {
1028
+ unitDefinitions,
1029
+ getDefaultUnitTypeForField
1030
+ }) => {
890
1031
  return visitSmartFolder(view, {
891
1032
  visitQueryExpression: query => query,
892
1033
  visitGroupByExpression: groupBy => groupBy,
893
1034
  visitExpression: (fromType, expression) => expression,
894
- visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, view)
1035
+ visitViewUnit: (fromType, unit, units) => {
1036
+ const {
1037
+ type,
1038
+ expression
1039
+ } = unit;
1040
+ if (type === "rich-text" && (view == null ? void 0 : view["fibery/type"]) === "grid") {
1041
+ if (unit.checked) {
1042
+ const snippetsUnits = units == null ? void 0 : units.filter(x => x.type === "rich-text-snippet");
1043
+ const snippetUnitForField = snippetsUnits == null ? void 0 : snippetsUnits.find(x => ___default["default"].isEqual(x.expression, expression));
1044
+ if (snippetUnitForField && !snippetUnitForField.checked) {
1045
+ snippetUnitForField.checked = true;
1046
+ }
1047
+ }
1048
+ return REMOVE;
1049
+ }
1050
+ return fixViewUnit(schema, fromType, unit, units, {
1051
+ unitDefinitions,
1052
+ getDefaultUnitTypeForField
1053
+ });
1054
+ }
895
1055
  });
896
1056
  };
897
1057
  const collectGarbage$3 = view => {
@@ -902,6 +1062,23 @@ const collectGarbage$3 = view => {
902
1062
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
903
1063
  });
904
1064
  };
1065
+ const enableHideWhenEmptyForCheckedUnits$1 = view => {
1066
+ return visitSmartFolder(view, {
1067
+ visitQueryExpression: queryExpression => queryExpression,
1068
+ visitGroupByExpression: groupBy => groupBy,
1069
+ visitExpression: (fromType, expression) => expression,
1070
+ visitEnums: enums => enums,
1071
+ visitViewUnit: (fromType, unit) => {
1072
+ if (unit.checked) {
1073
+ return {
1074
+ ...unit,
1075
+ hideWhenEmpty: true
1076
+ };
1077
+ }
1078
+ return unit;
1079
+ }
1080
+ });
1081
+ };
905
1082
 
906
1083
  const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view, {
907
1084
  "fibery/meta": {
@@ -916,7 +1093,7 @@ const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view,
916
1093
  $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
917
1094
  },
918
1095
  units: {
919
- $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit).filter(unit => unit !== REMOVE) : undefined
1096
+ $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit).filter(unit => unit !== REMOVE) : undefined
920
1097
  },
921
1098
  colorCoding: {
922
1099
  $apply: colorCodings => {
@@ -948,10 +1125,16 @@ const deleteExpressionWithNotFoundFieldsOrTypesInTableView = (schema, view) => v
948
1125
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
949
1126
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
950
1127
  });
951
- const fixUserSelectedUnitsInTableView = (schema, view) => visitView$1(view, {
1128
+ const fixUserSelectedUnitsInTableView = (schema, view, {
1129
+ unitDefinitions,
1130
+ getDefaultUnitTypeForField
1131
+ }) => visitView$1(view, {
952
1132
  visitExpression: (fromType, expression) => expression,
953
1133
  visitQueryExpression: query => query,
954
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
1134
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
1135
+ unitDefinitions,
1136
+ getDefaultUnitTypeForField
1137
+ })
955
1138
  });
956
1139
  const fixContextExpressionWithBrokenPath$2 = (schema, view, defaultContextExpression) => visitView$1(view, {
957
1140
  visitExpression: (fromType, expression) => expression,
@@ -1018,7 +1201,7 @@ const visitView = (view, visitor) => immutableUpdate__default["default"](view, {
1018
1201
  $apply: query => query ? visitor.visitQueryExpression(query) : null
1019
1202
  },
1020
1203
  units: {
1021
- $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit).filter(unit => unit !== REMOVE) : undefined
1204
+ $apply: units => units ? units.filter(unit => Boolean(unit)).map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map((unit, idx, units) => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit, units) : unit).filter(unit => unit !== REMOVE) : undefined
1022
1205
  },
1023
1206
  colorCoding: {
1024
1207
  $apply: colorCodings => {
@@ -1109,11 +1292,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, e
1109
1292
  });
1110
1293
  return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant(viewNew) : viewNew;
1111
1294
  };
1112
- const fixUserSelectedUnitsInTimelineView = (schema, view) => {
1295
+ const fixUserSelectedUnitsInTimelineView = (schema, view, {
1296
+ unitDefinitions,
1297
+ getDefaultUnitTypeForField
1298
+ }) => {
1113
1299
  return visitView(view, {
1114
1300
  visitQueryExpression: query => query,
1115
1301
  visitExpression: (fromType, expression) => expression,
1116
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
1302
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
1303
+ unitDefinitions,
1304
+ getDefaultUnitTypeForField
1305
+ })
1117
1306
  });
1118
1307
  };
1119
1308
  const fixContextExpressionWithBrokenPath$1 = (schema, view, defaultContextExpression) => visitView(view, {
@@ -1128,6 +1317,23 @@ const collectGarbage$1 = view => {
1128
1317
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
1129
1318
  });
1130
1319
  };
1320
+ const enableHideWhenEmptyForCheckedUnits = view => {
1321
+ return visitView(view, {
1322
+ visitQueryExpression: queryExpression => queryExpression,
1323
+ visitGroupByExpression: groupBy => groupBy,
1324
+ visitExpression: (fromType, expression) => expression,
1325
+ visitEnums: enums => enums,
1326
+ visitViewUnit: (fromType, unit) => {
1327
+ if (unit.checked) {
1328
+ return {
1329
+ ...unit,
1330
+ hideWhenEmpty: true
1331
+ };
1332
+ }
1333
+ return unit;
1334
+ }
1335
+ });
1336
+ };
1131
1337
 
1132
1338
  const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxisInvariant = true) => {
1133
1339
  switch (view["fibery/type"]) {
@@ -1153,24 +1359,51 @@ const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxi
1153
1359
  return view;
1154
1360
  }
1155
1361
  };
1156
- const fixUserSelectedUnits = (schema, view) => {
1362
+ const fixUserSelectedUnits = (schema, view, {
1363
+ unitDefinitions,
1364
+ getDefaultUnitTypeForField
1365
+ }) => {
1157
1366
  switch (view["fibery/type"]) {
1158
1367
  case "board":
1159
- return fixUserSelectedUnitsInBoardView(schema, view);
1368
+ return fixUserSelectedUnitsInBoardView(schema, view, {
1369
+ unitDefinitions,
1370
+ getDefaultUnitTypeForField
1371
+ });
1160
1372
  case "list":
1161
- return fixUserSelectedUnitsInSmartFolder(schema, view);
1373
+ return fixUserSelectedUnitsInSmartFolder(schema, view, {
1374
+ unitDefinitions,
1375
+ getDefaultUnitTypeForField
1376
+ });
1162
1377
  case "grid":
1163
- return fixUserSelectedUnitsInSmartFolder(schema, view);
1378
+ return fixUserSelectedUnitsInSmartFolder(schema, view, {
1379
+ unitDefinitions,
1380
+ getDefaultUnitTypeForField
1381
+ });
1164
1382
  case "table":
1165
- return fixUserSelectedUnitsInTableView(schema, view);
1383
+ return fixUserSelectedUnitsInTableView(schema, view, {
1384
+ unitDefinitions,
1385
+ getDefaultUnitTypeForField
1386
+ });
1166
1387
  case "timeline":
1167
- return fixUserSelectedUnitsInTimelineView(schema, view);
1388
+ return fixUserSelectedUnitsInTimelineView(schema, view, {
1389
+ unitDefinitions,
1390
+ getDefaultUnitTypeForField
1391
+ });
1168
1392
  case "calendar":
1169
- return fixUserSelectedUnitsInCalendarView(schema, view);
1393
+ return fixUserSelectedUnitsInCalendarView(schema, view, {
1394
+ unitDefinitions,
1395
+ getDefaultUnitTypeForField
1396
+ });
1170
1397
  case "feed":
1171
- return fixUserSelectedUnitsInFeedView(schema, view);
1398
+ return fixUserSelectedUnitsInFeedView(schema, view, {
1399
+ unitDefinitions,
1400
+ getDefaultUnitTypeForField
1401
+ });
1172
1402
  case "map":
1173
- return fixUserSelectedUnitsInMapView(schema, view);
1403
+ return fixUserSelectedUnitsInMapView(schema, view, {
1404
+ unitDefinitions,
1405
+ getDefaultUnitTypeForField
1406
+ });
1174
1407
  default:
1175
1408
  return view;
1176
1409
  }
@@ -1292,6 +1525,43 @@ const getViewCardTypes = ({
1292
1525
  "q/from": type
1293
1526
  }
1294
1527
  }) => type);
1528
+ const migrateHideWhenEmptyToUnitsLevel = view => {
1529
+ const viewTypesToTransform = ["board", "list", "timeline", "calendar", "feed", "map"];
1530
+ const viewType = view["fibery/type"];
1531
+ if (!viewTypesToTransform.includes(viewType)) {
1532
+ return view;
1533
+ }
1534
+ const showEmptyUnitValues = ___default["default"].get(view, ["fibery/meta", "showEmptyUnitValues"]);
1535
+ if (showEmptyUnitValues === undefined) {
1536
+ return view;
1537
+ }
1538
+ let result = immutableUpdate__default["default"](view, {
1539
+ "fibery/meta": {
1540
+ $apply: x => ___default["default"].omit(x, "showEmptyUnitValues")
1541
+ }
1542
+ });
1543
+ if (showEmptyUnitValues === true) {
1544
+ return result;
1545
+ }
1546
+ switch (result["fibery/type"]) {
1547
+ case "board":
1548
+ result = enableHideWhenEmptyForCovers(result);
1549
+ result = enableHideWhenEmptyForCheckedUnits$5(result);
1550
+ return result;
1551
+ case "list":
1552
+ return enableHideWhenEmptyForCheckedUnits$1(result);
1553
+ case "timeline":
1554
+ return enableHideWhenEmptyForCheckedUnits(result);
1555
+ case "calendar":
1556
+ return enableHideWhenEmptyForCheckedUnits$4(result);
1557
+ case "feed":
1558
+ return enableHideWhenEmptyForCheckedUnits$3(result);
1559
+ case "map":
1560
+ return enableHideWhenEmptyForCheckedUnits$2(result);
1561
+ default:
1562
+ return result;
1563
+ }
1564
+ };
1295
1565
 
1296
1566
  exports.collectGarbage = collectGarbage;
1297
1567
  exports.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder;
@@ -1299,6 +1569,7 @@ exports.deleteExpressionWithNotFoundFieldsOrTypesInView = deleteExpressionWithNo
1299
1569
  exports.fixContextExpressionWithBrokenPath = fixContextExpressionWithBrokenPath;
1300
1570
  exports.fixUserSelectedUnits = fixUserSelectedUnits;
1301
1571
  exports.getViewCardTypes = getViewCardTypes;
1572
+ exports.migrateHideWhenEmptyToUnitsLevel = migrateHideWhenEmptyToUnitsLevel;
1302
1573
  exports.replaceIdsWithNamesInSmartFolder = replaceIdsWithNamesInSmartFolder;
1303
1574
  exports.replaceIdsWithNamesInView = replaceIdsWithNamesInView;
1304
1575
  exports.replaceNamesWithIdsInSmartFolder = replaceNamesWithIdsInSmartFolder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "10.0.0",
3
+ "version": "10.1.0",
4
4
  "description": "Operations on view objects",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Fibery",
@@ -19,13 +19,13 @@
19
19
  "lodash": "4.17.21",
20
20
  "microbundle": "0.15.1",
21
21
  "@fibery/babel-preset": "7.4.0",
22
- "@fibery/schema": "10.2.0",
22
+ "@fibery/schema": "10.2.1",
23
23
  "@fibery/eslint-config": "8.6.0",
24
- "@fibery/expression-utils": "9.0.0"
24
+ "@fibery/expression-utils": "9.0.4"
25
25
  },
26
26
  "peerDependencies": {
27
- "@fibery/expression-utils": "^9.0.0",
28
- "@fibery/schema": "^10.2.0",
27
+ "@fibery/expression-utils": "^9.0.4",
28
+ "@fibery/schema": "^10.2.1",
29
29
  "immutability-helper": "^2.4.0",
30
30
  "lodash": "^4.17.21"
31
31
  },
package/src/index.js ADDED
@@ -0,0 +1,222 @@
1
+ import * as board from "./private/board";
2
+ import * as calendar from "./private/calendar";
3
+ import * as feed from "./private/feed";
4
+ import * as form from "./private/form";
5
+ import * as map from "./private/map";
6
+ import * as smartfolder from "./private/smart-folder";
7
+ import * as table from "./private/table";
8
+ import * as timeline from "./private/timeline";
9
+ import {REMOVE} from "./private/utils";
10
+ import _ from "lodash";
11
+ import immutableUpdate from "immutability-helper";
12
+
13
+ export {
14
+ deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder,
15
+ replaceIdsWithNamesInSmartFolder,
16
+ replaceNamesWithIdsInSmartFolder,
17
+ } from "./private/smart-folder";
18
+
19
+ export const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxisInvariant = true) => {
20
+ switch (view["fibery/type"]) {
21
+ case "board":
22
+ return board.deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView(schema, view, ensureAxisInvariant);
23
+ case "list":
24
+ return smartfolder.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder(schema, view);
25
+ case "grid":
26
+ return smartfolder.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder(schema, view);
27
+ case "timeline":
28
+ return timeline.deleteExpressionWithNotFoundFieldsOrTypesInTimelineView(schema, view, ensureAxisInvariant);
29
+ case "calendar":
30
+ return calendar.deleteExpressionWithNotFoundFieldsOrTypesInCalendarView(schema, view);
31
+ case "table":
32
+ return table.deleteExpressionWithNotFoundFieldsOrTypesInTableView(schema, view);
33
+ case "feed":
34
+ return feed.deleteExpressionWithNotFoundFieldsOrTypesInFeedView(schema, view);
35
+ case "form":
36
+ return form.deleteExpressionWithNotFoundFieldsOrTypesInFormView(schema, view);
37
+ case "map":
38
+ return map.deleteExpressionWithNotFoundFieldsOrTypesInMapView(schema, view);
39
+ default:
40
+ return view;
41
+ }
42
+ };
43
+
44
+ export const fixUserSelectedUnits = (schema, view, {unitDefinitions, getDefaultUnitTypeForField}) => {
45
+ switch (view["fibery/type"]) {
46
+ case "board":
47
+ return board.fixUserSelectedUnitsInBoardView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
48
+ case "list":
49
+ return smartfolder.fixUserSelectedUnitsInSmartFolder(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
50
+ case "grid":
51
+ return smartfolder.fixUserSelectedUnitsInSmartFolder(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
52
+ case "table":
53
+ return table.fixUserSelectedUnitsInTableView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
54
+ case "timeline":
55
+ return timeline.fixUserSelectedUnitsInTimelineView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
56
+ case "calendar":
57
+ return calendar.fixUserSelectedUnitsInCalendarView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
58
+ case "feed":
59
+ return feed.fixUserSelectedUnitsInFeedView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
60
+ case "map":
61
+ return map.fixUserSelectedUnitsInMapView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
62
+ default:
63
+ return view;
64
+ }
65
+ };
66
+
67
+ export const fixContextExpressionWithBrokenPath = (schema, view, defaultContextExpression) => {
68
+ switch (view["fibery/type"]) {
69
+ case "board":
70
+ return board.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
71
+ case "list":
72
+ return smartfolder.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
73
+ case "grid":
74
+ return smartfolder.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
75
+ case "table":
76
+ return table.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
77
+ case "timeline":
78
+ return timeline.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
79
+ case "calendar":
80
+ return calendar.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
81
+ case "feed":
82
+ return feed.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
83
+ case "map":
84
+ return map.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
85
+ default:
86
+ return view;
87
+ }
88
+ };
89
+
90
+ /**
91
+ * Removes garbage from view's meta to reduce the size.
92
+ */
93
+ export const collectGarbage = (schema, view) => {
94
+ const deleteRemoved = (x) => {
95
+ if (Array.isArray(x)) {
96
+ return x.map(deleteRemoved).filter((y) => y !== REMOVE);
97
+ }
98
+ if (typeof x === "object" && x !== null) {
99
+ let tmp = Object.entries(x);
100
+ tmp = tmp.map((e) => [e[0], deleteRemoved(e[1])]);
101
+ tmp = tmp.filter((e) => e[1] !== REMOVE);
102
+ return Object.fromEntries(tmp);
103
+ }
104
+ return x;
105
+ };
106
+
107
+ switch (view["fibery/type"]) {
108
+ case "board":
109
+ return deleteRemoved(board.collectGarbage(view));
110
+ case "list":
111
+ return deleteRemoved(smartfolder.collectGarbage(view));
112
+ case "grid":
113
+ return deleteRemoved(smartfolder.collectGarbage(view));
114
+ case "table":
115
+ return deleteRemoved(table.collectGarbage(view));
116
+ case "timeline":
117
+ return deleteRemoved(timeline.collectGarbage(view));
118
+ case "calendar":
119
+ return deleteRemoved(calendar.collectGarbage(view));
120
+ case "feed":
121
+ return deleteRemoved(feed.collectGarbage(view));
122
+ case "map":
123
+ return deleteRemoved(map.collectGarbage(view));
124
+ default:
125
+ return view;
126
+ }
127
+ };
128
+
129
+ export const replaceNamesWithIdsInView = (schema, view) => {
130
+ switch (view["fibery/type"]) {
131
+ case "board":
132
+ return board.replaceNamesWithIdsInBoardView(schema, view);
133
+ case "list":
134
+ return smartfolder.replaceNamesWithIdsInSmartFolder(schema, view);
135
+ case "grid":
136
+ return smartfolder.replaceNamesWithIdsInSmartFolder(schema, view);
137
+ case "table":
138
+ return table.replaceNamesWithIdsInTableView(schema, view);
139
+ case "timeline":
140
+ return timeline.replaceNamesWithIdsInTimelineView(schema, view);
141
+ case "calendar":
142
+ return calendar.replaceNamesWithIdsInCalendarView(schema, view);
143
+ case "feed":
144
+ return feed.replaceNamesWithIdsInFeedView(schema, view);
145
+ case "form":
146
+ return form.replaceNamesWithIdsInFormView(schema, view);
147
+ case "map":
148
+ return map.replaceNamesWithIdsInMapView(schema, view);
149
+ default:
150
+ return view;
151
+ }
152
+ };
153
+
154
+ export const replaceIdsWithNamesInView = (schema, view) => {
155
+ switch (view["fibery/type"]) {
156
+ case "board":
157
+ return board.replaceIdsWithNamesInBoardView(schema, view);
158
+ case "list":
159
+ return smartfolder.replaceIdsWithNamesInSmartFolder(schema, view);
160
+ case "grid":
161
+ return smartfolder.replaceIdsWithNamesInSmartFolder(schema, view);
162
+ case "table":
163
+ return table.replaceIdsWithNamesInTableView(schema, view);
164
+ case "timeline":
165
+ return timeline.replaceIdsWithNamesInTimelineView(schema, view);
166
+ case "calendar":
167
+ return calendar.replaceIdsWithNamesInCalendarView(schema, view);
168
+ case "feed":
169
+ return feed.replaceIdsWithNamesInFeedView(schema, view);
170
+ case "form":
171
+ return form.replaceIdsWithNamesInFormView(schema, view);
172
+ case "map":
173
+ return map.replaceIdsWithNamesInMapView(schema, view);
174
+ default:
175
+ return view;
176
+ }
177
+ };
178
+
179
+ export const getViewCardTypes = ({"fibery/meta": {items}}) => items.map(({query: {"q/from": type}}) => type);
180
+
181
+ export const migrateHideWhenEmptyToUnitsLevel = (view) => {
182
+ const viewTypesToTransform = ["board", "list", "timeline", "calendar", "feed", "map"];
183
+ const viewType = view["fibery/type"];
184
+
185
+ if (!viewTypesToTransform.includes(viewType)) {
186
+ return view;
187
+ }
188
+
189
+ const showEmptyUnitValues = _.get(view, ["fibery/meta", "showEmptyUnitValues"]);
190
+ if (showEmptyUnitValues === undefined) {
191
+ return view;
192
+ }
193
+
194
+ let result = immutableUpdate(view, {
195
+ "fibery/meta": {
196
+ $apply: (x) => _.omit(x, "showEmptyUnitValues"),
197
+ },
198
+ });
199
+
200
+ if (showEmptyUnitValues === true) {
201
+ return result;
202
+ }
203
+
204
+ switch (result["fibery/type"]) {
205
+ case "board":
206
+ result = board.enableHideWhenEmptyForCovers(result);
207
+ result = board.enableHideWhenEmptyForCheckedUnits(result);
208
+ return result;
209
+ case "list":
210
+ return smartfolder.enableHideWhenEmptyForCheckedUnits(result);
211
+ case "timeline":
212
+ return timeline.enableHideWhenEmptyForCheckedUnits(result);
213
+ case "calendar":
214
+ return calendar.enableHideWhenEmptyForCheckedUnits(result);
215
+ case "feed":
216
+ return feed.enableHideWhenEmptyForCheckedUnits(result);
217
+ case "map":
218
+ return map.enableHideWhenEmptyForCheckedUnits(result);
219
+ default:
220
+ return result;
221
+ }
222
+ };