@fibery/views 10.0.1 → 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,23 +199,6 @@ 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;
210
- }
211
- }
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;
218
- }
219
- }
220
- return REMOVE;
221
- }
222
202
  if (type === "avatar" && !expression) {
223
203
  var _schema$typeObjectsBy;
224
204
  const isAvatarExntensionEnabled = (_schema$typeObjectsBy = schema.typeObjectsByName[fromType]) == null ? void 0 : _schema$typeObjectsBy.installedMixins.has("avatar/avatar-mixin");
@@ -232,6 +212,38 @@ const fixViewUnit = (schema, fromType, unit, units, view) => {
232
212
  }
233
213
  return unit;
234
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;
242
+ }
243
+ }
244
+ }
245
+ return migrated;
246
+ };
235
247
 
236
248
  const visitQueryExpressionHolder = (queryHolder, visitor) => {
237
249
  if (queryHolder) {
@@ -257,7 +269,7 @@ const visitAxisUnits = (axis, fromType, visitor) => {
257
269
  $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
258
270
  },
259
271
  units: {
260
- $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
261
273
  }
262
274
  }) : axis;
263
275
  };
@@ -362,7 +374,7 @@ const visitView$5 = (view, visitor) => immutableUpdate__default["default"](view,
362
374
  $apply: query => query ? visitor.visitQueryExpression(query) : null
363
375
  },
364
376
  units: {
365
- $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
366
378
  },
367
379
  colorCoding: {
368
380
  $apply: colorCodings => {
@@ -439,12 +451,18 @@ const deleteExpressionWithNotFoundFieldsOrTypesViewVisitor = schema => {
439
451
  };
440
452
  return visitor;
441
453
  };
442
- const fixUserSelectedUnitsViewVisitor = schema => {
454
+ const fixUserSelectedUnitsViewVisitor = (schema, {
455
+ unitDefinitions,
456
+ getDefaultUnitTypeForField
457
+ }) => {
443
458
  return {
444
459
  visitQueryExpression: queryExpression => queryExpression,
445
460
  visitExpression: (fromType, expression) => expression,
446
461
  visitEnums: enums => enums,
447
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
462
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
463
+ unitDefinitions,
464
+ getDefaultUnitTypeForField
465
+ })
448
466
  };
449
467
  };
450
468
  const replaceIdsWithNamesInBoardView = (schema, view) => visitView$5(view, replaceIdsWithNamesViewVisitor(schema));
@@ -453,8 +471,14 @@ const deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView = (schema, v
453
471
  const viewNew = visitView$5(view, deleteExpressionWithNotFoundFieldsOrTypesViewVisitor(schema));
454
472
  return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant$1(viewNew) : viewNew;
455
473
  };
456
- const fixUserSelectedUnitsInBoardView = (schema, view) => {
457
- 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
+ }));
458
482
  };
459
483
  const fixContextExpressionWithBrokenPath$7 = (schema, view, defaultContextExpression) => visitView$5(view, {
460
484
  visitQueryExpression: query => query,
@@ -470,6 +494,40 @@ const collectGarbage$7 = view => {
470
494
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
471
495
  });
472
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
+ };
473
531
 
