@fibery/views 14.0.0 → 14.0.1

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 +79 -60
  2. package/package.json +6 -6
  3. package/src/index.js +0 -228
package/lib/views.js CHANGED
@@ -1217,14 +1217,14 @@ const replaceNamesWithIdsInGroupByExpression = (schema, groupByExpression, fromT
1217
1217
  const replaceNamesWithIdsInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
1218
1218
  visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
1219
1219
  visitFilter: (fromType, expression) => replaceNamesWithIdsInFilter(schema, fromType, expression),
1220
- visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType, Object.keys(groupBy).map(() => 0)),
1220
+ visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType),
1221
1221
  visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
1222
1222
  visitUnitGroupKey: unitGroupKey => replaceNamesWithIdsInUnitGroupKey(unitGroupKey, schema)
1223
1223
  });
1224
1224
  const replaceIdsWithNamesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
1225
1225
  visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
1226
1226
  visitFilter: (fromType, expression) => replaceIdsWithNamesInFilter(schema, fromType, expression),
1227
- visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType, Object.keys(groupBy).map(() => 0)),
1227
+ visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType),
1228
1228
  visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
1229
1229
  visitUnitGroupKey: unitGroupKey => replaceIdsWithNamesInUnitGroupKey(unitGroupKey, getFieldObjectsById(smartFolder, schema))
1230
1230
  });
