@fibery/views 10.1.0 → 10.2.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/lib/views.js CHANGED
@@ -244,6 +244,15 @@ const fixViewUnit = (schema, fromType, unit, units, {
244
244
  }
245
245
  return migrated;
246
246
  };
247
+ const enableHideWhenEmptyForCheckedEditableUnit = unit => {
248
+ if (unit.checked) {
249
+ return {
250
+ ...unit,
251
+ hideWhenEmpty: true
252
+ };
253
+ }
254
+ return unit;
255
+ };
247
256
 
248
257
  const visitQueryExpressionHolder = (queryHolder, visitor) => {
249
258
  if (queryHolder) {
@@ -511,21 +520,13 @@ const enableHideWhenEmptyForCovers = view => {
511
520
  }
512
521
  });
513
522
  };
514
- const enableHideWhenEmptyForCheckedUnits$5 = view => {
523
+ const enableHideWhenEmptyForCheckedEditableUnits$1 = view => {
515
524
  return visitView$5(view, {
516
525
  visitQueryExpression: queryExpression => queryExpression,
517
526
  visitGroupByExpression: groupBy => groupBy,
518
527
  visitExpression: (fromType, expression) => expression,
519
528
  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
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
529
530
  });
530
531
  };
531
532
 
@@ -609,21 +610,13 @@ const collectGarbage$6 = view => {
609
610
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
610
611
  });
611
612
  };
612
- const enableHideWhenEmptyForCheckedUnits$4 = view => {
613
+ const enableHideWhenEmptyForCheckedUnits$3 = view => {
613
614
  return visitView$4(view, {
614
615
  visitQueryExpression: queryExpression => queryExpression,
615
616
  visitGroupByExpression: groupBy => groupBy,
616
617
  visitExpression: (fromType, expression) => expression,
617
618
  visitEnums: enums => enums,
618
- visitViewUnit: (fromType, unit) => {
619
- if (unit.checked) {
620
- return {
621
- ...unit,
622
- hideWhenEmpty: true
623
- };
624
- }
625
- return unit;
626
- }
619
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
627
620
  });
628
621
  };
629
622
 
@@ -704,21 +697,13 @@ const collectGarbage$5 = view => {
704
697
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
705
698
  });
706
699
  };
707
- const enableHideWhenEmptyForCheckedUnits$3 = view => {
700
+ const enableHideWhenEmptyForCheckedUnits$2 = view => {
708
701
  return visitView$3(view, {
709
702
  visitQueryExpression: queryExpression => queryExpression,
710
703
  visitGroupByExpression: groupBy => groupBy,
711
704
  visitExpression: (fromType, expression) => expression,
712
705
  visitEnums: enums => enums,
713
- visitViewUnit: (fromType, unit) => {
714
- if (unit.checked) {
715
- return {
716
- ...unit,
717
- hideWhenEmpty: true
718
- };
719
- }
720
- return unit;
721
- }
706
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
722
707
  });
723
708
  };
724
709
 
@@ -862,21 +847,13 @@ const collectGarbage$4 = view => {
862
847
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
863
848
  });
864
849
  };
865
- const enableHideWhenEmptyForCheckedUnits$2 = view => {
850
+ const enableHideWhenEmptyForCheckedUnits$1 = view => {
866
851
  return visitView$2(view, {
867
852
  visitQueryExpression: queryExpression => queryExpression,
868
853
  visitGroupByExpression: groupBy => groupBy,
869
854
  visitExpression: (fromType, expression) => expression,
870
855
  visitEnums: enums => enums,
871
- visitViewUnit: (fromType, unit) => {
872
- if (unit.checked) {
873
- return {
874
- ...unit,
875
- hideWhenEmpty: true
876
- };
877
- }
878
- return unit;
879
- }
856
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
880
857
  });
881
858
  };
882
859
 
@@ -1062,21 +1039,13 @@ const collectGarbage$3 = view => {
1062
1039
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
1063
1040
  });
1064
1041
  };
