@fibery/views 10.3.0 → 10.5.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 +94 -12
- package/package.json +5 -5
package/lib/views.js
CHANGED
|
@@ -857,7 +857,7 @@ const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["def
|
|
|
857
857
|
$apply: (items = []) => {
|
|
858
858
|
const isOldSmartFolder = !items.every(item => item.hasOwnProperty("groupBy"));
|
|
859
859
|
const removedItemsIndexes = items.map((item, index) => visitor.visitQueryExpression(item.query) ? null : index).filter(value => value !== null);
|
|
860
|
-
return items.map(
|
|
860
|
+
return items.map(item => {
|
|
861
861
|
if (isOldSmartFolder) {
|
|
862
862
|
return item;
|
|
863
863
|
}
|
|
@@ -865,12 +865,16 @@ const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["def
|
|
|
865
865
|
return fromType ? immutableUpdate__default["default"](item, {
|
|
866
866
|
groupBy: {
|
|
867
867
|
$apply: groupBy => {
|
|
868
|
-
|
|
869
|
-
|
|
868
|
+
if (!groupBy) {
|
|
869
|
+
return null;
|
|
870
|
+
}
|
|
871
|
+
const groupByIndexes = Object.keys(groupBy).map(key => parseInt(key));
|
|
872
|
+
const removedItemsBeforeTargetLengths = groupByIndexes.map(groupByIndex => removedItemsIndexes.filter(n => n < groupByIndex).length);
|
|
873
|
+
return visitor.visitGroupByExpression(groupBy, fromType, removedItemsBeforeTargetLengths);
|
|
870
874
|
}
|
|
871
875
|
}
|
|
872
876
|
}) : item;
|
|
873
|
-
}).map(
|
|
877
|
+
}).map(item => {
|
|
874
878
|
if (isOldSmartFolder) {
|
|
875
879
|
return item;
|
|
876
880
|
}
|
|
@@ -878,8 +882,12 @@ const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["def
|
|
|
878
882
|
return fromType ? immutableUpdate__default["default"](item, {
|
|
879
883
|
groupingExpression: {
|
|
880
884
|
$apply: groupingExpression => {
|
|
881
|
-
|
|
882
|
-
|
|
885
|
+
if (!groupingExpression) {
|
|
886
|
+
return null;
|
|
887
|
+
}
|
|
888
|
+
const groupingExpressionIndexes = Object.keys(groupingExpression).map(key => parseInt(key));
|
|
889
|
+
const removedItemsBeforeTargetLengths = groupingExpressionIndexes.map(groupByIndex => removedItemsIndexes.filter(n => n < groupByIndex).length);
|
|
890
|
+
return visitor.visitGroupByExpression(groupingExpression, fromType, removedItemsBeforeTargetLengths);
|
|
883
891
|
}
|
|
884
892
|
}
|
|
885
893
|
}) : item;
|
|
@@ -916,6 +924,32 @@ const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["def
|
|
|
916
924
|
return query ? item : null;
|
|
917
925
|
});
|
|
918
926
|
}
|
|
927
|
+
},
|
|
928
|
+
columnOrderWithIds: {
|
|
929
|
+
$apply: columnOrderWithIds => {
|
|
930
|
+
if (!visitor.visitUnitGroupKey || !columnOrderWithIds) {
|
|
931
|
+
return columnOrderWithIds;
|
|
932
|
+
}
|
|
933
|
+
return columnOrderWithIds.map(key => visitor.visitUnitGroupKey(key));
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
pinnedColumnsWithIds: {
|
|
937
|
+
$apply: pinnedColumnsWithIds => {
|
|
938
|
+
if (!visitor.visitUnitGroupKey || !pinnedColumnsWithIds) {
|
|
939
|
+
return pinnedColumnsWithIds;
|
|
940
|
+
}
|
|
941
|
+
return pinnedColumnsWithIds.map(key => visitor.visitUnitGroupKey(key));
|
|
942
|
+
}
|
|
943
|
+
},
|
|
944
|
+
columnAggFunc: {
|
|
945
|
+
$apply: columnAggFunc => {
|
|
946
|
+
if (!visitor.visitUnitGroupKey || !columnAggFunc) {
|
|
947
|
+
return columnAggFunc;
|
|
948
|
+
}
|
|
949
|
+
return Object.fromEntries(Object.entries(columnAggFunc).map(([key, value]) => {
|
|
950
|
+
return [visitor.visitUnitGroupKey(key), value];
|
|
951
|
+
}));
|
|
952
|
+
}
|
|
919
953
|
}
|
|
920
954
|
}
|
|
921
955
|
});
|
|
@@ -925,10 +959,10 @@ const deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression = (schema, gr
|
|
|
925
959
|
}
|
|
926
960
|
const entries = Object.entries(groupByExpression).map(([index, {
|
|
927
961
|
expression
|
|
928
|
-
}]) => {
|
|
962
|
+
}], groupByIndex) => {
|
|
929
963
|
const visitedExpression = deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression);
|
|
930
964
|
if (visitedExpression) {
|
|
931
|
-
return [`${parseInt(index) - removedItems}`, {
|
|
965
|
+
return [`${parseInt(index) - removedItems[groupByIndex]}`, {
|
|
932
966
|
expression: visitedExpression
|
|
933
967
|
}];
|
|
934
968
|
}
|
|
@@ -976,13 +1010,61 @@ const replaceNamesWithIdsInGroupByExpression = (schema, groupByExpression, fromT
|
|
|
976
1010
|
};
|
|
977
1011
|
const replaceNamesWithIdsInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
|
|
978
1012
|
visitQueryExpression: query => replaceNamesWithIdsInQueryExpression(schema, query),
|
|
979
|
-
visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType),
|
|
980
|
-
visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression)
|
|
1013
|
+
visitGroupByExpression: (groupBy, fromType) => replaceNamesWithIdsInGroupByExpression(schema, groupBy, fromType, Object.keys(groupBy).map(() => 0)),
|
|
1014
|
+
visitExpression: (fromType, expression) => replaceNamesWithIdsInExpression(schema, fromType, expression),
|
|
1015
|
+
visitUnitGroupKey: unitGroupKey => {
|
|
1016
|
+
const keyParts = unitGroupKey.split("|");
|
|
1017
|
+
return keyParts.map(keyPart => {
|
|
1018
|
+
const [unitType, ...rest] = keyPart.split("_");
|
|
1019
|
+
if (unitType === "user-button") {
|
|
1020
|
+
return keyPart;
|
|
1021
|
+
}
|
|
1022
|
+
const name = rest.join("_");
|
|
1023
|
+
if (!name) {
|
|
1024
|
+
return keyPart;
|
|
1025
|
+
}
|
|
1026
|
+
const [type, field] = name.split(":");
|
|
1027
|
+
const fieldObject = schema.typeObjectsByName[type].fieldObjectsByName[field];
|
|
1028
|
+
if (!fieldObject) {
|
|
1029
|
+
return null;
|
|
1030
|
+
}
|
|
1031
|
+
return `${unitType}_${fieldObject.id}`;
|
|
1032
|
+
}).filter(Boolean).join("|");
|
|
1033
|
+
}
|
|
981
1034
|
});
|
|
982
1035
|
const replaceIdsWithNamesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
|
|
983
1036
|
visitQueryExpression: query => replaceIdsWithNamesInQueryExpression(schema, query),
|
|
984
|
-
visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType),
|
|
985
|
-
visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression)
|
|
1037
|
+
visitGroupByExpression: (groupBy, fromType) => replaceIdsWithNamesInGroupByExpression(schema, groupBy, fromType, Object.keys(groupBy).map(() => 0)),
|
|
1038
|
+
visitExpression: (fromType, expression) => replaceIdsWithNamesInExpression(schema, fromType, expression),
|
|
1039
|
+
visitUnitGroupKey: unitGroupKey => {
|
|
1040
|
+
const types = smartFolder["fibery/meta"].items.map(item => item.query["q/from"]);
|
|
1041
|
+
const fieldObjectsById = types.reduce((acc, type) => {
|
|
1042
|
+
if (!(type in schema.typeObjectsById)) {
|
|
1043
|
+
return acc;
|
|
1044
|
+
}
|
|
1045
|
+
const fieldObjects = schema.typeObjectsById[type].fieldObjectsById;
|
|
1046
|
+
return {
|
|
1047
|
+
...acc,
|
|
1048
|
+
...fieldObjects
|
|
1049
|
+
};
|
|
1050
|
+
}, {});
|
|
1051
|
+
const keyParts = unitGroupKey.split("|");
|
|
1052
|
+
return keyParts.map(keyPart => {
|
|
1053
|
+
const [unitType, ...rest] = keyPart.split("_");
|
|
1054
|
+
if (unitType === "user-button") {
|
|
1055
|
+
return keyPart;
|
|
1056
|
+
}
|
|
1057
|
+
const fieldId = rest.join("_");
|
|
1058
|
+
if (!fieldId) {
|
|
1059
|
+
return keyPart;
|
|
1060
|
+
}
|
|
1061
|
+
const fieldObject = fieldObjectsById[fieldId];
|
|
1062
|
+
if (!fieldObject) {
|
|
1063
|
+
return null;
|
|
1064
|
+
}
|
|
1065
|
+
return `${unitType}_${fieldObject.holderType}:${fieldObject.name}`;
|
|
1066
|
+
}).filter(Boolean).join("|");
|
|
1067
|
+
}
|
|
986
1068
|
});
|
|
987
1069
|
const deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = (schema, smartFolder) => visitSmartFolder(smartFolder, {
|
|
988
1070
|
visitQueryExpression: query => deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression(schema, query),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/views",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.5.0",
|
|
4
4
|
"description": "Operations on view objects",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Fibery",
|
|
@@ -18,13 +18,13 @@
|
|
|
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",
|
|
21
22
|
"@fibery/eslint-config": "8.6.0",
|
|
22
|
-
"@fibery/
|
|
23
|
-
"@fibery/
|
|
24
|
-
"@fibery/babel-preset": "7.4.0"
|
|
23
|
+
"@fibery/expression-utils": "9.0.5",
|
|
24
|
+
"@fibery/schema": "10.2.1"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@fibery/expression-utils": "^9.0.
|
|
27
|
+
"@fibery/expression-utils": "^9.0.5",
|
|
28
28
|
"@fibery/schema": "^10.2.1",
|
|
29
29
|
"immutability-helper": "^2.4.0",
|
|
30
30
|
"lodash": "^4.17.21"
|