@@ -1334,56 +1334,69 @@ const visitView = (view, visitor) => immutableUpdate__default["default"](view, {
1334
1334
  $apply: y => visitAxis(y, visitor)
1335
1335
  },
1336
1336
  items: {
1337
- $apply: items => items.map(item => {
1338
- const fromType = ___default["default"].get(item, ["query", "q/from"]);
1339
- return fromType ? immutableUpdate__default["default"](item, {
1340
- yExpression: {
1341
- $apply: yExpression => yExpression ? visitor.visitExpression(fromType, yExpression) : yExpression
1342
- },
1343
- startExpression: {
1344
- $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
1345
- },
1346
- endExpression: {
1347
- $apply: endExpression => endExpression ? visitor.visitExpression(fromType, endExpression) : endExpression
1348
- },
1349
- secondaryStartExpression: {
1350
- $apply: secondaryStartExpression => secondaryStartExpression ? visitor.visitExpression(fromType, secondaryStartExpression) : secondaryStartExpression
1351
- },
1352
- secondaryEndExpression: {
1353
- $apply: secondaryEndExpression => secondaryEndExpression ? visitor.visitExpression(fromType, secondaryEndExpression) : secondaryEndExpression
1354
- },
1355
- contextExpression: {
1356
- $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
1357
- },
1358
- filter: {
1359
- $apply: filter => filter ? visitor.visitFilter(fromType, filter) : null
1360
- },
1361
- query: {
1362
- $apply: query => query ? visitor.visitQueryExpression(query) : null
1363
- },
1364
- units: {
1365
- $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
1366
- },
1367
- colorCoding: {
1368
- $apply: colorCodings => {
1369
- return colorCodings && colorCodings.map(colorCoding => ({
1370
- ...colorCoding,
1371
- expression: visitor.visitExpression(fromType, colorCoding.expression)
1372
- })).filter(colorCoding => colorCoding.expression !== null);
1373
- }
1374
- },
1375
- dependencyExpression: {
1376
- $apply: expression => {
1377
- return expression && visitor.visitExpression(fromType, expression);
1337
+ $apply: items => {
1338
+ const removedItemsIndexes = items.map((item, index) => visitor.visitQueryExpression(item.query) ? null : index).filter(value => value !== null);
1339
+ return items.map(item => {
1340
+ const fromType = ___default["default"].get(item, ["query", "q/from"]);
1341
+ return fromType ? immutableUpdate__default["default"](item, {
1342
+ yExpression: {
1343
+ $apply: yExpression => yExpression ? visitor.visitExpression(fromType, yExpression) : yExpression
1344
+ },
1345
+ startExpression: {
1346
+ $apply: startExpression => startExpression ? visitor.visitExpression(fromType, startExpression) : startExpression
1347
+ },
1348
+ endExpression: {
1349
+ $apply: endExpression => endExpression ? visitor.visitExpression(fromType, endExpression) : endExpression
1350
+ },
1351
+ secondaryStartExpression: {
1352
+ $apply: secondaryStartExpression => secondaryStartExpression ? visitor.visitExpression(fromType, secondaryStartExpression) : secondaryStartExpression
1353
+ },
1354
+ secondaryEndExpression: {
1355
+ $apply: secondaryEndExpression => secondaryEndExpression ? visitor.visitExpression(fromType, secondaryEndExpression) : secondaryEndExpression
1356
+ },
1357
+ contextExpression: {
1358
+ $apply: contextExpression => visitContextExpression(fromType, contextExpression, visitor)
1359
+ },
1360
+ filter: {
1361
+ $apply: filter => filter ? visitor.visitFilter(fromType, filter) : null
1362
+ },
1363
+ query: {
1364
+ $apply: query => query ? visitor.visitQueryExpression(query) : null
1365
+ },
1366
+ units: {
1367
+ $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
1368
+ },
1369
+ colorCoding: {
1370
+ $apply: colorCodings => {
1371
+ return colorCodings && colorCodings.map(colorCoding => ({
1372
+ ...colorCoding,
1373
+ expression: visitor.visitExpression(fromType, colorCoding.expression)
1374
+ })).filter(colorCoding => colorCoding.expression !== null);
1375
+ }
1376
+ },
1377
+ dependencyExpression: {
1378
+ $apply: expression => {
1379
+ return expression && visitor.visitExpression(fromType, expression);
1380
+ }
1381
+ },
1382
+ groupBy: {
1383
+ $apply: groupBy => {
1384
+ if (!groupBy) {
1385
+ return groupBy;
1386
+ }
1387
+ const groupByIndexes = Object.keys(groupBy).map(key => parseInt(key));
1388
+ const removedItemsBeforeTargetLengths = groupByIndexes.map(groupByIndex => removedItemsIndexes.filter(n => n < groupByIndex).length);
1389
+ return visitor.visitGroupByExpression(groupBy, fromType, removedItemsBeforeTargetLengths);
1390
+ }
1378
1391
  }
1379
- }
1380
- }) : item;
1381
- }).filter(item => {
1382
- const {
1383
- query
1384
- } = item;
1385
- return query ? item : null;
1386
- })
1392
+ }) : item;
1393
+ }).filter(item => {
1394
+ const {
1395
+ query
1396
+ } = item;
1397
+ return query ? item : null;
1398
+ });
1399
+ }
1387
1400
  },
1388
1401
  milestones: {
1389
1402
  $apply: milestones => {
@@ -1429,7 +1442,8 @@ const replaceNamesWithIdsInTimelineView = (schema, view) => {
1429
1442
  result[type] = axis;
1430
1443
  }
1431
1444
  return result;
1432
- }, {})
1445
+ }, {}),
1446
+ visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType)
1433
1447
  };
1434
1448
  return visitView(view, visitor);
1435
1449
  };
@@ -1446,7 +1460,8 @@ const replaceIdsWithNamesInTimelineView = (schema, view) => {
1446
1460
  result[typeId] = axis;
1447
1461
  }
1448
1462
  return result;
1449
- }, {})
1463
+ }, {}),
1464
+ visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType)
1450
1465
  };
1451
1466
  return visitView(view, visitor);
1452
1467
  };
@@ -1477,7 +1492,7 @@ const ensureAxisAndItemExpressionInvariant = (view, canGroupMetaItem) => {
1477
1492
  actions.forEach(action => action());
1478
1493
  return view;
1479
1494
  };
