@fibery/views 13.0.3 → 14.0.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.
Files changed (3) hide show
  1. package/lib/views.js +69 -18
  2. package/package.json +6 -6
  3. package/src/index.js +228 -0
package/lib/views.js CHANGED
@@ -1292,10 +1292,7 @@ const enableHideWhenEmptyForCheckedUnits = view => {
1292
1292
  });
1293
1293
  };
1294
1294
 
1295
- const visitAxis = (axis, visitor) => {
1296
- if (!axis) {
1297
- return axis;
1298
- }
1295
+ const visitAxisSingle = (axis, visitor) => {
1299
1296
  const fromType = ___default["default"].get(axis, ["query", "q/from"]);
1300
1297
  const firstOrNull = x => ___default["default"].first(x) || null;
1301
1298
  const axisResult = {
@@ -1314,6 +1311,23 @@ const visitAxis = (axis, visitor) => {
1314
1311
  }
1315
1312
  return axisResult;
1316
1313
  };
1314
+ const visitAxis = (axis, visitor) => {
1315
+ if (axis && axis.hasOwnProperty("query")) {
1316
+ return visitAxisSingle(axis, visitor);
1317
+ }
1318
+ if (axis && axis.hasOwnProperty("enums")) {
1319
+ const axisNew = immutableUpdate__default["default"](axis, {
1320
+ enums: {
1321
+ $apply: enums => visitor.visitEnums(enums)
1322
+ }
1323
+ });
1324
+ const {
1325
+ enums
1326
+ } = axisNew;
1327
+ return enums ? axisNew : null;
1328
+ }
1329
+ return axis;
1330
+ };
1317
1331
  const visitView = (view, visitor) => immutableUpdate__default["default"](view, {
1318
1332
  "fibery/meta": {
1319
1333
  y: {
@@ -1403,18 +1417,38 @@ const visitView = (view, visitor) => immutableUpdate__default["default"](view, {
1403
1417
  }
1404
1418
  });
1405
1419
  const replaceNamesWithIdsInTimelineView = (schema, view) => {
1406
- return visitView(view, {
1420
+ const visitor = {
1407
1421
  visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
1408
1422
  visitFilter: (fromType, expression) => replaceNamesWithIdsInFilter(schema, fromType, expression),
1409
- visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
1410
- });
1423
+ visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
1424
+ visitEnums: enums => ___default["default"].entries(enums).reduce((result, [type, axis]) => {
1425
+ if (schema.typeObjectsByName.hasOwnProperty(type)) {
1426
+ const typeObject = schema.typeObjectsByName[type];
1427
+ result[typeObject.id] = visitAxisSingle(axis, visitor);
1428
+ } else {
1429
+ result[type] = axis;
1430
+ }
1431
+ return result;
1432
+ }, {})
1433
+ };
1434
+ return visitView(view, visitor);
1411
1435
  };
1412
1436
  const replaceIdsWithNamesInTimelineView = (schema, view) => {
1413
- return visitView(view, {
1437
+ const visitor = {
1414
1438
  visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
1415
1439
  visitFilter: (fromType, expression) => replaceIdsWithNamesInFilter(schema, fromType, expression),
1416
- visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
1417
- });
1440
+ visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
1441
+ visitEnums: enums => ___default["default"].entries(enums).reduce((result, [typeId, axis]) => {
1442
+ if (schema.typeObjectsById.hasOwnProperty(typeId)) {
1443
+ const typeObject = schema.typeObjectsById[typeId];
1444
+ result[typeObject.name] = visitAxisSingle(axis, visitor);
1445
+ } else {
1446
+ result[typeId] = axis;
1447
+ }
1448
+ return result;
1449
+ }, {})
1450
+ };
1451
+ return visitView(view, visitor);
1418
1452
  };
1419
1453
  const ensureAxisAndItemExpressionInvariant = (view, canGroupMetaItem) => {
1420
1454
  const actions = [];
@@ -1444,11 +1478,25 @@ const ensureAxisAndItemExpressionInvariant = (view, canGroupMetaItem) => {
1444
1478
  return view;
1445
1479
  };
1446
1480
  const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant, canGroupMetaItem = () => true) => {
1447
- const viewNew = visitView(view, {
1481
+ const visitor = {
1448
1482
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
1449
1483
  visitFilter: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInFilter(schema, fromType, expression),
1450
- visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
1451
- });
1484
+ visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression),
1485
+ visitEnums: enums => {
1486
+ const enumsNew = ___default["default"].entries(enums).reduce((result, [type, axis]) => {
1487
+ if (schema.typeObjectsByName.hasOwnProperty(type)) {
1488
+ const typeObject = schema.typeObjectsByName[type];
1489
+ const axisResult = visitAxisSingle(axis, visitor);
1490
+ if (axisResult) {
1491
+ result[typeObject.name] = axisResult;
1492
+ }
1493
+ }
1494
+ return result;
1495
+ }, {});
1496
+ return ___default["default"].isEmpty(enumsNew) ? null : enumsNew;
1497
+ }
1498
+ };
1499
+ const viewNew = visitView(view, visitor);
1452
1500
  return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant(viewNew, canGroupMetaItem) : viewNew;
1453
1501
  };
1454
1502
  const fixUserSelectedUnitsInTimelineView = (schema, view, {
@@ -1462,21 +1510,24 @@ const fixUserSelectedUnitsInTimelineView = (schema, view, {
1462
1510
  visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
1463
1511
  unitDefinitions,
1464
1512
  getDefaultUnitTypeForField
1465
- })
1513
+ }),
1514
+ visitEnums: enums => enums
1466
1515
  });
1467
1516
  };
1468
1517
  const fixContextExpressionWithBrokenPath$1 = (schema, view, defaultContextExpression) => visitView(view, {
1469
1518
  visitExpression: (_fromType, expression) => expression,
1470
1519
  visitFilter: (_fromType, filter) => filter,
1471
1520
  visitQueryExpression: query => query,
1472
- visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression)
1521
+ visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression),
1522
+ visitEnums: enums => enums
1473
1523
  });