474
532
  const visitView$4 = (view, visitor) => immutableUpdate__default["default"](view, {
475
533
  "fibery/meta": {
@@ -490,7 +548,7 @@ const visitView$4 = (view, visitor) => immutableUpdate__default["default"](view,
490
548
  $apply: query => query ? visitor.visitQueryExpression(query) : null
491
549
  },
492
550
  units: {
493
- $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
494
552
  },
495
553
  colorCoding: {
496
554
  $apply: colorCodings => {
@@ -526,11 +584,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInCalendarView = (schema, view) =
526
584
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
527
585
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
528
586
  });
529
- const fixUserSelectedUnitsInCalendarView = (schema, view) => {
587
+ const fixUserSelectedUnitsInCalendarView = (schema, view, {
588
+ unitDefinitions,
589
+ getDefaultUnitTypeForField
590
+ }) => {
530
591
  return visitView$4(view, {
531
592
  visitExpression: (fromType, expression) => expression,
532
593
  visitQueryExpression: query => query,
533
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
594
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
595
+ unitDefinitions,
596
+ getDefaultUnitTypeForField
597
+ })
534
598
  });
535
599
  };
536
600
  const fixContextExpressionWithBrokenPath$6 = (schema, view, defaultContextExpression) => visitView$4(view, {
@@ -545,6 +609,23 @@ const collectGarbage$6 = view => {
545
609
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
546
610
  });
547
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
+ };
548
629
 
549
630
  const visitView$3 = (view, visitor) => immutableUpdate__default["default"](view, {
550
631
  "fibery/meta": {
@@ -562,7 +643,7 @@ const visitView$3 = (view, visitor) => immutableUpdate__default["default"](view,
562
643
  $apply: query => query ? visitor.visitQueryExpression(query) : null
563
644
  },
564
645
  units: {
565
- $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
566
647
  },
567
648
  colorCoding: {
568
649
  $apply: colorCodings => {
@@ -598,11 +679,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInFeedView = (schema, view) => vi
598
679
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
599
680
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
600
681
  });
601
- const fixUserSelectedUnitsInFeedView = (schema, view) => {
682
+ const fixUserSelectedUnitsInFeedView = (schema, view, {
683
+ unitDefinitions,
684
+ getDefaultUnitTypeForField
685
+ }) => {
602
686
  return visitView$3(view, {
603
687
  visitExpression: (fromType, expression) => expression,
604
688
  visitQueryExpression: query => query,
605
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
689
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
690
+ unitDefinitions,
691
+ getDefaultUnitTypeForField
692
+ })
606
693
  });
607
694
  };
608
695
  const fixContextExpressionWithBrokenPath$5 = (schema, view, defaultContextExpression) => visitView$3(view, {
@@ -617,6 +704,23 @@ const collectGarbage$5 = view => {
617
704
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
618
705
  });
619
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
+ };
620
724
 
621
725
  const replaceNamesWithIdsInFormView = (schema, view) => {
622
726
  var _view$fiberyMeta, _view$fiberyMeta2;
@@ -697,7 +801,7 @@ const visitView$2 = (view, visitor) => immutableUpdate__default["default"](view,
697
801
  $apply: query => query ? visitor.visitQueryExpression(query) : null
698
802
  },
699
803
  units: {
700
- $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
701
805
  },
702
806
  colorCoding: {
703
807
  $apply: colorCodings => {
@@ -733,11 +837,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInMapView = (schema, view) => vis
733
837
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
734
838
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
735
839
  });
736
- const fixUserSelectedUnitsInMapView = (schema, view) => {
840
+ const fixUserSelectedUnitsInMapView = (schema, view, {
841
+ unitDefinitions,
842
+ getDefaultUnitTypeForField
843
+ }) => {
737
844
  return visitView$2(view, {
738
845
  visitQueryExpression: query => query,
739
846
  visitExpression: (fromType, expression) => expression,
740
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
847
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
848
+ unitDefinitions,
849
+ getDefaultUnitTypeForField
850
+ })
741
851
  });
742
852
  };
743
853
  const fixContextExpressionWithBrokenPath$4 = (schema, view, defaultContextExpression) => visitView$2(view, {
@@ -752,6 +862,23 @@ const collectGarbage$4 = view => {
752
862
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
753
863
  });
754
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
+ };
755
882
 
756
883
  const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["default"](smartFolder, {
757
884
  "fibery/meta": {
@@ -897,12 +1024,34 @@ const fixContextExpressionWithBrokenPath$3 = (schema, view, defaultContextExpres
897
1024
  visitExpression: (fromType, expression) => expression,
898
1025
  visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
899
1026
  });
900
- const fixUserSelectedUnitsInSmartFolder = (schema, view) => {
1027
+ const fixUserSelectedUnitsInSmartFolder = (schema, view, {
1028
+ unitDefinitions,
1029
+ getDefaultUnitTypeForField
1030
+ }) => {
901
1031
  return visitSmartFolder(view, {
902
1032
  visitQueryExpression: query => query,
903
1033
  visitGroupByExpression: groupBy => groupBy,
904
1034
  visitExpression: (fromType, expression) => expression,
905
- 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
+ }
906
1055
  });
907
1056
  };
908
1057
  const collectGarbage$3 = view => {
@@ -913,6 +1062,23 @@ const collectGarbage$3 = view => {
913
1062
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
914
1063
  });
915
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
+ };
916
1082
 
917
1083
  const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view, {
918
1084
  "fibery/meta": {
@@ -927,7 +1093,7 @@ const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view,
927
1093
  $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
928
1094
  },
929
1095
  units: {
930
- $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
931
1097
  },
932
1098
  colorCoding: {
933
1099
  $apply: colorCodings => {
@@ -959,10 +1125,16 @@ const deleteExpressionWithNotFoundFieldsOrTypesInTableView = (schema, view) => v
959
1125
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
960
1126
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
961
1127
  });
962
- const fixUserSelectedUnitsInTableView = (schema, view) => visitView$1(view, {
1128
+ const fixUserSelectedUnitsInTableView = (schema, view, {
1129
+ unitDefinitions,
1130
+ getDefaultUnitTypeForField
1131
+ }) => visitView$1(view, {
963
1132
  visitExpression: (fromType, expression) => expression,
964
1133
  visitQueryExpression: query => query,
965
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
1134
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
1135
+ unitDefinitions,
1136
+ getDefaultUnitTypeForField
1137
+ })
966
1138
  });
967
1139
  const fixContextExpressionWithBrokenPath$2 = (schema, view, defaultContextExpression) => visitView$1(view, {
968
1140
  visitExpression: (fromType, expression) => expression,
@@ -1029,7 +1201,7 @@ const visitView = (view, visitor) => immutableUpdate__default["default"](view, {
1029
1201
  $apply: query => query ? visitor.visitQueryExpression(query) : null
1030
1202
  },
1031
1203
  units: {
1032
- $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
1033
1205
  },
1034
1206
  colorCoding: {
1035
1207
  $apply: colorCodings => {
@@ -1120,11 +1292,17 @@ const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, e
1120
1292
  });
1121
1293
  return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant(viewNew) : viewNew;
1122
1294
  };
1123
- const fixUserSelectedUnitsInTimelineView = (schema, view) => {
1295
+ const fixUserSelectedUnitsInTimelineView = (schema, view, {
1296
+ unitDefinitions,
1297
+ getDefaultUnitTypeForField
1298
+ }) => {
1124
1299
  return visitView(view, {
1125
1300
  visitQueryExpression: query => query,
1126
1301
  visitExpression: (fromType, expression) => expression,
1127
- visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
1302
+ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
1303
+ unitDefinitions,
1304
+ getDefaultUnitTypeForField
1305
+ })
1128
1306
  });
1129
1307
  };
1130
1308
  const fixContextExpressionWithBrokenPath$1 = (schema, view, defaultContextExpression) => visitView(view, {
@@ -1139,6 +1317,23 @@ const collectGarbage$1 = view => {
1139
1317
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
1140
1318
  });
1141
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
+ };
1142
1337
 
1143
1338
  const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxisInvariant = true) => {
1144
1339
  switch (view["fibery/type"]) {
@@ -1164,24 +1359,51 @@ const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxi
1164
1359
  return view;
1165
1360
  }
1166
1361
  };
1167
- const fixUserSelectedUnits = (schema, view) => {
1362
+ const fixUserSelectedUnits = (schema, view, {
1363
+ unitDefinitions,
1364
+ getDefaultUnitTypeForField
1365
+ }) => {
1168
1366
  switch (view["fibery/type"]) {
1169
1367
  case "board":
1170
- return fixUserSelectedUnitsInBoardView(schema, view);
1368
+ return fixUserSelectedUnitsInBoardView(schema, view, {
1369
+ unitDefinitions,
1370
+ getDefaultUnitTypeForField
1371
+ });
1171
1372
  case "list":
1172
- return fixUserSelectedUnitsInSmartFolder(schema, view);
1373
+ return fixUserSelectedUnitsInSmartFolder(schema, view, {
1374
+ unitDefinitions,
1375
+ getDefaultUnitTypeForField
1376
+ });
1173
1377
  case "grid":
1174
- return fixUserSelectedUnitsInSmartFolder(schema, view);
1378
+ return fixUserSelectedUnitsInSmartFolder(schema, view, {
1379
+ unitDefinitions,
1380
+ getDefaultUnitTypeForField
1381
+ });
1175
1382
  case "table":
1176
- return fixUserSelectedUnitsInTableView(schema, view);
1383
+ return fixUserSelectedUnitsInTableView(schema, view, {
1384
+ unitDefinitions,
1385
+ getDefaultUnitTypeForField
1386
+ });
1177
1387
  case "timeline":
1178
- return fixUserSelectedUnitsInTimelineView(schema, view);
1388
+ return fixUserSelectedUnitsInTimelineView(schema, view, {
1389
+ unitDefinitions,
1390
+ getDefaultUnitTypeForField
1391
+ });
1179
1392
  case "calendar":
1180
- return fixUserSelectedUnitsInCalendarView(schema, view);
1393
+ return fixUserSelectedUnitsInCalendarView(schema, view, {
1394
+ unitDefinitions,
1395
+ getDefaultUnitTypeForField
1396
+ });
1181
1397
  case "feed":
1182
- return fixUserSelectedUnitsInFeedView(schema, view);
1398
+ return fixUserSelectedUnitsInFeedView(schema, view, {
1399
+ unitDefinitions,
1400
+ getDefaultUnitTypeForField
1401
+ });
1183
1402
  case "map":
1184
- return fixUserSelectedUnitsInMapView(schema, view);
1403
+ return fixUserSelectedUnitsInMapView(schema, view, {
1404
+ unitDefinitions,
1405
+ getDefaultUnitTypeForField
1406
+ });
1185
1407
  default:
1186
1408
  return view;
1187
1409
  }
@@ -1303,6 +1525,43 @@ const getViewCardTypes = ({
1303
1525
  "q/from": type
1304
1526
  }
1305
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
+ };
1306
1565
 
1307
1566
  exports.collectGarbage = collectGarbage;
1308
1567
  exports.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder;
@@ -1310,6 +1569,7 @@ exports.deleteExpressionWithNotFoundFieldsOrTypesInView = deleteExpressionWithNo
1310
1569
  exports.fixContextExpressionWithBrokenPath = fixContextExpressionWithBrokenPath;
1311
1570
  exports.fixUserSelectedUnits = fixUserSelectedUnits;
1312
1571
  exports.getViewCardTypes = getViewCardTypes;
1572
+ exports.migrateHideWhenEmptyToUnitsLevel = migrateHideWhenEmptyToUnitsLevel;
1313
1573
  exports.replaceIdsWithNamesInSmartFolder = replaceIdsWithNamesInSmartFolder;
1314
1574
  exports.replaceIdsWithNamesInView = replaceIdsWithNamesInView;
1315
1575
  exports.replaceNamesWithIdsInSmartFolder = replaceNamesWithIdsInSmartFolder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "10.0.1",
3
+ "version": "10.1.0",
4
4
  "description": "Operations on view objects",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Fibery",
@@ -19,12 +19,12 @@
19
19
  "lodash": "4.17.21",
20
20
  "microbundle": "0.15.1",
21
21
  "@fibery/babel-preset": "7.4.0",
22
- "@fibery/expression-utils": "9.0.1",
22
+ "@fibery/schema": "10.2.1",
23
23
  "@fibery/eslint-config": "8.6.0",
24
- "@fibery/schema": "10.2.1"
24
+ "@fibery/expression-utils": "9.0.4"
25
25
  },
26
26
  "peerDependencies": {
27
- "@fibery/expression-utils": "^9.0.1",
27
+ "@fibery/expression-utils": "^9.0.4",
28
28
  "@fibery/schema": "^10.2.1",
29
29
  "immutability-helper": "^2.4.0",
30
30
  "lodash": "^4.17.21"
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
+ };