1480
- const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant, canGroupMetaItem = () => true) => {
1495
+ const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant, canGroupMetaItem = metaItem => true) => {
1481
1496
  const visitor = {
1482
1497
  visitQueryExpression: queryExpression => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
1483
1498
  visitFilter: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInFilter(schema, fromType, expression),
@@ -1494,7 +1509,8 @@ const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, e
1494
1509
  return result;
1495
1510
  }, {});
1496
1511
  return ___default["default"].isEmpty(enumsNew) ? null : enumsNew;
1497
- }
1512
+ },
1513
+ visitGroupByExpression: (groupBy, fromType, removedItems) => deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression(schema, groupBy, fromType, removedItems)
1498
1514
  };
1499
1515
  const viewNew = visitView(view, visitor);
1500
1516
  return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant(viewNew, canGroupMetaItem) : viewNew;
@@ -1511,7 +1527,8 @@ const fixUserSelectedUnitsInTimelineView = (schema, view, {
1511
1527
  unitDefinitions,
1512
1528
  getDefaultUnitTypeForField
1513
1529
  }),
1514
- visitEnums: enums => enums
1530
+ visitEnums: enums => enums,
1531
+ visitGroupByExpression: groupBy => groupBy
1515
1532
  });
1516
1533
  };
1517
1534
  const fixContextExpressionWithBrokenPath$1 = (schema, view, defaultContextExpression) => visitView(view, {
@@ -1519,7 +1536,8 @@ const fixContextExpressionWithBrokenPath$1 = (schema, view, defaultContextExpres
1519
1536
  visitFilter: (_fromType, filter) => filter,
1520
1537
  visitQueryExpression: query => query,
1521
1538
  visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression),
1522
- visitEnums: enums => enums
1539
+ visitEnums: enums => enums,
1540
+ visitGroupByExpression: groupBy => groupBy
1523
1541
  });
1524
1542
  const collectGarbage$1 = view => {
1525
1543
  return visitView(view, {
@@ -1527,17 +1545,18 @@ const collectGarbage$1 = view => {
1527
1545
  visitFilter: (_fromType, filter) => filter,
1528
1546
  visitExpression: (_fromType, expression) => expression,
1529
1547
  visitViewUnit: (_fromType, unit) => unit.checked ? unit : REMOVE,
1530
- visitEnums: enums => enums
1548
+ visitEnums: enums => enums,
1549
+ visitGroupByExpression: groupBy => groupBy
1531
1550
  });
1532
1551
  };
1533
1552
  const enableHideWhenEmptyForCheckedEditableUnits = view => {
1534
1553
  return visitView(view, {
1535
1554
  visitQueryExpression: queryExpression => queryExpression,
1536
- visitGroupByExpression: groupBy => groupBy,
1537
1555
  visitExpression: (_fromType, expression) => expression,
1538
1556
  visitFilter: (_fromType, filter) => filter,
1539
1557
  visitViewUnit: (_fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit),
1540
- visitEnums: enums => enums
1558
+ visitEnums: enums => enums,
1559
+ visitGroupByExpression: groupBy => groupBy
1541
1560
  });
1542
1561
  };
1543
1562
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "14.0.0",
3
+ "version": "14.0.1",
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.2.0",
23
- "@fibery/schema": "10.2.7",
24
- "@fibery/eslint-config": "8.6.1"
22
+ "@fibery/eslint-config": "8.6.1",
23
+ "@fibery/schema": "10.2.8",
24
+ "@fibery/expression-utils": "9.2.1"
25
25
  },
26
26
  "peerDependencies": {
27
- "@fibery/expression-utils": "^9.2.0",
28
- "@fibery/schema": "^10.2.7",
27
+ "@fibery/expression-utils": "^9.2.1",
28
+ "@fibery/schema": "^10.2.8",
29
29
  "immutability-helper": "^2.4.0",
30
30
  "lodash": "^4.17.21"
31
31
  },
package/src/index.js DELETED
@@ -1,228 +0,0 @@
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
- };