@fibery/views 10.1.0 → 10.3.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
@@ -153,23 +153,17 @@ const migrateUnit = (schema, fromType, unit, units) => {
153
153
  type,
154
154
  expression
155
155
  } = unit;
156
- if (type === "date") {
157
- const [field] = expression;
158
- if (getFieldType(schema, fromType, field) === "fibery/date-time") {
159
- return {
160
- ...unit,
161
- type: "date-time"
162
- };
163
- }
156
+ if (type === "date-time") {
157
+ return {
158
+ ...unit,
159
+ type: "date"
160
+ };
164
161
  }
165
- if (type === "date-range") {
166
- const [field] = expression;
167
- if (getFieldType(schema, fromType, field) === "fibery/date-time-range") {
168
- return {
169
- ...unit,
170
- type: "date-time-range"
171
- };
172
- }
162
+ if (type === "date-time-range") {
163
+ return {
164
+ ...unit,
165
+ type: "date-range"
166
+ };
173
167
  }
174
168
  if (type === "text") {
175
169
  const [field] = expression;
@@ -244,6 +238,15 @@ const fixViewUnit = (schema, fromType, unit, units, {
244
238
  }
245
239
  return migrated;
246
240
  };
241
+ const enableHideWhenEmptyForCheckedEditableUnit = unit => {
242
+ if (unit.checked) {
243
+ return {
244
+ ...unit,
245
+ hideWhenEmpty: true
246
+ };
247
+ }
248
+ return unit;
249
+ };
247
250
 
248
251
  const visitQueryExpressionHolder = (queryHolder, visitor) => {
249
252
  if (queryHolder) {
@@ -511,21 +514,13 @@ const enableHideWhenEmptyForCovers = view => {
511
514
  }
512
515
  });
513
516
  };
514
- const enableHideWhenEmptyForCheckedUnits$5 = view => {
517
+ const enableHideWhenEmptyForCheckedEditableUnits$1 = view => {
515
518
  return visitView$5(view, {
516
519
  visitQueryExpression: queryExpression => queryExpression,
517
520
  visitGroupByExpression: groupBy => groupBy,
518
521
  visitExpression: (fromType, expression) => expression,
519
522
  visitEnums: enums => enums,
520
- visitViewUnit: (fromType, unit) => {
521
- if (unit.checked) {
522
- return {
523
- ...unit,
524
- hideWhenEmpty: true
525
- };
526
- }
527
- return unit;
528
- }
523
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
529
524
  });
530
525
  };
531
526
 
@@ -609,21 +604,13 @@ const collectGarbage$6 = view => {
609
604
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
610
605
  });
611
606
  };
612
- const enableHideWhenEmptyForCheckedUnits$4 = view => {
607
+ const enableHideWhenEmptyForCheckedUnits$3 = view => {
613
608
  return visitView$4(view, {
614
609
  visitQueryExpression: queryExpression => queryExpression,
615
610
  visitGroupByExpression: groupBy => groupBy,
616
611
  visitExpression: (fromType, expression) => expression,
617
612
  visitEnums: enums => enums,
618
- visitViewUnit: (fromType, unit) => {
619
- if (unit.checked) {
620
- return {
621
- ...unit,
622
- hideWhenEmpty: true
623
- };
624
- }
625
- return unit;
626
- }
613
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
627
614
  });
628
615
  };
629
616
 
@@ -704,21 +691,13 @@ const collectGarbage$5 = view => {
704
691
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
705
692
  });
706
693
  };
707
- const enableHideWhenEmptyForCheckedUnits$3 = view => {
694
+ const enableHideWhenEmptyForCheckedUnits$2 = view => {
708
695
  return visitView$3(view, {
709
696
  visitQueryExpression: queryExpression => queryExpression,
710
697
  visitGroupByExpression: groupBy => groupBy,
711
698
  visitExpression: (fromType, expression) => expression,
712
699
  visitEnums: enums => enums,
713
- visitViewUnit: (fromType, unit) => {
714
- if (unit.checked) {
715
- return {
716
- ...unit,
717
- hideWhenEmpty: true
718
- };
719
- }
720
- return unit;
721
- }
700
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
722
701
  });
723
702
  };
724
703
 
@@ -862,21 +841,13 @@ const collectGarbage$4 = view => {
862
841
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
863
842
  });
864
843
  };
