@fibery/views 25.1.5 → 26.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.
- package/lib/errors.d.ts +2 -3
- package/lib/field-utils/avatar.d.ts +8 -9
- package/lib/field-utils/back-references.d.ts +4 -5
- package/lib/field-utils/comments.d.ts +5 -6
- package/lib/field-utils/date-time.d.ts +7 -8
- package/lib/field-utils/enum-value.d.ts +6 -7
- package/lib/field-utils/file.d.ts +3 -4
- package/lib/field-utils/icon.d.ts +6 -7
- package/lib/field-utils/number.d.ts +11 -12
- package/lib/field-utils/reference-collection.d.ts +6 -7
- package/lib/field-utils/reference.d.ts +3 -4
- package/lib/field-utils/relation-view.d.ts +2 -3
- package/lib/field-utils/rich-text.d.ts +9 -10
- package/lib/field-utils/text.d.ts +9 -10
- package/lib/field-utils/user-active.d.ts +3 -4
- package/lib/field-utils/user-role.d.ts +3 -4
- package/lib/field-utils/workflow.d.ts +9 -10
- package/lib/filter.d.ts +29 -0
- package/lib/filter.js +0 -0
- package/lib/index.d.ts +57 -21
- package/lib/index.js +101 -94
- package/lib/meta-validation.d.ts +3 -4
- package/lib/private/board.d.ts +218 -14
- package/lib/private/board.js +138 -231
- package/lib/private/calendar.d.ts +213 -13
- package/lib/private/calendar.js +35 -81
- package/lib/private/feed.d.ts +211 -13
- package/lib/private/feed.js +34 -80
- package/lib/private/form.d.ts +52 -7
- package/lib/private/form.js +41 -48
- package/lib/private/map.d.ts +211 -13
- package/lib/private/map.js +34 -80
- package/lib/private/smart-folder.d.ts +118 -29
- package/lib/private/smart-folder.js +70 -148
- package/lib/private/timeline.d.ts +535 -31
- package/lib/private/timeline.js +158 -219
- package/lib/private/units.d.ts +3 -4
- package/lib/private/utils.d.ts +63 -57
- package/lib/private/utils.js +71 -49
- package/lib/refs.d.ts +19 -0
- package/lib/refs.js +0 -0
- package/lib/unit-definitions/avatar-collection.d.ts +29 -4
- package/lib/unit-definitions/avatar-collection.js +1 -1
- package/lib/unit-definitions/avatar-input.d.ts +49 -4
- package/lib/unit-definitions/avatar.d.ts +54 -4
- package/lib/unit-definitions/avatar.js +1 -1
- package/lib/unit-definitions/back-references-list.d.ts +31 -4
- package/lib/unit-definitions/bool-checkbox.d.ts +23 -4
- package/lib/unit-definitions/bool.d.ts +23 -4
- package/lib/unit-definitions/collection-count.d.ts +31 -4
- package/lib/unit-definitions/color-input.d.ts +22 -4
- package/lib/unit-definitions/comments-list.d.ts +63 -4
- package/lib/unit-definitions/date-range-combobox.d.ts +23 -4
- package/lib/unit-definitions/date-range.d.ts +23 -4
- package/lib/unit-definitions/date-time-combobox.d.ts +23 -4
- package/lib/unit-definitions/date.d.ts +23 -4
- package/lib/unit-definitions/email-input.d.ts +23 -4
- package/lib/unit-definitions/email.d.ts +23 -4
- package/lib/unit-definitions/emoji.d.ts +23 -4
- package/lib/unit-definitions/file-collection-count.d.ts +23 -4
- package/lib/unit-definitions/file-compact-collection.d.ts +23 -4
- package/lib/unit-definitions/file-compact-reference.d.ts +27 -4
- package/lib/unit-definitions/file-reference.d.ts +23 -4
- package/lib/unit-definitions/files-gallery.d.ts +23 -4
- package/lib/unit-definitions/files-l-list-item.d.ts +23 -4
- package/lib/unit-definitions/files-l-list.d.ts +23 -4
- package/lib/unit-definitions/files-list-item.d.ts +23 -4
- package/lib/unit-definitions/files-list.d.ts +23 -4
- package/lib/unit-definitions/geometry-preview.d.ts +23 -4
- package/lib/unit-definitions/icon-button.d.ts +28 -4
- package/lib/unit-definitions/icon-input.d.ts +23 -4
- package/lib/unit-definitions/id.d.ts +32 -4
- package/lib/unit-definitions/index.js +2 -2
- package/lib/unit-definitions/json-input.d.ts +22 -4
- package/lib/unit-definitions/location-input.d.ts +23 -4
- package/lib/unit-definitions/location.d.ts +23 -4
- package/lib/unit-definitions/not-found.d.ts +6 -4
- package/lib/unit-definitions/number-input.d.ts +23 -4
- package/lib/unit-definitions/number.d.ts +27 -4
- package/lib/unit-definitions/phone-input.d.ts +23 -4
- package/lib/unit-definitions/phone.d.ts +23 -4
- package/lib/unit-definitions/progress-bar.d.ts +26 -4
- package/lib/unit-definitions/reference-collection-combobox.d.ts +19 -4
- package/lib/unit-definitions/reference-collection-list.d.ts +19 -4
- package/lib/unit-definitions/reference-collection-view.d.ts +19 -4
- package/lib/unit-definitions/reference-collection.d.ts +23 -4
- package/lib/unit-definitions/reference-combobox.d.ts +19 -4
- package/lib/unit-definitions/reference-icon.d.ts +27 -4
- package/lib/unit-definitions/reference.d.ts +27 -4
- package/lib/unit-definitions/rich-text-document.d.ts +23 -4
- package/lib/unit-definitions/rich-text-snippet.d.ts +25 -5
- package/lib/unit-definitions/single-location-preview.d.ts +23 -4
- package/lib/unit-definitions/text-input.d.ts +23 -4
- package/lib/unit-definitions/text.d.ts +23 -4
- package/lib/unit-definitions/title-input.d.ts +24 -4
- package/lib/unit-definitions/title.d.ts +27 -4
- package/lib/unit-definitions/type-badge-abbr.d.ts +15 -4
- package/lib/unit-definitions/type-badge.d.ts +15 -4
- package/lib/unit-definitions/type-icon.d.ts +15 -4
- package/lib/unit-definitions/url-input.d.ts +23 -4
- package/lib/unit-definitions/url.d.ts +23 -4
- package/lib/unit-definitions/user-button.d.ts +13 -4
- package/lib/unit-definitions/user-role-input.d.ts +26 -4
- package/lib/unit-definitions/user-role.d.ts +27 -4
- package/lib/unit-utils/access.d.ts +4 -5
- package/lib/unit-utils/can-edit-field.d.ts +4 -5
- package/lib/unit-utils/common.d.ts +16 -11
- package/lib/unit-utils/decimal.js +4 -4
- package/lib/unit-utils/dynamic-keys.d.ts +8 -9
- package/lib/unit-utils/enums.d.ts +4 -5
- package/lib/unit-utils/formatters.d.ts +15 -16
- package/lib/unit-utils/get-export-value.d.ts +18 -19
- package/lib/unit-utils/get-field-label.d.ts +4 -5
- package/lib/unit-utils/get-unmatched-unit-label.d.ts +2 -3
- package/lib/unit-utils/wrap-normalized-in-expression.d.ts +2 -3
- package/lib/units/board.d.ts +22 -25
- package/lib/units/board.js +2 -1
- package/lib/units/canvas/all-units-data-definitions.js +1 -1
- package/lib/units/canvas/index.d.ts +19 -24
- package/lib/units/canvas/type-badge-abbr.d.ts +13 -35
- package/lib/units/canvas/type-badge.d.ts +13 -35
- package/lib/units/default.d.ts +21 -22
- package/lib/units/default.js +2 -1
- package/lib/units/gallery.d.ts +5 -3
- package/lib/units/gantt.d.ts +23 -24
- package/lib/units/gantt.js +3 -2
- package/lib/units/get-unit-definitions-for-view-type.d.ts +4 -4
- package/lib/units/grid.d.ts +14 -25
- package/lib/units/grid.js +5 -4
- package/lib/units/list.d.ts +17 -26
- package/lib/units/list.js +2 -1
- package/lib/units/make-factory.d.ts +25 -27
- package/lib/units/types.d.ts +19 -13
- package/package.json +8 -8
package/lib/private/timeline.js
CHANGED
|
@@ -1,244 +1,183 @@
|
|
|
1
|
-
import { REMOVE,
|
|
1
|
+
import { REMOVE, deleteNotFoundViewVisitor, identityViewVisitor, replaceIdsWithNamesViewVisitor, replaceNamesWithIdsViewVisitor, resetContextExpressionIfBroken, reuseIfUnchanged, typeObjectById, typeObjectByName, visitColorCoding, visitContextExpression, visitUnits } from "./utils.js";
|
|
2
2
|
import { enableHideWhenEmptyForCheckedEditableUnit, fixViewUnit } from "./units.js";
|
|
3
3
|
import { deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression, replaceIdsWithNamesInGroupByExpression, replaceNamesWithIdsInGroupByExpression } from "./smart-folder.js";
|
|
4
4
|
import { truthy } from "@fibery/helpers/src/_";
|
|
5
|
-
import get from "lodash/get.js";
|
|
6
|
-
import entries from "lodash/entries.js";
|
|
7
|
-
import isEmpty from "lodash/isEmpty.js";
|
|
8
|
-
import set from "lodash/set.js";
|
|
9
|
-
import some from "lodash/some.js";
|
|
10
|
-
import has from "lodash/has.js";
|
|
11
5
|
//#region src/private/timeline.ts
|
|
12
|
-
const
|
|
6
|
+
const firstOrNull = (expression) => expression ? expression[0] : null;
|
|
13
7
|
const visitAxisSingle = (axis, visitor) => {
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
const { query, filter, contextExpression, units, groupByExpression, ...rest } = axis;
|
|
9
|
+
const fromType = query?.["q/from"];
|
|
10
|
+
const visitedQuery = query && fromType ? visitor.visitQueryExpression(query) : null;
|
|
11
|
+
if (!fromType || !visitedQuery) return null;
|
|
12
|
+
return {
|
|
13
|
+
...rest,
|
|
14
|
+
filter: filter ? visitor.visitFilter(fromType, filter) : null,
|
|
15
|
+
query: visitedQuery,
|
|
16
|
+
contextExpression: visitContextExpression(fromType, contextExpression, visitor),
|
|
17
|
+
...units ? { units: visitUnits(fromType, units, visitor) } : {},
|
|
18
|
+
groupByExpression: groupByExpression && firstOrNull(visitor.visitExpression(fromType, [groupByExpression]))
|
|
23
19
|
};
|
|
24
|
-
if (!axisResult.query) return null;
|
|
25
|
-
if (!axisResult.units) delete axisResult.units;
|
|
26
|
-
return axisResult;
|
|
27
20
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
21
|
+
function visitEnums(enums, visitor, { mapKey, prune }) {
|
|
22
|
+
const entries = [];
|
|
23
|
+
for (const key in enums) {
|
|
24
|
+
if (!Object.hasOwn(enums, key)) continue;
|
|
25
|
+
const nextKey = mapKey(key);
|
|
26
|
+
const value = enums[key];
|
|
27
|
+
if (!prune && nextKey !== null && String(nextKey) === key) {
|
|
28
|
+
entries.push([nextKey, value]);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const axis = nextKey !== null && value ? visitAxisSingle(value, visitor) : null;
|
|
32
|
+
if (nextKey !== null && (!prune || axis)) entries.push([nextKey, axis]);
|
|
33
|
+
}
|
|
34
|
+
return prune && entries.length === 0 ? null : Object.fromEntries(entries);
|
|
35
|
+
}
|
|
36
|
+
const visitAxis = (axis, visitor, enumKeys) => {
|
|
37
|
+
if (!axis) return axis;
|
|
38
|
+
if (axis.type === ":axis-type/merged-enums") {
|
|
39
|
+
const { enums, ...rest } = axis;
|
|
40
|
+
const visitedEnums = visitEnums(enums, visitor, enumKeys);
|
|
41
|
+
return visitedEnums && {
|
|
42
|
+
...rest,
|
|
43
|
+
enums: visitedEnums
|
|
35
44
|
};
|
|
36
|
-
const { enums } = axisNew;
|
|
37
|
-
return enums ? axisNew : null;
|
|
38
45
|
}
|
|
39
|
-
return axis;
|
|
46
|
+
return visitObjectsAxis(axis, visitor);
|
|
40
47
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
...item,
|
|
49
|
-
dateExpression: item.dateExpression ? visitor.visitExpression(fromType, item.dateExpression) : item.dateExpression,
|
|
50
|
-
filter: item.filter ? visitor.visitFilter(fromType, item.filter) : null,
|
|
51
|
-
query: item.query ? visitor.visitQueryExpression(item.query) : null,
|
|
52
|
-
contextExpression: visitContextExpression(fromType, item.contextExpression, visitor)
|
|
53
|
-
};
|
|
54
|
-
return Object.entries(nextItem).every(([key, value]) => Object.hasOwn(item, key) && item[key] === value) ? item : nextItem;
|
|
55
|
-
}).filter((item) => {
|
|
56
|
-
const { query } = item;
|
|
57
|
-
return query ? item : null;
|
|
58
|
-
});
|
|
48
|
+
function visitObjectsAxis(axis, visitor) {
|
|
49
|
+
if (!Object.hasOwn(axis, "query")) return axis;
|
|
50
|
+
const { type, ...single } = axis;
|
|
51
|
+
const visited = visitAxisSingle(single, visitor);
|
|
52
|
+
return visited && {
|
|
53
|
+
...visited,
|
|
54
|
+
type
|
|
59
55
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
56
|
+
}
|
|
57
|
+
function visitMilestone(milestone, visitor) {
|
|
58
|
+
const { query, filter, dateExpression, contextExpression, ...rest } = milestone;
|
|
59
|
+
const fromType = query?.["q/from"];
|
|
60
|
+
if (!fromType) return query ? milestone : null;
|
|
61
|
+
const visitedQuery = visitor.visitQueryExpression(query);
|
|
62
|
+
if (!visitedQuery) return null;
|
|
63
|
+
return reuseIfUnchanged(milestone, {
|
|
64
|
+
...rest,
|
|
65
|
+
dateExpression: dateExpression ? visitor.visitExpression(fromType, dateExpression) : dateExpression,
|
|
66
|
+
filter: filter ? visitor.visitFilter(fromType, filter) : null,
|
|
67
|
+
query: visitedQuery,
|
|
68
|
+
contextExpression: visitContextExpression(fromType, contextExpression, visitor)
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function visitItems(items, visitor) {
|
|
72
|
+
const removedItemsIndexes = items.flatMap((item, index) => item.query && visitor.visitQueryExpression(item.query) ? [] : [index]);
|
|
73
|
+
const removedBefore = (groupBy) => Object.keys(groupBy).map((key) => removedItemsIndexes.filter((n) => n < parseInt(key)).length);
|
|
74
|
+
return items.map((item) => {
|
|
75
|
+
const { query, filter, yExpression, startExpression, endExpression, secondaryStartExpression, secondaryEndExpression, contextExpression, units, laneUnits, colorCoding, dependencyExpression, groupBy, groupingExpression, ...rest } = item;
|
|
76
|
+
const fromType = query?.["q/from"];
|
|
77
|
+
if (!fromType) return query ? item : null;
|
|
78
|
+
const visitedQuery = visitor.visitQueryExpression(query);
|
|
79
|
+
if (!visitedQuery) return null;
|
|
80
|
+
const visit = (expression) => expression ? visitor.visitExpression(fromType, expression) : expression;
|
|
81
|
+
return reuseIfUnchanged(item, {
|
|
82
|
+
...rest,
|
|
83
|
+
yExpression: visit(yExpression),
|
|
84
|
+
startExpression: visit(startExpression),
|
|
85
|
+
endExpression: visit(endExpression),
|
|
86
|
+
secondaryStartExpression: visit(secondaryStartExpression),
|
|
87
|
+
secondaryEndExpression: visit(secondaryEndExpression),
|
|
88
|
+
contextExpression: visitContextExpression(fromType, contextExpression, visitor),
|
|
89
|
+
filter: filter ? visitor.visitFilter(fromType, filter) : null,
|
|
90
|
+
query: visitedQuery,
|
|
91
|
+
units: units ? visitUnits(fromType, units.filter(truthy), visitor) : void 0,
|
|
92
|
+
laneUnits: laneUnits ? visitUnits(fromType, laneUnits.filter(truthy), visitor) : void 0,
|
|
93
|
+
colorCoding: colorCoding ? visitColorCoding(fromType, colorCoding, visitor) : colorCoding,
|
|
94
|
+
dependencyExpression: dependencyExpression && visitor.visitExpression(fromType, dependencyExpression),
|
|
95
|
+
groupBy: groupBy ? visitor.visitGroupByExpression(groupBy, fromType, removedBefore(groupBy)) : groupBy,
|
|
96
|
+
...Object.hasOwn(item, "groupingExpression") ? { groupingExpression: groupingExpression ? visitor.visitGroupByExpression(groupingExpression, fromType, removedBefore(groupingExpression)) : null } : {}
|
|
100
97
|
});
|
|
98
|
+
}).filter(truthy);
|
|
99
|
+
}
|
|
100
|
+
const visitView = (view, visitor, visitY, canGroupMetaItem) => {
|
|
101
|
+
const { "fibery/meta": meta, ...rest } = view;
|
|
102
|
+
const { items, y, milestones, ...metaRest } = meta;
|
|
103
|
+
const visitedY = visitY(y);
|
|
104
|
+
const visitedItems = visitItems(items, visitor);
|
|
105
|
+
const visitedMilestones = milestones && milestones.map((milestone) => visitMilestone(milestone, visitor)).filter(truthy);
|
|
106
|
+
if (!canGroupMetaItem) return {
|
|
107
|
+
...rest,
|
|
108
|
+
"fibery/meta": {
|
|
109
|
+
...metaRest,
|
|
110
|
+
y: visitedY,
|
|
111
|
+
items: visitedItems,
|
|
112
|
+
milestones: visitedMilestones
|
|
113
|
+
}
|
|
101
114
|
};
|
|
102
|
-
const
|
|
115
|
+
const someGroupableWithoutY = visitedY !== null && visitedItems.some((item) => canGroupMetaItem(item) && item.yExpression === null);
|
|
116
|
+
const resetY = visitedY !== null && (someGroupableWithoutY || visitedItems.length === 0);
|
|
103
117
|
return {
|
|
104
|
-
...
|
|
118
|
+
...rest,
|
|
105
119
|
"fibery/meta": {
|
|
106
|
-
...
|
|
107
|
-
y:
|
|
108
|
-
items:
|
|
109
|
-
|
|
120
|
+
...metaRest,
|
|
121
|
+
y: resetY ? null : visitedY,
|
|
122
|
+
items: visitedItems.map((item) => visitedY !== null && !(someGroupableWithoutY && canGroupMetaItem(item)) ? item : reuseIfUnchanged(item, {
|
|
123
|
+
...item,
|
|
124
|
+
yExpression: null
|
|
125
|
+
})),
|
|
126
|
+
milestones: visitedMilestones
|
|
110
127
|
}
|
|
111
128
|
};
|
|
112
129
|
};
|
|
130
|
+
const identityTimelineVisitor = (overrides = {}) => ({
|
|
131
|
+
...identityViewVisitor(overrides),
|
|
132
|
+
visitGroupByExpression: (groupBy) => groupBy
|
|
133
|
+
});
|
|
134
|
+
const replaceNamesWithIdsVisitor = (schema) => ({
|
|
135
|
+
...replaceNamesWithIdsViewVisitor(schema),
|
|
136
|
+
visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType)
|
|
137
|
+
});
|
|
138
|
+
const replaceIdsWithNamesVisitor = (schema) => ({
|
|
139
|
+
...replaceIdsWithNamesViewVisitor(schema),
|
|
140
|
+
visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType)
|
|
141
|
+
});
|
|
142
|
+
const deleteNotFoundVisitor = (schema) => ({
|
|
143
|
+
...deleteNotFoundViewVisitor(schema),
|
|
144
|
+
visitGroupByExpression: (groupBy, fromType, removedItems) => deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression(schema, groupBy, fromType, removedItems)
|
|
145
|
+
});
|
|
113
146
|
const replaceNamesWithIdsInTimelineView = (schema, view) => {
|
|
114
|
-
const visitor =
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const typeObject = schema.getTypeObjectByName(type);
|
|
120
|
-
if (!typeObject) {
|
|
121
|
-
result[type] = axis;
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
result[typeObject.id] = visitAxisSingle(axis, visitor);
|
|
125
|
-
return result;
|
|
126
|
-
}, {}),
|
|
127
|
-
visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType)
|
|
128
|
-
};
|
|
129
|
-
return visitView(view, visitor);
|
|
147
|
+
const visitor = replaceNamesWithIdsVisitor(schema);
|
|
148
|
+
return visitView(view, visitor, (y) => visitAxis(y, visitor, {
|
|
149
|
+
mapKey: (typeName) => typeObjectByName(schema, typeName)?.id ?? typeName,
|
|
150
|
+
prune: false
|
|
151
|
+
}));
|
|
130
152
|
};
|
|
131
153
|
const replaceIdsWithNamesInTimelineView = (schema, view) => {
|
|
132
|
-
const visitor =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const typeObject = schema.getTypeObjectById(typeId);
|
|
138
|
-
if (!typeObject) {
|
|
139
|
-
result[typeId] = axis;
|
|
140
|
-
return result;
|
|
141
|
-
}
|
|
142
|
-
result[typeObject.name] = visitAxisSingle(axis, visitor);
|
|
143
|
-
return result;
|
|
144
|
-
}, {}),
|
|
145
|
-
visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType)
|
|
146
|
-
};
|
|
147
|
-
return visitView(view, visitor);
|
|
148
|
-
};
|
|
149
|
-
const ensureAxisAndItemExpressionInvariant = (view, canGroupMetaItem) => {
|
|
150
|
-
const actions = [];
|
|
151
|
-
const y = get(view, ["fibery/meta", "y"]);
|
|
152
|
-
const yQuery = get(view, [
|
|
153
|
-
"fibery/meta",
|
|
154
|
-
"y",
|
|
155
|
-
"query"
|
|
156
|
-
]);
|
|
157
|
-
const yGroupByExpression = get(view, [
|
|
158
|
-
"fibery/meta",
|
|
159
|
-
"y",
|
|
160
|
-
"groupByExpression"
|
|
161
|
-
]);
|
|
162
|
-
const items = get(view, ["fibery/meta", "items"]);
|
|
163
|
-
if (yQuery === null && yGroupByExpression !== null) actions.push(() => set(view, [
|
|
164
|
-
"fibery/meta",
|
|
165
|
-
"y",
|
|
166
|
-
"groupByExpression"
|
|
167
|
-
], null));
|
|
168
|
-
if (y === null) {
|
|
169
|
-
const resetActions = items.map((item) => () => item.yExpression = null);
|
|
170
|
-
actions.push(...resetActions);
|
|
171
|
-
}
|
|
172
|
-
const filteredMetaItems = items.filter(canGroupMetaItem);
|
|
173
|
-
if (y !== null && some(filteredMetaItems, ({ yExpression }) => yExpression === null)) {
|
|
174
|
-
const resetActions = filteredMetaItems.map((item) => () => item.yExpression = null);
|
|
175
|
-
actions.push(...resetActions);
|
|
176
|
-
actions.push(() => set(view, ["fibery/meta", "y"], null));
|
|
177
|
-
}
|
|
178
|
-
if (y !== null && isEmpty(items)) actions.push(() => set(view, ["fibery/meta", "y"], null));
|
|
179
|
-
actions.forEach((action) => action());
|
|
180
|
-
return view;
|
|
181
|
-
};
|
|
182
|
-
const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant, canGroupMetaItem = (_metaItem) => true) => {
|
|
183
|
-
const visitor = {
|
|
184
|
-
visitQueryExpression: (queryExpression) => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, queryExpression),
|
|
185
|
-
visitFilter: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInFilter(schema, fromType, expression),
|
|
186
|
-
visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression),
|
|
187
|
-
visitEnums: (enums) => {
|
|
188
|
-
const enumsNew = entries(enums).reduce((result, [type, axis]) => {
|
|
189
|
-
const typeObject = schema.getTypeObjectByName(type);
|
|
190
|
-
if (!typeObject) return result;
|
|
191
|
-
const axisResult = visitAxisSingle(axis, visitor);
|
|
192
|
-
if (axisResult) result[typeObject.name] = axisResult;
|
|
193
|
-
return result;
|
|
194
|
-
}, {});
|
|
195
|
-
return isEmpty(enumsNew) ? null : enumsNew;
|
|
196
|
-
},
|
|
197
|
-
visitGroupByExpression: (groupBy, fromType, removedItems) => deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression(schema, groupBy, fromType, removedItems)
|
|
198
|
-
};
|
|
199
|
-
const viewNew = visitView(view, visitor);
|
|
200
|
-
return ensureAxisInvariant ? ensureAxisAndItemExpressionInvariant(viewNew, canGroupMetaItem) : viewNew;
|
|
154
|
+
const visitor = replaceIdsWithNamesVisitor(schema);
|
|
155
|
+
return visitView(view, visitor, (y) => visitAxis(y, visitor, {
|
|
156
|
+
mapKey: (typeId) => typeObjectById(schema, typeId)?.name ?? typeId,
|
|
157
|
+
prune: false
|
|
158
|
+
}));
|
|
201
159
|
};
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
unitDefinitions,
|
|
209
|
-
getDefaultUnitTypeForField
|
|
210
|
-
}),
|
|
211
|
-
visitEnums: (enums) => enums,
|
|
212
|
-
visitGroupByExpression: (groupBy) => groupBy
|
|
213
|
-
});
|
|
160
|
+
const deleteExpressionWithNotFoundFieldsOrTypesInTimelineView = (schema, view, ensureAxisInvariant, canGroupMetaItem = () => true) => {
|
|
161
|
+
const visitor = deleteNotFoundVisitor(schema);
|
|
162
|
+
return visitView(view, visitor, (y) => visitAxis(y, visitor, {
|
|
163
|
+
mapKey: (type) => schema.getTypeObjectByName(type)?.name ?? null,
|
|
164
|
+
prune: true
|
|
165
|
+
}), ensureAxisInvariant ? canGroupMetaItem : void 0);
|
|
214
166
|
};
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
visitGroupByExpression: (groupBy) => groupBy
|
|
222
|
-
});
|
|
223
|
-
const collectGarbage = (view) => {
|
|
224
|
-
return visitView(view, {
|
|
225
|
-
visitQueryExpression: (query) => query,
|
|
226
|
-
visitFilter: (_fromType, filter) => filter,
|
|
227
|
-
visitExpression: (_fromType, expression) => expression,
|
|
228
|
-
visitViewUnit: (_fromType, unit) => unit.checked ? unit : REMOVE,
|
|
229
|
-
visitEnums: (enums) => enums,
|
|
230
|
-
visitGroupByExpression: (groupBy) => groupBy
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
const enableHideWhenEmptyForCheckedEditableUnits = (view) => {
|
|
234
|
-
return visitView(view, {
|
|
235
|
-
visitQueryExpression: (queryExpression) => queryExpression,
|
|
236
|
-
visitExpression: (_fromType, expression) => expression,
|
|
237
|
-
visitFilter: (_fromType, filter) => filter,
|
|
238
|
-
visitViewUnit: (_fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit),
|
|
239
|
-
visitEnums: (enums) => enums,
|
|
240
|
-
visitGroupByExpression: (groupBy) => groupBy
|
|
241
|
-
});
|
|
167
|
+
const deleteExpressionWithNotFoundFieldsOrTypesInGanttView = (schema, view, ensureAxisInvariant) => {
|
|
168
|
+
const visitor = deleteNotFoundVisitor(schema);
|
|
169
|
+
return visitView(view, visitor, (y) => visitAxis(y, visitor, {
|
|
170
|
+
mapKey: (type) => schema.getTypeObjectByName(type)?.name ?? null,
|
|
171
|
+
prune: true
|
|
172
|
+
}), ensureAxisInvariant ? (metaItem) => !metaItem.groupBy : void 0);
|
|
242
173
|
};
|
|
174
|
+
const visitViewKeepingEnums = (view, visitor) => visitView(view, visitor, (y) => y && y.type === ":axis-type/objects" ? visitObjectsAxis(y, visitor) : y);
|
|
175
|
+
const fixUserSelectedUnitsInTimelineView = (schema, view, { unitDefinitions, getDefaultUnitTypeForField }) => visitViewKeepingEnums(view, identityTimelineVisitor({ visitViewUnit: (fromType, unit, units) => fixViewUnit(schema, fromType, unit, units, {
|
|
176
|
+
unitDefinitions,
|
|
177
|
+
getDefaultUnitTypeForField
|
|
178
|
+
}) }));
|
|
179
|
+
const fixContextExpressionWithBrokenPath = (schema, view, defaultContextExpression) => visitViewKeepingEnums(view, identityTimelineVisitor({ visitContextExpression: (fromType, expression) => resetContextExpressionIfBroken(schema, fromType, expression, defaultContextExpression) }));
|
|
180
|
+
const enableHideWhenEmptyForCheckedEditableUnits = (view) => visitViewKeepingEnums(view, identityTimelineVisitor({ visitViewUnit: (_fromType, unit) => enableHideWhenEmptyForCheckedEditableUnit(unit) }));
|
|
181
|
+
const collectGarbage = (view) => visitViewKeepingEnums(view, identityTimelineVisitor({ visitViewUnit: (_fromType, unit) => unit.checked ? unit : REMOVE }));
|
|
243
182
|
//#endregion
|
|
244
|
-
export { collectGarbage, deleteExpressionWithNotFoundFieldsOrTypesInTimelineView, enableHideWhenEmptyForCheckedEditableUnits, fixContextExpressionWithBrokenPath, fixUserSelectedUnitsInTimelineView, replaceIdsWithNamesInTimelineView, replaceNamesWithIdsInTimelineView };
|
|
183
|
+
export { collectGarbage, deleteExpressionWithNotFoundFieldsOrTypesInGanttView, deleteExpressionWithNotFoundFieldsOrTypesInTimelineView, enableHideWhenEmptyForCheckedEditableUnits, fixContextExpressionWithBrokenPath, fixUserSelectedUnitsInTimelineView, replaceIdsWithNamesInTimelineView, replaceNamesWithIdsInTimelineView, visitViewKeepingEnums };
|
package/lib/private/units.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import { REMOVE, UnitDefinitions } from "./utils.js";
|
|
|
2
2
|
import { FieldObject, Schema } from "@fibery/schema";
|
|
3
3
|
import { Unit } from "@fibery/views/src/units/types";
|
|
4
4
|
//#region src/private/units.d.ts
|
|
5
|
-
declare const fixViewUnit: (schema: Schema, fromType: string, unit: Unit, units: Unit[], { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit }: {
|
|
5
|
+
export declare const fixViewUnit: (schema: Schema, fromType: string, unit: Unit, units: Unit[], { unitDefinitions, getDefaultUnitTypeForField, migrateFileCollectionUnit }: {
|
|
6
6
|
unitDefinitions: UnitDefinitions;
|
|
7
7
|
getDefaultUnitTypeForField: (fieldObject: FieldObject, allowedUnits: Unit[]) => string | undefined;
|
|
8
8
|
migrateFileCollectionUnit?: boolean;
|
|
9
9
|
}) => Unit | typeof REMOVE;
|
|
10
|
-
declare const enableHideWhenEmptyForCheckedEditableUnit: (unit: Unit) => Unit;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { enableHideWhenEmptyForCheckedEditableUnit, fixViewUnit };
|
|
10
|
+
export declare const enableHideWhenEmptyForCheckedEditableUnit: (unit: Unit) => Unit;
|
|
11
|
+
//#endregion
|
package/lib/private/utils.d.ts
CHANGED
|
@@ -1,66 +1,72 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Filter, FilterGroup } from "../filter.js";
|
|
2
|
+
import { FieldObject, Schema, TypeId, TypeName } from "@fibery/schema";
|
|
3
|
+
import { Expression, FieldExpression, Query } from "@fibery/expression-utils/src/types";
|
|
3
4
|
import { Unit } from "@fibery/views/src/units/types";
|
|
4
5
|
//#region src/private/utils.d.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
/** @deprecated Use `Filter | FilterGroup` from `../filter`. */
|
|
7
|
+
export type ViewFilter = Filter | FilterGroup;
|
|
8
|
+
export declare const REMOVE: unique symbol;
|
|
9
|
+
export declare const skipRemove: (unit: Unit | typeof REMOVE) => unit is Unit;
|
|
10
|
+
export type GroupByExpression<E extends Expression = Expression> = Record<string, {
|
|
11
|
+
expression: E;
|
|
12
|
+
}>;
|
|
13
|
+
export type ViewVisitor<From extends string = string, To extends string = From> = {
|
|
14
|
+
visitExpression: <E extends Expression>(fromType: From, expression: E) => E | null;
|
|
15
|
+
visitFilter: (fromType: From, filter: FilterGroup) => FilterGroup | null;
|
|
16
|
+
visitQueryExpression: (query: Query<From>) => Query<To> | null;
|
|
17
|
+
visitViewUnit?: (fromType: From, unit: Unit, units: Unit[]) => Unit | typeof REMOVE;
|
|
18
|
+
visitContextExpression?: (fromType: From, expression: FieldExpression) => FieldExpression;
|
|
19
|
+
visitGroupByExpression?: <E extends Expression>(groupBy: GroupByExpression<E>, fromType: From, removedItems: number[]) => GroupByExpression<E> | null;
|
|
15
20
|
visitUnitGroupKey?: (key: string) => string;
|
|
16
21
|
};
|
|
17
|
-
|
|
22
|
+
export declare const typeObjectById: (schema: Schema, id: string) => import("@fibery/schema").TypeObject | null;
|
|
23
|
+
export declare const typeObjectByName: (schema: Schema, name: string) => import("@fibery/schema").TypeObject | null;
|
|
24
|
+
export type ColorCoding = {
|
|
25
|
+
expression: Expression;
|
|
26
|
+
color: string;
|
|
27
|
+
};
|
|
28
|
+
export type WithMeta<V, M> = Omit<V, "fibery/meta"> & {
|
|
29
|
+
"fibery/meta": M;
|
|
30
|
+
};
|
|
31
|
+
export declare const visitColorCoding: <From extends string>(fromType: From, colorCoding: ColorCoding[], visitor: Pick<ViewVisitor<From>, "visitExpression">) => {
|
|
32
|
+
color: string;
|
|
33
|
+
expression: Expression;
|
|
34
|
+
}[];
|
|
35
|
+
export type UnitDefinitions = {
|
|
18
36
|
getUnitsForField: (fieldObject: FieldObject, options?: {
|
|
19
37
|
parentFieldObjects?: FieldObject[];
|
|
20
38
|
}) => Unit[];
|
|
21
39
|
};
|
|
22
|
-
type ViewRecord = Record<string, unknown>;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type ViewFilterGroup = {
|
|
31
|
-
kind: "group";
|
|
32
|
-
value: ViewFilter[];
|
|
40
|
+
export type ViewRecord = Record<string, unknown>;
|
|
41
|
+
export declare const reuseIfUnchanged: <T extends object>(prev: object, next: T) => T;
|
|
42
|
+
export declare const deleteExpressionWithNotFoundFieldsOrTypesInFilter: (schema: Schema, fromType: string, filter: FilterGroup) => FilterGroup | null;
|
|
43
|
+
export declare const deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression: (schema: Schema, queryExpression: Query) => Query<TypeName> | null;
|
|
44
|
+
export declare const replaceNamesWithIdsInExpression: <E extends Expression>(schema: Schema, fromType: string, expression: E) => E;
|
|
45
|
+
export declare const replaceIdsWithNamesInExpression: <E extends Expression>(schema: Schema, fromTypeId: string, expression: E) => E;
|
|
46
|
+
export type UnitWithoutExpression = Omit<Unit, "expression"> & {
|
|
47
|
+
expression: null;
|
|
33
48
|
};
|
|
34
|
-
|
|
35
|
-
declare const
|
|
36
|
-
declare const
|
|
37
|
-
declare const
|
|
38
|
-
declare const
|
|
39
|
-
declare const
|
|
40
|
-
declare const
|
|
41
|
-
declare const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
declare const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
59
|
-
declare const deleteExpressionWithNotFoundFieldsOrTypesInExpression: (schema: Schema, fromType: string, expression: Expression) => any;
|
|
60
|
-
declare const resetContextExpressionIfBroken: (schema: Schema, fromType: string, expression: Expression, defaultExpression: Expression) => any;
|
|
61
|
-
declare const isUnitExpressionValid: (unit: Record<string, unknown>) => boolean;
|
|
62
|
-
declare const getFieldObjectsById: (smartFolder: Record<string, unknown>, schema: Schema) => Record<string, FieldObject>;
|
|
63
|
-
declare const replaceIdsWithNamesInUnitGroupKey: (unitGroupKey: string, fieldObjectsById: Record<string, FieldObject>) => string;
|
|
64
|
-
declare const replaceNamesWithIdsInUnitGroupKey: (unitGroupKey: string, schema: Schema) => string;
|
|
65
|
-
//#endregion
|
|
66
|
-
export { REMOVE, UnitDefinitions, ViewFilter, ViewRecord, ViewVisitor, deleteExpressionWithNotFoundFieldsOrTypesInExpression, deleteExpressionWithNotFoundFieldsOrTypesInFilter, deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression, getFieldObjectsById, isUnitExpressionValid, replaceIdsWithNamesInExpression, replaceIdsWithNamesInFilter, replaceIdsWithNamesInQueryExpression, replaceIdsWithNamesInUnitGroupKey, replaceNamesWithIdsInExpression, replaceNamesWithIdsInFilter, replaceNamesWithIdsInQueryExpression, replaceNamesWithIdsInUnitGroupKey, resetContextExpressionIfBroken, skipRemove, visitContextExpression, visitViewUnit };
|
|
49
|
+
export declare const visitViewUnit: <From extends string>(fromType: From, unit: Unit, visitor: Pick<ViewVisitor<From>, "visitExpression">) => Unit | UnitWithoutExpression;
|
|
50
|
+
export declare const visitUnits: <From extends string>(fromType: From, units: Unit[], visitor: Pick<ViewVisitor<From>, "visitExpression" | "visitViewUnit">) => Unit[];
|
|
51
|
+
export declare const visitContextExpression: <From extends string>(fromType: From, contextExpression: FieldExpression | null | undefined, visitor: Pick<ViewVisitor<From>, "visitExpression" | "visitContextExpression">) => FieldExpression | null | undefined;
|
|
52
|
+
export declare const replaceIdsWithNamesInQueryExpression: (schema: Schema, queryExpression: Query<TypeName | TypeId>) => Query<TypeName | TypeId>;
|
|
53
|
+
export declare const replaceIdsWithNamesInFilter: (schema: Schema, fromType: string, filter: FilterGroup | null) => FilterGroup | null;
|
|
54
|
+
export declare const replaceNamesWithIdsInFilter: (schema: Schema, fromType: string, filter: FilterGroup | null) => FilterGroup | null;
|
|
55
|
+
export declare const replaceNamesWithIdsInQueryExpression: (schema: Schema, queryExpression: Query<TypeName | TypeId>) => Query<TypeId | TypeName>;
|
|
56
|
+
export declare const deleteExpressionWithNotFoundFieldsOrTypesInExpression: <E extends Expression>(schema: Schema, fromType: string, expression: E) => E | null;
|
|
57
|
+
export declare const resetContextExpressionIfBroken: <E extends Expression>(schema: Schema, fromType: string, expression: E, defaultExpression: E) => E;
|
|
58
|
+
export declare const isUnitExpressionValid: (unit: Unit | UnitWithoutExpression) => unit is Unit;
|
|
59
|
+
export declare const getFieldObjectsById: (smartFolder: {
|
|
60
|
+
"fibery/meta": {
|
|
61
|
+
items?: {
|
|
62
|
+
query?: Query | null;
|
|
63
|
+
}[] | null;
|
|
64
|
+
};
|
|
65
|
+
}, schema: Schema) => Record<string, FieldObject>;
|
|
66
|
+
export declare const replaceIdsWithNamesInUnitGroupKey: (unitGroupKey: string, fieldObjectsById: Record<string, FieldObject>) => string;
|
|
67
|
+
export declare const replaceNamesWithIdsInUnitGroupKey: (unitGroupKey: string, schema: Schema) => string;
|
|
68
|
+
export declare const replaceIdsWithNamesViewVisitor: (schema: Schema) => ViewVisitor<TypeName | TypeId, TypeName | TypeId>;
|
|
69
|
+
export declare const replaceNamesWithIdsViewVisitor: (schema: Schema) => ViewVisitor<TypeName | TypeId, TypeId | TypeName>;
|
|
70
|
+
export declare const deleteNotFoundViewVisitor: (schema: Schema) => ViewVisitor<string, TypeName>;
|
|
71
|
+
export declare const identityViewVisitor: <From extends string>(overrides?: Partial<ViewVisitor<From>>) => ViewVisitor<From>;
|
|
72
|
+
//#endregion
|