@fibery/views 1.1.4 → 1.1.5
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/README.md +31 -0
- package/lib/views.js +70 -11
- package/package.json +20 -7
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
## How to update and publish @fibery/views
|
|
2
|
+
|
|
3
|
+
Execute this:
|
|
4
|
+
|
|
5
|
+
cd fibery-views
|
|
6
|
+
yarn build
|
|
7
|
+
npm version patch
|
|
8
|
+
npm publish --dry-run
|
|
9
|
+
|
|
10
|
+
Check the output, it should say there are at least 2 total files:
|
|
11
|
+
|
|
12
|
+
npm notice 📦 @fibery/views@1.1.4
|
|
13
|
+
npm notice === Tarball Contents ===
|
|
14
|
+
npm notice 37.1kB lib/views.js
|
|
15
|
+
npm notice 1.1kB package.json
|
|
16
|
+
npm notice === Tarball Details ===
|
|
17
|
+
npm notice name: @fibery/views
|
|
18
|
+
npm notice version: 1.1.4
|
|
19
|
+
npm notice package size: 4.7 kB
|
|
20
|
+
npm notice unpacked size: 38.3 kB
|
|
21
|
+
npm notice shasum: 0c8f17195d49cda1a321edc9a07d443c97ed6ba5
|
|
22
|
+
npm notice integrity: sha512-XpaByuvN4YSZi[...]OFceXnL4J2VHw==
|
|
23
|
+
npm notice total files: 2
|
|
24
|
+
npm notice
|
|
25
|
+
+ @fibery/views@1.1.4
|
|
26
|
+
|
|
27
|
+
If everything looks good, do
|
|
28
|
+
|
|
29
|
+
npm publish
|
|
30
|
+
|
|
31
|
+
Don't forget to commit the updated package.json.
|
package/lib/views.js
CHANGED
|
@@ -26,6 +26,38 @@ function _extends() {
|
|
|
26
26
|
return _extends.apply(this, arguments);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
const getFieldType = (schema, fromType, field) => {
|
|
30
|
+
if (!schema.typeObjectsByName.hasOwnProperty(fromType) || !schema.typeObjectsByName[fromType].fieldObjectsByName.hasOwnProperty(field)) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return schema.typeObjectsByName[fromType].fieldObjectsByName[field].type;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getFieldMeta = (schema, fromType, field) => {
|
|
38
|
+
if (!schema.typeObjectsByName.hasOwnProperty(fromType) || !schema.typeObjectsByName[fromType].fieldObjectsByName.hasOwnProperty(field)) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return schema.typeObjectsByName[fromType].fieldObjectsByName[field].rawMeta;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const getUnitTypeForTextField = fieldMeta => {
|
|
46
|
+
switch (fieldMeta["ui/type"]) {
|
|
47
|
+
case "email":
|
|
48
|
+
return "email";
|
|
49
|
+
|
|
50
|
+
case "url":
|
|
51
|
+
return "url";
|
|
52
|
+
|
|
53
|
+
case "phone":
|
|
54
|
+
return "phone";
|
|
55
|
+
|
|
56
|
+
default:
|
|
57
|
+
return "text";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
29
61
|
const fixViewUnit = (schema, fromType, unit) => {
|
|
30
62
|
const {
|
|
31
63
|
type,
|
|
@@ -35,7 +67,7 @@ const fixViewUnit = (schema, fromType, unit) => {
|
|
|
35
67
|
if (type === "date") {
|
|
36
68
|
const [field] = expression;
|
|
37
69
|
|
|
38
|
-
if (schema
|
|
70
|
+
if (getFieldType(schema, fromType, field) === "fibery/date-time") {
|
|
39
71
|
return _extends({}, unit, {
|
|
40
72
|
type: "date-time"
|
|
41
73
|
});
|
|
@@ -45,13 +77,34 @@ const fixViewUnit = (schema, fromType, unit) => {
|
|
|
45
77
|
if (type === "date-range") {
|
|
46
78
|
const [field] = expression;
|
|
47
79
|
|
|
48
|
-
if (schema
|
|
80
|
+
if (getFieldType(schema, fromType, field) === "fibery/date-time-range") {
|
|
49
81
|
return _extends({}, unit, {
|
|
50
82
|
type: "date-time-range"
|
|
51
83
|
});
|
|
52
84
|
}
|
|
53
85
|
}
|
|
54
86
|
|
|
87
|
+
if (type === "text") {
|
|
88
|
+
const [field] = expression;
|
|
89
|
+
const fieldType = getFieldType(schema, fromType, field);
|
|
90
|
+
|
|
91
|
+
if (fieldType === "fibery/email") {
|
|
92
|
+
return _extends({}, unit, {
|
|
93
|
+
type: "email"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (["text", "email", "phone", "url"].includes(type)) {
|
|
99
|
+
const [field] = expression;
|
|
100
|
+
|
|
101
|
+
if (getFieldType(schema, fromType, field) === "fibery/text") {
|
|
102
|
+
return _extends({}, unit, {
|
|
103
|
+
type: getUnitTypeForTextField(getFieldMeta(schema, fromType, field))
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
55
108
|
return unit;
|
|
56
109
|
};
|
|
57
110
|
|
|
@@ -547,7 +600,7 @@ const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["def
|
|
|
547
600
|
items: {
|
|
548
601
|
$apply: items => {
|
|
549
602
|
const isOldSmartFolder = !items.every(item => item.hasOwnProperty("groupBy"));
|
|
550
|
-
|
|
603
|
+
const removedItemsIndexes = items.map((item, index) => visitor.visitQueryExpression(item.query) ? null : index).filter(value => value !== null);
|
|
551
604
|
return items.map((item, index) => {
|
|
552
605
|
if (isOldSmartFolder) {
|
|
553
606
|
return item;
|
|
@@ -558,28 +611,23 @@ const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["def
|
|
|
558
611
|
return fromType ? immutableUpdate__default["default"](item, {
|
|
559
612
|
groupBy: {
|
|
560
613
|
$apply: groupBy => {
|
|
561
|
-
const removedItemsBeforeCurrent =
|
|
614
|
+
const removedItemsBeforeCurrent = removedItemsIndexes.filter(n => n < index);
|
|
562
615
|
return groupBy ? visitor.visitGroupByExpression(groupBy, fromType, removedItemsBeforeCurrent.length) : null;
|
|
563
616
|
}
|
|
564
617
|
}
|
|
565
618
|
}) : item;
|
|
566
|
-
}).map(
|
|
619
|
+
}).map(item => {
|
|
567
620
|
const fromType = ___default["default"].get(item, ["query", "q/from"]);
|
|
568
621
|
|
|
569
622
|
return fromType ? immutableUpdate__default["default"](item, {
|
|
570
623
|
query: {
|
|
571
624
|
$apply: query => {
|
|
572
625
|
const visitedQuery = visitor.visitQueryExpression(query);
|
|
573
|
-
|
|
574
|
-
if (!visitedQuery) {
|
|
575
|
-
removedItems.push(index);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
626
|
return query ? visitedQuery : null;
|
|
579
627
|
}
|
|
580
628
|
},
|
|
581
629
|
units: {
|
|
582
|
-
$apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)) : undefined
|
|
630
|
+
$apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)).map(unit => visitor.visitViewUnit ? visitor.visitViewUnit(fromType, unit) : unit) : undefined
|
|
583
631
|
},
|
|
584
632
|
contextExpression: {
|
|
585
633
|
$apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
|
|
@@ -679,6 +727,14 @@ const deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = (schema, smartFol
|
|
|
679
727
|
visitGroupByExpression: (groupBy, fromType, removedItems) => deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression(schema, groupBy, fromType, removedItems),
|
|
680
728
|
visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
|
|
681
729
|
});
|
|
730
|
+
const fixUserSelectedUnitsInSmartFolder = (schema, view) => {
|
|
731
|
+
return visitSmartFolder(view, {
|
|
732
|
+
visitQueryExpression: query => query,
|
|
733
|
+
visitGroupByExpression: groupBy => groupBy,
|
|
734
|
+
visitExpression: (fromType, expression) => expression,
|
|
735
|
+
visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
|
|
736
|
+
});
|
|
737
|
+
};
|
|
682
738
|
|
|
683
739
|
const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view, {
|
|
684
740
|
"fibery/meta": {
|
|
@@ -923,6 +979,9 @@ const fixUserSelectedUnits = (schema, view) => {
|
|
|
923
979
|
case "board":
|
|
924
980
|
return fixUserSelectedUnitsInBoardView(schema, view);
|
|
925
981
|
|
|
982
|
+
case "list":
|
|
983
|
+
return fixUserSelectedUnitsInSmartFolder(schema, view);
|
|
984
|
+
|
|
926
985
|
case "table":
|
|
927
986
|
return fixUserSelectedUnitsInTableView(schema, view);
|
|
928
987
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fibery/views",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Operations on view objects",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"author": "Fibery",
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
"dependencies": {},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@babel/core": "7.15.0",
|
|
16
|
-
"babel-jest": "27.
|
|
17
|
-
"babel-loader": "8.2.
|
|
18
|
-
"babel-preset
|
|
19
|
-
"eslint-config
|
|
20
|
-
"jest": "27.
|
|
16
|
+
"babel-jest": "27.5.1",
|
|
17
|
+
"babel-loader": "8.2.5",
|
|
18
|
+
"@fibery/babel-preset": "7.2.0",
|
|
19
|
+
"@fibery/eslint-config": "7.1.0",
|
|
20
|
+
"jest": "27.5.1",
|
|
21
|
+
"jest-junit": "13.0.0",
|
|
21
22
|
"microbundle": "0.14.1"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
@@ -29,15 +30,27 @@
|
|
|
29
30
|
"scripts": {
|
|
30
31
|
"build": "rm -rf lib && microbundle index.js -o lib -f cjs --no-compress --target node --sourcemap false",
|
|
31
32
|
"test": "node scripts/test.js",
|
|
33
|
+
"test:ci": "yarn test --coverage --reporters=default --reporters=jest-junit",
|
|
32
34
|
"lint": "eslint ."
|
|
33
35
|
},
|
|
34
36
|
"jest": {
|
|
35
37
|
"testEnvironment": "node",
|
|
38
|
+
"coveragePathIgnorePatterns": [
|
|
39
|
+
"/node_modules/"
|
|
40
|
+
],
|
|
41
|
+
"collectCoverageFrom": [
|
|
42
|
+
"src/**/*.{js,jsx,ts,tsx}",
|
|
43
|
+
"!src/**/*.d.ts"
|
|
44
|
+
],
|
|
45
|
+
"coverageReporters": [
|
|
46
|
+
"text",
|
|
47
|
+
"cobertura"
|
|
48
|
+
],
|
|
36
49
|
"testPathIgnorePatterns": [
|
|
37
50
|
"<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
|
|
38
51
|
],
|
|
39
52
|
"transform": {
|
|
40
|
-
"^.+\\.jsx
|
|
53
|
+
"^.+\\.(js|jsx|ts|tsx)$": "../fibery-ui/config/jest/babel.js"
|
|
41
54
|
},
|
|
42
55
|
"testURL": "http://localhost"
|
|
43
56
|
}
|