@fibery/views 1.1.4 → 1.1.7

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/README.md +30 -0
  2. package/lib/views.js +153 -11
  3. package/package.json +22 -9
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ ## How to update and publish @fibery/views
2
+
3
+ Execute this:
4
+
5
+ yarn build
6
+ npm version patch
7
+ npm publish --dry-run
8
+
9
+ Check the output, it should say there are at least 2 total files:
10
+
11
+ npm notice 📦 @fibery/views@1.1.4
12
+ npm notice === Tarball Contents ===
13
+ npm notice 37.1kB lib/views.js
14
+ npm notice 1.1kB package.json
15
+ npm notice === Tarball Details ===
16
+ npm notice name: @fibery/views
17
+ npm notice version: 1.1.4
18
+ npm notice package size: 4.7 kB
19
+ npm notice unpacked size: 38.3 kB
20
+ npm notice shasum: 0c8f17195d49cda1a321edc9a07d443c97ed6ba5
21
+ npm notice integrity: sha512-XpaByuvN4YSZi[...]OFceXnL4J2VHw==
22
+ npm notice total files: 2
23
+ npm notice
24
+ + @fibery/views@1.1.4
25
+
26
+ If everything looks good, do
27
+
28
+ npm publish
29
+
30
+ 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.typeObjectsByName[fromType].fieldObjectsByName[field].type === "fibery/date-time") {
70
+ if (getFieldType(schema, fromType, field) === "fibery/date-time") {
39
71
  return _extends({}, unit, {
40
72
  type: "date-time"
41
73
  });
@@ -45,16 +77,40 @@ const fixViewUnit = (schema, fromType, unit) => {
45
77
  if (type === "date-range") {
46
78
  const [field] = expression;
47
79
 
48
- if (schema.typeObjectsByName[fromType].fieldObjectsByName[field].type === "fibery/date-time-range") {
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
 
111
+ // output. Not supported in all places, add support as needed.
112
+
113
+ const REMOVE = Symbol("remove");
58
114
  const deleteExpressionWithNotFoundFieldsOrTypesInQueryExpression = (schema, queryExpression) => {
59
115
  const {
60
116
  "q/from": fromExpression,
@@ -416,6 +472,14 @@ const deleteExpressionWithNotFoundOrInvalidFieldsOrTypesInBoardView = (schema, v
416
472
  const fixUserSelectedUnitsInBoardView = (schema, view) => {
417
473
  return visitView$4(view, fixUserSelectedUnitsViewVisitor(schema));
418
474
  };
475
+ const collectGarbage$5 = view => {
476
+ return visitView$4(view, {
477
+ visitQueryExpression: queryExpression => queryExpression,
478
+ visitExpression: (fromType, expression) => expression,
479
+ visitEnums: enums => enums,
480
+ visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
481
+ });
482
+ };
419
483
 
420
484
  const visitView$3 = (view, visitor) => immutableUpdate__default["default"](view, {
421
485
  "fibery/meta": {
@@ -480,6 +544,13 @@ const fixUserSelectedUnitsInCalendarView = (schema, view) => {
480
544
  visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
481
545
  });
482
546
  };
547
+ const collectGarbage$4 = view => {
548
+ return visitView$3(view, {
549
+ visitExpression: (fromType, expression) => expression,
550
+ visitQueryExpression: query => query,
551
+ visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
552
+ });
553
+ };
483
554
 
484
555
  const visitView$2 = (view, visitor) => immutableUpdate__default["default"](view, {
485
556
  "fibery/meta": {
@@ -541,13 +612,20 @@ const fixUserSelectedUnitsInFeedView = (schema, view) => {
541
612
  visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
542
613
  });
543
614
  };
615
+ const collectGarbage$3 = view => {
616
+ return visitView$2(view, {
617
+ visitExpression: (fromType, expression) => expression,
618
+ visitQueryExpression: query => query,
619
+ visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
620
+ });
621
+ };
544
622
 
545
623
  const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["default"](smartFolder, {
546
624
  "fibery/meta": {
547
625
  items: {
548
626
  $apply: items => {
549
627
  const isOldSmartFolder = !items.every(item => item.hasOwnProperty("groupBy"));
550
- let removedItems = [];
628
+ const removedItemsIndexes = items.map((item, index) => visitor.visitQueryExpression(item.query) ? null : index).filter(value => value !== null);
551
629
  return items.map((item, index) => {
552
630
  if (isOldSmartFolder) {
553
631
  return item;
@@ -558,28 +636,23 @@ const visitSmartFolder = (smartFolder, visitor) => immutableUpdate__default["def
558
636
  return fromType ? immutableUpdate__default["default"](item, {
559
637
  groupBy: {
560
638
  $apply: groupBy => {
561
- const removedItemsBeforeCurrent = removedItems.filter(n => n < index);
639
+ const removedItemsBeforeCurrent = removedItemsIndexes.filter(n => n < index);
562
640
  return groupBy ? visitor.visitGroupByExpression(groupBy, fromType, removedItemsBeforeCurrent.length) : null;
563
641
  }
564
642
  }
565
643
  }) : item;
566
- }).map((item, index) => {
644
+ }).map(item => {
567
645
  const fromType = ___default["default"].get(item, ["query", "q/from"]);
568
646
 
569
647
  return fromType ? immutableUpdate__default["default"](item, {
570
648
  query: {
571
649
  $apply: query => {
572
650
  const visitedQuery = visitor.visitQueryExpression(query);
573
-
574
- if (!visitedQuery) {
575
- removedItems.push(index);
576
- }
577
-
578
651
  return query ? visitedQuery : null;
579
652
  }
580
653
  },
581
654
  units: {
582
- $apply: units => units ? units.map(unit => visitViewUnit(fromType, unit, visitor)).filter(unit => isUnitExpressionValid(unit)) : undefined
655
+ $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
656
  },
584
657
  contextExpression: {
585
658
  $apply: contextExpression => contextExpression ? visitor.visitExpression(fromType, contextExpression) : contextExpression
@@ -679,6 +752,14 @@ const deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = (schema, smartFol
679
752
  visitGroupByExpression: (groupBy, fromType, removedItems) => deleteExpressionWithNotFoundFieldsOrTypesInGroupByExpression(schema, groupBy, fromType, removedItems),
680
753
  visitExpression: (fromType, expression) => deleteExpressionWithNotFoundFieldsOrTypesInExpression(schema, fromType, expression)
681
754
  });
755
+ const fixUserSelectedUnitsInSmartFolder = (schema, view) => {
756
+ return visitSmartFolder(view, {
757
+ visitQueryExpression: query => query,
758
+ visitGroupByExpression: groupBy => groupBy,
759
+ visitExpression: (fromType, expression) => expression,
760
+ visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
761
+ });
762
+ };
682
763
 
683
764
  const visitView$1 = (view, visitor) => immutableUpdate__default["default"](view, {
684
765
  "fibery/meta": {
@@ -731,6 +812,13 @@ const fixUserSelectedUnitsInTableView = (schema, view) => visitView$1(view, {
731
812
  visitQueryExpression: query => query,
732
813
  visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
733
814
  });
815
+ const collectGarbage$2 = view => {
816
+ return visitView$1(view, {
817
+ visitExpression: (fromType, expression) => expression,
818
+ visitQueryExpression: query => query,
819
+ visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
820
+ });
821
+ };
734
822
 
735
823
  const visitAxis = (axis, visitor) => {
736
824
  if (!axis) {
@@ -893,6 +981,13 @@ const fixUserSelectedUnitsInTimelineView = (schema, view) => {
893
981
  visitViewUnit: (fromType, unit) => fixViewUnit(schema, fromType, unit)
894
982
  });
895
983
  };
984
+ const collectGarbage$1 = view => {
985
+ return visitView(view, {
986
+ visitQueryExpression: query => query,
987
+ visitExpression: (fromType, expression) => expression,
988
+ visitViewUnit: (fromType, unit) => unit.checked ? unit : REMOVE
989
+ });
990
+ };
896
991
 
897
992
  const deleteExpressionWithNotFoundFieldsOrTypesInView = (schema, view, ensureAxisInvariant = true) => {
898
993
  switch (view["fibery/type"]) {
@@ -923,6 +1018,9 @@ const fixUserSelectedUnits = (schema, view) => {
923
1018
  case "board":
924
1019
  return fixUserSelectedUnitsInBoardView(schema, view);
925
1020
 
1021
+ case "list":
1022
+ return fixUserSelectedUnitsInSmartFolder(schema, view);
1023
+
926
1024
  case "table":
927
1025
  return fixUserSelectedUnitsInTableView(schema, view);
928
1026
 
@@ -939,6 +1037,49 @@ const fixUserSelectedUnits = (schema, view) => {
939
1037
  return view;
940
1038
  }
941
1039
  };
1040
+ /**
1041
+ * Removes garbage from view's meta to reduce the size.
1042
+ */
1043
+
1044
+ const collectGarbage = (schema, view) => {
1045
+ const deleteRemoved = x => {
1046
+ if (Array.isArray(x)) {
1047
+ return x.map(deleteRemoved).filter(y => y !== REMOVE);
1048
+ }
1049
+
1050
+ if (typeof x === "object" && x !== null) {
1051
+ let tmp = Object.entries(x);
1052
+ tmp = tmp.map(e => [e[0], deleteRemoved(e[1])]);
1053
+ tmp = tmp.filter(e => e[1] !== REMOVE);
1054
+ return Object.fromEntries(tmp);
1055
+ }
1056
+
1057
+ return x;
1058
+ };
1059
+
1060
+ switch (view["fibery/type"]) {
1061
+ case "board":
1062
+ return deleteRemoved(collectGarbage$5(view));
1063
+
1064
+ case "list":
1065
+ return deleteRemoved(undefined(view));
1066
+
1067
+ case "table":
1068
+ return deleteRemoved(collectGarbage$2(view));
1069
+
1070
+ case "timeline":
1071
+ return deleteRemoved(collectGarbage$1(view));
1072
+
1073
+ case "calendar":
1074
+ return deleteRemoved(collectGarbage$4(view));
1075
+
1076
+ case "feed":
1077
+ return deleteRemoved(collectGarbage$3(view));
1078
+
1079
+ default:
1080
+ return view;
1081
+ }
1082
+ };
942
1083
  const replaceNamesWithIdsInView = (schema, view) => {
943
1084
  switch (view["fibery/type"]) {
944
1085
  case "board":
@@ -997,6 +1138,7 @@ const getViewCardTypes = ({
997
1138
  }
998
1139
  }) => type);
999
1140
 
1141
+ exports.collectGarbage = collectGarbage;
1000
1142
  exports.deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder = deleteExpressionWithNotFoundFieldsOrTypesInSmartFolder;
1001
1143
  exports.deleteExpressionWithNotFoundFieldsOrTypesInView = deleteExpressionWithNotFoundFieldsOrTypesInView;
1002
1144
  exports.fixUserSelectedUnits = fixUserSelectedUnits;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fibery/views",
3
- "version": "1.1.4",
3
+ "version": "1.1.7",
4
4
  "description": "Operations on view objects",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Fibery",
@@ -13,31 +13,44 @@
13
13
  "dependencies": {},
14
14
  "devDependencies": {
15
15
  "@babel/core": "7.15.0",
16
- "babel-jest": "27.0.6",
17
- "babel-loader": "8.2.2",
18
- "babel-preset-fibery": "7.2.0",
19
- "eslint-config-fibery": "7.0.0",
20
- "jest": "27.0.6",
21
- "microbundle": "0.14.1"
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",
22
+ "microbundle": "0.15.0"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "@fibery/expression-utils": "^1.1.4",
25
- "fibery-schema": "^7.0.6",
26
+ "@fibery/schema": "^8.0.6",
26
27
  "immutability-helper": "^2.4.0",
27
28
  "lodash": "^4.17.21"
28
29
  },
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?$": "../fibery-ui/config/jest/babel.js"
53
+ "^.+\\.(js|jsx|ts|tsx)$": "../../fibery-ui/config/jest/babel.js"
41
54
  },
42
55
  "testURL": "http://localhost"
43
56
  }