865
- const enableHideWhenEmptyForCheckedUnits$2 = view => {
844
+ const enableHideWhenEmptyForCheckedUnits$1 = view => {
866
845
  return visitView$2(view, {
867
846
  visitQueryExpression: queryExpression => queryExpression,
868
847
  visitGroupByExpression: groupBy => groupBy,
869
848
  visitExpression: (fromType, expression) => expression,
870
849
  visitEnums: enums => enums,
871
- visitViewUnit: (fromType, unit) => {
872
- if (unit.checked) {
873
- return {
874
- ...unit,
875
- hideWhenEmpty: true
876
- };
877
- }
878
- return unit;
879
- }
850
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
880
851
  });
881
852
  };
882
853
 
@@ -1062,21 +1033,13 @@ const collectGarbage$3 = view => {
1062
1033
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
1063
1034
  });
1064
1035
  };
1065
- const enableHideWhenEmptyForCheckedUnits$1 = view => {
1036
+ const enableHideWhenEmptyForCheckedUnits = view => {
1066
1037
  return visitSmartFolder(view, {
1067
1038
  visitQueryExpression: queryExpression => queryExpression,
1068
1039
  visitGroupByExpression: groupBy => groupBy,
1069
1040
  visitExpression: (fromType, expression) => expression,
1070
1041
  visitEnums: enums => enums,
1071
- visitViewUnit: (fromType, unit) => {
1072
- if (unit.checked) {
1073
- return {
1074
- ...unit,
1075
- hideWhenEmpty: true
1076
- };
1077
- }
1078
- return unit;
1079
- }
1042
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
1080
1043
  });
1081
1044
  };
1082
1045
 
@@ -1159,7 +1122,7 @@ const visitAxis = (axis, visitor) => {
1159
1122
  ...axis,
1160
1123
  query: axis.query && visitor.visitQueryExpression(axis.query),
1161
1124
  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),
1125
+ 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
1126
  groupByExpression: axis.groupByExpression && firstOrNull(visitor.visitExpression(fromType, [axis.groupByExpression]))
1164
1127
  };
1165
1128
  if (!axisResult.query) {
@@ -1317,21 +1280,13 @@ const collectGarbage$1 = view => {
1317
1280
  visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
1318
1281
  });
1319
1282
  };
1320
- const enableHideWhenEmptyForCheckedUnits = view => {
1283
+ const enableHideWhenEmptyForCheckedEditableUnits = view => {
1321
1284
  return visitView(view, {
1322
1285
  visitQueryExpression: queryExpression => queryExpression,
1323
1286
  visitGroupByExpression: groupBy => groupBy,
1324
1287
  visitExpression: (fromType, expression) => expression,
1325
1288
  visitEnums: enums => enums,
1326
- visitViewUnit: (fromType, unit) => {
1327
- if (unit.checked) {
1328
- return {
1329
- ...unit,
1330
- hideWhenEmpty: true
1331
- };
1332
- }
1333
- return unit;
1334
- }
1289
+ visitViewUnit: (fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
1335
1290
  });
1336
1291
  };
1337
1292
 
@@ -1546,18 +1501,18 @@ const migrateHideWhenEmptyToUnitsLevel = view => {
1546
1501
  switch (result["fibery/type"]) {
1547
1502
  case "board":
1548
1503
  result = enableHideWhenEmptyForCovers(result);
1549
- result = enableHideWhenEmptyForCheckedUnits$5(result);
1504
+ result = enableHideWhenEmptyForCheckedEditableUnits$1(result);
1550
1505
  return result;
1551
1506
  case "list":
1552
- return enableHideWhenEmptyForCheckedUnits$1(result);
1553
- case "timeline":
1554
1507
  return enableHideWhenEmptyForCheckedUnits(result);
1508
+ case "timeline":
1509
+ return enableHideWhenEmptyForCheckedEditableUnits(result);
1555
1510
  case "calendar":
1556
- return enableHideWhenEmptyForCheckedUnits$4(result);
1557
- case "feed":
1558
1511
  return enableHideWhenEmptyForCheckedUnits$3(result);
1559
- case "map":
1512
+ case "feed":
1560
1513
  return enableHideWhenEmptyForCheckedUnits$2(result);
1514
+ case "map":
1515
+ return enableHideWhenEmptyForCheckedUnits$1(result);
1561
1516
  default:
1562
1517
  return result;
1563
1518
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "10.1.0",
3
+ "version": "10.3.0",
4
4
  "description": "Operations on view objects",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Fibery",
@@ -18,10 +18,10 @@
18
18
  "jest-junit": "13.0.0",
19
19
  "lodash": "4.17.21",
20
20
  "microbundle": "0.15.1",
21
- "@fibery/babel-preset": "7.4.0",
22
- "@fibery/schema": "10.2.1",
23
21
  "@fibery/eslint-config": "8.6.0",
24
- "@fibery/expression-utils": "9.0.4"
22
+ "@fibery/schema": "10.2.1",
23
+ "@fibery/expression-utils": "9.0.4",
24
+ "@fibery/babel-preset": "7.4.0"
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
- };