1065
- const enableHideWhenEmptyForCheckedUnits$1 = view => {
1042
+ const enableHideWhenEmptyForCheckedUnits = view => {
1066
1043
  return visitSmartFolder(view, {
1067
1044
  visitQueryExpression: queryExpression => queryExpression,
1068
1045
  visitGroupByExpression: groupBy => groupBy,
1069
1046
  visitExpression: (fromType, expression) => expression,
1070
1047
  visitEnums: enums => enums,
1071
- visitViewUnit: (fromType, unit) => {
1072
- if (unit.checked) {
1073
- return {
1074
- ...unit,
1075
- hideWhenEmpty: true
1076
- };
1077
- }
1078
- return unit;
1079
- }
1048
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
1080
1049
  });
1081
1050
  };
1082
1051
 
@@ -1159,7 +1128,7 @@ const visitAxis = (axis, visitor) => {
1159
1128
  ...axis,
1160
1129
  query: axis.query && visitor.visitQueryExpression(axis.query),
1161
1130
  contextExpression: visitContextExpression(fromType, axis.contextExpression, visitor),
1162
- units: axis.units && axis.units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).filter(unit => unit !== REMOVE),
1131
+ units: axis.units && axis.units.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),
1163
1132
  groupByExpression: axis.groupByExpression && firstOrNull(visitor.visitExpression(fromType, [axis.groupByExpression]))
1164
1133
  };
1165
1134
  if (!axisResult.query) {
@@ -1317,21 +1286,13 @@ const collectGarbage$1 = view => {
1317
1286
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
1318
1287
  });
1319
1288
  };
1320
- const enableHideWhenEmptyForCheckedUnits = view => {
1289
+ const enableHideWhenEmptyForCheckedEditableUnits = view => {
1321
1290
  return visitView(view, {
1322
1291
  visitQueryExpression: queryExpression => queryExpression,
1323
1292
  visitGroupByExpression: groupBy => groupBy,
1324
1293
  visitExpression: (fromType, expression) => expression,
1325
1294
  visitEnums: enums => enums,
1326
- visitViewUnit: (fromType, unit) => {
1327
- if (unit.checked) {
1328
- return {
1329
- ...unit,
1330
- hideWhenEmpty: true
1331
- };
1332
- }
1333
- return unit;
1334
- }
1295
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
1335
1296
  });
1336
1297
  };
1337
1298
 
@@ -1546,18 +1507,18 @@ const migrateHideWhenEmptyToUnitsLevel = view => {
1546
1507
  switch (result["fibery/type"]) {
1547
1508
  case "board":
1548
1509
  result = enableHideWhenEmptyForCovers(result);
1549
- result = enableHideWhenEmptyForCheckedUnits$5(result);
1510
+ result = enableHideWhenEmptyForCheckedEditableUnits$1(result);
1550
1511
  return result;
1551
1512
  case "list":
1552
- return enableHideWhenEmptyForCheckedUnits$1(result);
1553
- case "timeline":
1554
1513
  return enableHideWhenEmptyForCheckedUnits(result);
1514
+ case "timeline":
1515
+ return enableHideWhenEmptyForCheckedEditableUnits(result);
1555
1516
  case "calendar":
1556
- return enableHideWhenEmptyForCheckedUnits$4(result);
1557
- case "feed":
1558
1517
  return enableHideWhenEmptyForCheckedUnits$3(result);
1559
- case "map":
1518
+ case "feed":
1560
1519
  return enableHideWhenEmptyForCheckedUnits$2(result);
1520
+ case "map":
1521
+ return enableHideWhenEmptyForCheckedUnits$1(result);
1561
1522
  default:
1562
1523
  return result;
1563
1524
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "10.1.0",
3
+ "version": "10.2.0",
4
4
  "description": "Operations on view objects",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Fibery",
@@ -19,9 +19,9 @@
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.1",
23
22
  "@fibery/eslint-config": "8.6.0",
24
- "@fibery/expression-utils": "9.0.4"
23
+ "@fibery/expression-utils": "9.0.4",
24
+ "@fibery/schema": "10.2.1"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@fibery/expression-utils": "^9.0.4",
package/index.js DELETED
@@ -1 +0,0 @@
1
- export * from "./src";
package/src/index.js DELETED
@@ -1,222 +0,0 @@
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
- };