1474
1524
  const collectGarbage$1 = view => {
1475
1525
  return visitView(view, {
1476
1526
  visitQueryExpression: query => query,
1477
1527
  visitFilter: (_fromType, filter) => filter,
1478
1528
  visitExpression: (_fromType, expression) => expression,
1479
- visitViewUnit: (_fromType, unit) => unit.checked ? unit : REMOVE
1529
+ visitViewUnit: (_fromType, unit) => unit.checked ? unit : REMOVE,
1530
+ visitEnums: enums => enums
1480
1531
  });
1481
1532
  };
1482
1533
  const enableHideWhenEmptyForCheckedEditableUnits = view => {
@@ -1485,8 +1536,8 @@ const enableHideWhenEmptyForCheckedEditableUnits = view => {
1485
1536
  visitGroupByExpression: groupBy => groupBy,
1486
1537
  visitExpression: (_fromType, expression) => expression,
1487
1538
  visitFilter: (_fromType, filter) => filter,
1488
- visitEnums: enums => enums,
1489
- visitViewUnit: (_fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit)
1539
+ visitViewUnit: (_fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit),
1540
+ visitEnums: enums => enums
1490
1541
  });
1491
1542
  };
1492
1543
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "13.0.3",
3
+ "version": "14.0.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/expression-utils": "9.1.5",
23
- "@fibery/eslint-config": "8.6.1",
24
- "@fibery/schema": "10.2.6"
22
+ "@fibery/expression-utils": "9.2.0",
23
+ "@fibery/schema": "10.2.7",
24
+ "@fibery/eslint-config": "8.6.1"
25
25
  },
26
26
  "peerDependencies": {
27
- "@fibery/expression-utils": "^9.1.5",
28
- "@fibery/schema": "^10.2.6",
27
+ "@fibery/expression-utils": "^9.2.0",
28
+ "@fibery/schema": "^10.2.7",
29
29
  "immutability-helper": "^2.4.0",
30
30
  "lodash": "^4.17.21"
31
31
  },
package/src/index.js ADDED
@@ -0,0 +1,228 @@
1
+ import immutableUpdate from "immutability-helper";
2
+ import _ from "lodash";
3
+ import * as board from "./private/board";
4
+ import * as calendar from "./private/calendar";
5
+ import * as feed from "./private/feed";
6
+ import * as form from "./private/form";
7
+ import * as map from "./private/map";
8
+ import * as smartfolder from "./private/smart-folder";
9
+ import * as timeline from "./private/timeline";
10
+ import {REMOVE} from "./private/utils";
11
+
12
+ export {
13
+ deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder,
14
+ replaceIdsWithNamesInSmartFolder,
15
+ replaceNamesWithIdsInSmartFolder,
16
+ } from "./private/smart-folder";
17
+
18
+ export const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxisInvariant = true) => {
19
+ switch (view["fibery/type"]) {
20
+ case "board":
21
+ return board.deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView(schema, view, ensureAxisInvariant);
22
+ case "list":
23
+ case "grid":
24
+ case "table":
25
+ return smartfolder.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder(schema, view);
26
+ case "timeline":
27
+ return timeline.deleteExpressionWithNotFoundFieldsOrTypesInTimelineView(
28
+ schema,
29
+ view,
30
+ ensureAxisInvariant,
31
+ () => true
32
+ );
33
+ case "gantt":
34
+ return timeline.deleteExpressionWithNotFoundFieldsOrTypesInTimelineView(
35
+ schema,
36
+ view,
37
+ ensureAxisInvariant,
38
+ // Only hierarchy top level meta items can be grouped
39
+ (metaItem) => !metaItem.groupBy
40
+ );
41
+ case "calendar":
42
+ return calendar.deleteExpressionWithNotFoundFieldsOrTypesInCalendarView(schema, view);
43
+ case "feed":
44
+ return feed.deleteExpressionWithNotFoundFieldsOrTypesInFeedView(schema, view);
45
+ case "form":
46
+ return form.deleteExpressionWithNotFoundFieldsOrTypesInFormView(schema, view);
47
+ case "map":
48
+ return map.deleteExpressionWithNotFoundFieldsOrTypesInMapView(schema, view);
49
+ default:
50
+ return view;
51
+ }
52
+ };
53
+
54
+ export const fixUserSelectedUnits = (schema, view, {unitDefinitions, getDefaultUnitTypeForField}) => {
55
+ switch (view["fibery/type"]) {
56
+ case "board":
57
+ return board.fixUserSelectedUnitsInBoardView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
58
+ case "list":
59
+ case "grid":
60
+ case "table":
61
+ return smartfolder.fixUserSelectedUnitsInSmartFolder(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
62
+ case "timeline":
63
+ case "gantt":
64
+ return timeline.fixUserSelectedUnitsInTimelineView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
65
+ case "calendar":
66
+ return calendar.fixUserSelectedUnitsInCalendarView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
67
+ case "feed":
68
+ return feed.fixUserSelectedUnitsInFeedView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
69
+ case "map":
70
+ return map.fixUserSelectedUnitsInMapView(schema, view, {unitDefinitions, getDefaultUnitTypeForField});
71
+ default:
72
+ return view;
73
+ }
74
+ };
75
+
76
+ export const fixContextExpressionWithBrokenPath = (schema, view, defaultContextExpression) => {
77
+ switch (view["fibery/type"]) {
78
+ case "board":
79
+ return board.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
80
+ case "list":
81
+ case "grid":
82
+ case "table":
83
+ return smartfolder.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
84
+ case "timeline":
85
+ case "gantt":
86
+ return timeline.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
87
+ case "calendar":
88
+ return calendar.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
89
+ case "feed":
90
+ return feed.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
91
+ case "map":
92
+ return map.fixContextExpressionWithBrokenPath(schema, view, defaultContextExpression);
93
+ default:
94
+ return view;
95
+ }
96
+ };
97
+
98
+ /**
99
+ * Removes garbage from view's meta to reduce the size.
100
+ */
101
+ export const collectGarbage = (schema, view) => {
102
+ const deleteRemoved = (x) => {
103
+ if (Array.isArray(x)) {
104
+ return x.map(deleteRemoved).filter((y) => y !== REMOVE);
105
+ }
106
+ if (typeof x === "object" && x !== null) {
107
+ let tmp = Object.entries(x);
108
+ tmp = tmp.map((e) => [e[0], deleteRemoved(e[1])]);
109
+ tmp = tmp.filter((e) => e[1] !== REMOVE);
110
+ return Object.fromEntries(tmp);
111
+ }
112
+ return x;
113
+ };
114
+
115
+ switch (view["fibery/type"]) {
116
+ case "board":
117
+ return deleteRemoved(board.collectGarbage(view));
118
+ case "list":
119
+ case "grid":
120
+ case "table":
121
+ return deleteRemoved(smartfolder.collectGarbage(view));
122
+ case "timeline":
123
+ case "gantt":
124
+ return deleteRemoved(timeline.collectGarbage(view));
125
+ case "calendar":
126
+ return deleteRemoved(calendar.collectGarbage(view));
127
+ case "feed":
128
+ return deleteRemoved(feed.collectGarbage(view));
129
+ case "map":
130
+ return deleteRemoved(map.collectGarbage(view));
131
+ default:
132
+ return view;
133
+ }
134
+ };
135
+
136
+ export const replaceNamesWithIdsInView = (schema, view) => {
137
+ switch (view["fibery/type"]) {
138
+ case "board":
139
+ return board.replaceNamesWithIdsInBoardView(schema, view);
140
+ case "list":
141
+ case "grid":
142
+ case "table":
143
+ return smartfolder.replaceNamesWithIdsInSmartFolder(schema, view);
144
+ case "timeline":
145
+ case "gantt":
146
+ return timeline.replaceNamesWithIdsInTimelineView(schema, view);
147
+ case "calendar":
148
+ return calendar.replaceNamesWithIdsInCalendarView(schema, view);
149
+ case "feed":
150
+ return feed.replaceNamesWithIdsInFeedView(schema, view);
151
+ case "form":
152
+ return form.replaceNamesWithIdsInFormView(schema, view);
153
+ case "map":
154
+ return map.replaceNamesWithIdsInMapView(schema, view);
155
+ default:
156
+ return view;
157
+ }
158
+ };
159
+
160
+ export const replaceIdsWithNamesInView = (schema, view) => {
161
+ switch (view["fibery/type"]) {
162
+ case "board":
163
+ return board.replaceIdsWithNamesInBoardView(schema, view);
164
+ case "list":
165
+ case "grid":
166
+ case "table":
167
+ return smartfolder.replaceIdsWithNamesInSmartFolder(schema, view);
168
+ case "timeline":
169
+ case "gantt":
170
+ return timeline.replaceIdsWithNamesInTimelineView(schema, view);
171
+ case "calendar":
172
+ return calendar.replaceIdsWithNamesInCalendarView(schema, view);
173
+ case "feed":
174
+ return feed.replaceIdsWithNamesInFeedView(schema, view);
175
+ case "form":
176
+ return form.replaceIdsWithNamesInFormView(schema, view);
177
+ case "map":
178
+ return map.replaceIdsWithNamesInMapView(schema, view);
179
+ default:
180
+ return view;
181
+ }
182
+ };
183
+
184
+ export const getViewCardTypes = ({"fibery/meta": {items}}) => items.map(({query: {"q/from": type}}) => type);
185
+
186
+ export const migrateHideWhenEmptyToUnitsLevel = (view) => {
187
+ const viewTypesToTransform = ["board", "list", "timeline", "gantt", "calendar", "feed", "map"];
188
+ const viewType = view["fibery/type"];
189
+
190
+ if (!viewTypesToTransform.includes(viewType)) {
191
+ return view;
192
+ }
193
+
194
+ const showEmptyUnitValues = _.get(view, ["fibery/meta", "showEmptyUnitValues"]);
195
+ if (showEmptyUnitValues === undefined) {
196
+ return view;
197
+ }
198
+
199
+ let result = immutableUpdate(view, {
200
+ "fibery/meta": {
201
+ $apply: (x) => _.omit(x, "showEmptyUnitValues"),
202
+ },
203
+ });
204
+
205
+ if (showEmptyUnitValues === true) {
206
+ return result;
207
+ }
208
+
209
+ switch (result["fibery/type"]) {
210
+ case "board":
211
+ result = board.enableHideWhenEmptyForCovers(result);
212
+ result = board.enableHideWhenEmptyForCheckedEditableUnits(result);
213
+ return result;
214
+ case "list":
215
+ return smartfolder.enableHideWhenEmptyForCheckedUnits(result);
216
+ case "timeline":
217
+ case "gantt":
218
+ return timeline.enableHideWhenEmptyForCheckedEditableUnits(result);
219
+ case "calendar":
220
+ return calendar.enableHideWhenEmptyForCheckedUnits(result);
221
+ case "feed":
222
+ return feed.enableHideWhenEmptyForCheckedUnits(result);
223
+ case "map":
224
+ return map.enableHideWhenEmptyForCheckedUnits(result);
225
+ default:
226
+ return result;
227
+ }
228
+ };