@jahia/data-helper 1.0.5 → 1.0.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.
- package/esm/fragments/PredefinedFragments.js +21 -221
- package/esm/fragments/fragments.utils.js +17 -43
- package/esm/fragments/getIsNodeTypeFragment.js +2 -15
- package/esm/fragments/getPermissionFragment.js +3 -28
- package/esm/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -12
- package/esm/hooks/useContentPreview/useContentPreview.js +7 -7
- package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -2
- package/esm/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -1
- package/esm/hooks/useNodeChecks/useNodeChecks.js +13 -28
- package/esm/hooks/useNodeChecks/useNodeChecks.spec.js +156 -67
- package/esm/hooks/useNodeInfo/useMemoRequest.js +49 -0
- package/esm/hooks/useNodeInfo/useNodeInfo.gql-queries.js +23 -104
- package/esm/hooks/useNodeInfo/useNodeInfo.js +139 -57
- package/esm/hooks/useNodeInfo/useNodeInfo.spec.js +429 -233
- package/esm/hooks/useNodeInfo/useNodeInfo.utils.js +52 -0
- package/esm/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -12
- package/esm/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -12
- package/esm/hooks/useSiteInfo/useSiteInfo.js +2 -9
- package/esm/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -12
- package/esm/hooks/useTreeEntries/useTreeEntries.js +18 -40
- package/esm/legacy/Picker.gql-fragments.js +4 -34
- package/esm/legacy/Picker.js +31 -113
- package/js/fragments/PredefinedFragments.js +21 -224
- package/js/fragments/encodeName.js +0 -2
- package/js/fragments/fragments.utils.js +17 -44
- package/js/fragments/getIsNodeTypeFragment.js +2 -23
- package/js/fragments/getPermissionFragment.js +3 -38
- package/js/fragments/index.js +0 -4
- package/js/hooks/index.js +0 -10
- package/js/hooks/useContentPreview/index.js +0 -2
- package/js/hooks/useContentPreview/useContentPreview.gql-queries.js +2 -16
- package/js/hooks/useContentPreview/useContentPreview.js +7 -11
- package/js/hooks/useContentPreview/useContentPreview.spec.js +0 -2
- package/js/hooks/useDeepCompareMemo/index.js +0 -2
- package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.js +0 -7
- package/js/hooks/useDeepCompareMemo/useDeepCompareMemo.spec.js +0 -2
- package/js/hooks/useNodeChecks/index.js +0 -2
- package/js/hooks/useNodeChecks/useNodeChecks.js +13 -30
- package/js/hooks/useNodeChecks/useNodeChecks.spec.js +157 -69
- package/js/hooks/useNodeInfo/index.js +0 -2
- package/js/hooks/useNodeInfo/useMemoRequest.js +56 -0
- package/js/hooks/useNodeInfo/useNodeInfo.gql-queries.js +25 -111
- package/js/hooks/useNodeInfo/useNodeInfo.js +139 -65
- package/js/hooks/useNodeInfo/useNodeInfo.spec.js +430 -236
- package/js/hooks/useNodeInfo/useNodeInfo.utils.js +60 -0
- package/js/hooks/useSchemaFields/index.js +0 -2
- package/js/hooks/useSchemaFields/useSchemaFields.gql-queries.js +2 -15
- package/js/hooks/useSchemaFields/useSchemaFields.jsx +0 -4
- package/js/hooks/useSiteInfo/index.js +0 -2
- package/js/hooks/useSiteInfo/useSiteInfo.gql-queries.js +2 -16
- package/js/hooks/useSiteInfo/useSiteInfo.js +2 -12
- package/js/hooks/useSiteInfo/useSiteInfo.spec.js +0 -4
- package/js/hooks/useTreeEntries/index.js +0 -2
- package/js/hooks/useTreeEntries/useTreeEntries.gql-queries.js +2 -16
- package/js/hooks/useTreeEntries/useTreeEntries.js +18 -46
- package/js/hooks/useTreeEntries/useTreeEntries.spec.js +0 -3
- package/js/index.js +0 -6
- package/js/legacy/Picker.gql-fragments.js +4 -37
- package/js/legacy/Picker.js +31 -134
- package/js/legacy/index.js +0 -4
- package/package.json +1 -1
package/esm/legacy/Picker.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
|
|
3
2
|
import _includes from "lodash/includes";
|
|
4
3
|
import _startsWith from "lodash/startsWith";
|
|
5
4
|
import _split from "lodash/split";
|
|
@@ -16,53 +15,27 @@ import _union from "lodash/union";
|
|
|
16
15
|
import _eq from "lodash/eq";
|
|
17
16
|
import _clone from "lodash/clone";
|
|
18
17
|
import _filter from "lodash/filter";
|
|
19
|
-
|
|
18
|
+
var _templateObject;
|
|
20
19
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
-
|
|
22
20
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
-
|
|
24
21
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
|
|
26
22
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
27
|
-
|
|
28
23
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
29
|
-
|
|
30
24
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
31
|
-
|
|
32
25
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
33
|
-
|
|
34
26
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
35
|
-
|
|
36
27
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
37
|
-
|
|
38
|
-
function _templateObject() {
|
|
39
|
-
var data = _taggedTemplateLiteral(["\n query PickerQuery($rootPaths:[String!]!, $selectable:[String]!, $openable:[String]!, $openPaths:[String!]!, $types:[String]!) {\n jcr {\n rootNodes:nodesByPath(paths: $rootPaths) {\n name\n children(typesFilter:{types:$types}, limit:1) {\n pageInfo {\n nodesCount\n }\n }\n selectable : isNodeType(type: {types:$selectable})\n openable : isNodeType(type: {types:$openable})\n ... NodeCacheRequiredFields\n ... node\n },\n openNodes:nodesByPath(paths: $openPaths) {\n ... NodeCacheRequiredFields\n children(typesFilter:{types:$types}) {\n nodes {\n name\n children(typesFilter:{types:$types}, limit:1) {\n pageInfo {\n nodesCount\n }\n }\n selectable : isNodeType(type: {types:$selectable})\n openable : isNodeType(type: {types:$openable})\n ... NodeCacheRequiredFields\n ... node\n }\n }\n }\n }\n }\n ", ""]);
|
|
40
|
-
|
|
41
|
-
_templateObject = function _templateObject() {
|
|
42
|
-
return data;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
28
|
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
49
|
-
|
|
50
29
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
51
|
-
|
|
52
30
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
53
|
-
|
|
54
31
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
55
|
-
|
|
56
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
57
|
-
|
|
58
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
59
|
-
|
|
60
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
61
|
-
|
|
62
32
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
63
|
-
|
|
64
33
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
65
|
-
|
|
34
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
35
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
36
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
37
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
38
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
66
39
|
// TODO BACKLOG-12393 - refactor Legacy Picker into hook without lodash
|
|
67
40
|
import React from 'react';
|
|
68
41
|
import { Query } from 'react-apollo';
|
|
@@ -72,32 +45,28 @@ import { displayName, nodeCacheRequiredFields, replaceFragmentsInDocument } from
|
|
|
72
45
|
import { PickerItemsFragment } from './Picker.gql-fragments';
|
|
73
46
|
export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
74
47
|
_inherits(Picker, _React$Component);
|
|
75
|
-
|
|
48
|
+
var _super = _createSuper(Picker);
|
|
76
49
|
function Picker(props) {
|
|
77
50
|
var _this;
|
|
78
|
-
|
|
79
51
|
_classCallCheck(this, Picker);
|
|
80
|
-
|
|
81
|
-
_this = _possibleConstructorReturn(this, _getPrototypeOf(Picker).call(this, props));
|
|
52
|
+
_this = _super.call(this, props);
|
|
82
53
|
var fragments = props.fragments,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
_this.query = gql(_templateObject(), nodeCacheRequiredFields.gql);
|
|
54
|
+
rootPaths = props.rootPaths,
|
|
55
|
+
onOpenItem = props.onOpenItem,
|
|
56
|
+
onSelectItem = props.onSelectItem,
|
|
57
|
+
openPaths = props.openPaths,
|
|
58
|
+
selectedPaths = props.selectedPaths,
|
|
59
|
+
defaultSelectedPaths = props.defaultSelectedPaths,
|
|
60
|
+
onSelectionChange = props.onSelectionChange,
|
|
61
|
+
defaultOpenPaths = props.defaultOpenPaths;
|
|
62
|
+
_this.query = gql(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n query PickerQuery($rootPaths:[String!]!, $selectable:[String]!, $openable:[String]!, $openPaths:[String!]!, $types:[String]!) {\n jcr {\n rootNodes:nodesByPath(paths: $rootPaths) {\n name\n children(typesFilter:{types:$types}, limit:1) {\n pageInfo {\n nodesCount\n }\n }\n selectable : isNodeType(type: {types:$selectable})\n openable : isNodeType(type: {types:$openable})\n ... NodeCacheRequiredFields\n ... node\n },\n openNodes:nodesByPath(paths: $openPaths) {\n ... NodeCacheRequiredFields\n children(typesFilter:{types:$types}) {\n nodes {\n name\n children(typesFilter:{types:$types}, limit:1) {\n pageInfo {\n nodesCount\n }\n }\n selectable : isNodeType(type: {types:$selectable})\n openable : isNodeType(type: {types:$openable})\n ... NodeCacheRequiredFields\n ... node\n }\n }\n }\n }\n }\n ", ""])), nodeCacheRequiredFields.gql);
|
|
92
63
|
_this.query = replaceFragmentsInDocument(_this.query, fragments);
|
|
93
64
|
var state = {};
|
|
94
65
|
_this.eventsHandlers = {};
|
|
95
|
-
|
|
96
66
|
if (openPaths === null) {
|
|
97
67
|
// Uncontrolled mode
|
|
98
68
|
state.isOpenControlled = false;
|
|
99
69
|
state.openPaths = [];
|
|
100
|
-
|
|
101
70
|
_this.eventsHandlers.onOpenItem = function (path, open) {
|
|
102
71
|
_this.setState(function (prevState) {
|
|
103
72
|
return {
|
|
@@ -107,27 +76,23 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
107
76
|
};
|
|
108
77
|
});
|
|
109
78
|
};
|
|
110
|
-
|
|
111
79
|
if (defaultOpenPaths) {
|
|
112
80
|
state.openPaths = _this.addPathToOpenPath(defaultOpenPaths, rootPaths, state.openPaths);
|
|
113
81
|
}
|
|
114
82
|
} else {
|
|
115
83
|
state.isOpenControlled = true;
|
|
116
|
-
|
|
117
84
|
if (onOpenItem) {
|
|
118
85
|
_this.eventsHandlers.onOpenItem = onOpenItem;
|
|
119
86
|
}
|
|
120
87
|
}
|
|
121
|
-
|
|
122
88
|
if (selectedPaths === null) {
|
|
123
89
|
// Uncontrolled mode
|
|
124
90
|
state.isSelectControlled = false;
|
|
125
|
-
state.selectedPaths = defaultSelectedPaths ? _clone(defaultSelectedPaths) : [];
|
|
126
|
-
|
|
91
|
+
state.selectedPaths = defaultSelectedPaths ? _clone(defaultSelectedPaths) : [];
|
|
92
|
+
// Open selected path if open is uncontrolled
|
|
127
93
|
if (defaultSelectedPaths && !state.isOpenControlled) {
|
|
128
94
|
state.openPaths = _this.addPathToOpenPath(defaultSelectedPaths, rootPaths, state.openPaths);
|
|
129
95
|
}
|
|
130
|
-
|
|
131
96
|
_this.eventsHandlers.onSelectItem = function (path, selected, multiple) {
|
|
132
97
|
_this.setState(function (prevState) {
|
|
133
98
|
var newSelectedPaths = selected ? [].concat(_toConsumableArray(multiple ? prevState.selectedPaths : []), [path]) : _filter(prevState.selectedPaths, function (thispath) {
|
|
@@ -141,26 +106,24 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
141
106
|
};
|
|
142
107
|
} else if (onSelectItem) {
|
|
143
108
|
state.isSelectControlled = true;
|
|
144
|
-
|
|
145
109
|
if (onSelectItem) {
|
|
146
110
|
_this.eventsHandlers.onSelectItem = onSelectItem;
|
|
147
111
|
}
|
|
148
112
|
}
|
|
113
|
+
_this.state = state;
|
|
149
114
|
|
|
150
|
-
|
|
151
|
-
|
|
115
|
+
// Binding
|
|
152
116
|
_this.openPaths = _this.openPaths.bind(_assertThisInitialized(_this));
|
|
153
117
|
return _this;
|
|
154
118
|
}
|
|
155
|
-
|
|
156
119
|
_createClass(Picker, [{
|
|
157
120
|
key: "getVariables",
|
|
158
121
|
value: function getVariables(selectedPaths, openPaths) {
|
|
159
122
|
var _this$props = this.props,
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
123
|
+
rootPaths = _this$props.rootPaths,
|
|
124
|
+
openableTypes = _this$props.openableTypes,
|
|
125
|
+
selectableTypes = _this$props.selectableTypes,
|
|
126
|
+
queryVariables = _this$props.queryVariables;
|
|
164
127
|
var vars = {
|
|
165
128
|
rootPaths: rootPaths,
|
|
166
129
|
types: _union(openableTypes, selectableTypes),
|
|
@@ -168,29 +131,23 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
168
131
|
openable: openableTypes,
|
|
169
132
|
openPaths: openPaths
|
|
170
133
|
};
|
|
171
|
-
|
|
172
134
|
if (queryVariables) {
|
|
173
135
|
_assign(vars, queryVariables);
|
|
174
136
|
}
|
|
175
|
-
|
|
176
137
|
return vars;
|
|
177
138
|
}
|
|
178
139
|
}, {
|
|
179
140
|
key: "getPickerEntries",
|
|
180
141
|
value: function getPickerEntries(data, selectedPaths, openPaths) {
|
|
181
142
|
var _this2 = this;
|
|
182
|
-
|
|
183
143
|
var pickerEntries = [];
|
|
184
144
|
var nodesById = {};
|
|
185
145
|
var jcr = data.jcr;
|
|
186
|
-
|
|
187
146
|
var addNode = function addNode(node, depth, index) {
|
|
188
147
|
var selected = false;
|
|
189
|
-
|
|
190
148
|
if (node.selectable) {
|
|
191
149
|
selected = _indexOf(selectedPaths, node.path) !== -1;
|
|
192
150
|
}
|
|
193
|
-
|
|
194
151
|
var pickerNode = {
|
|
195
152
|
name: node.name,
|
|
196
153
|
path: node.path,
|
|
@@ -208,7 +165,6 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
208
165
|
nodesById[node.uuid] = pickerNode;
|
|
209
166
|
return pickerNode;
|
|
210
167
|
};
|
|
211
|
-
|
|
212
168
|
if (jcr) {
|
|
213
169
|
if (jcr.rootNodes) {
|
|
214
170
|
_forEach(jcr.rootNodes, function (rootNode) {
|
|
@@ -216,29 +172,25 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
216
172
|
root.hidden = _this2.props.hideRoot;
|
|
217
173
|
});
|
|
218
174
|
}
|
|
219
|
-
|
|
220
175
|
if (jcr.openNodes) {
|
|
221
176
|
_sortBy(jcr.openNodes, ['path']).forEach(function (node) {
|
|
222
177
|
var parent = nodesById[node.uuid];
|
|
223
|
-
|
|
224
178
|
if (parent) {
|
|
225
179
|
var parentIndex = _indexOf(pickerEntries, parent);
|
|
226
|
-
|
|
227
180
|
_forEachRight(node.children.nodes, function (child) {
|
|
228
181
|
addNode(child, parent.depth + 1, parentIndex + 1);
|
|
229
182
|
});
|
|
230
183
|
}
|
|
231
184
|
});
|
|
232
185
|
}
|
|
233
|
-
}
|
|
234
|
-
|
|
186
|
+
}
|
|
235
187
|
|
|
188
|
+
// Nodes loaded, fill selection list
|
|
236
189
|
var selectedNodes = _filter(pickerEntries, function (node) {
|
|
237
190
|
return node.selected;
|
|
238
191
|
}).map(function (node) {
|
|
239
192
|
return node.node;
|
|
240
193
|
});
|
|
241
|
-
|
|
242
194
|
selectedPaths = _map(selectedNodes, 'path');
|
|
243
195
|
pickerEntries = _filter(pickerEntries, function (pickerNode) {
|
|
244
196
|
return !pickerNode.hidden;
|
|
@@ -250,44 +202,35 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
250
202
|
value: function addPathToOpenPath(pathsToOpen, rootPaths, openPaths) {
|
|
251
203
|
_each(pathsToOpen, function (path) {
|
|
252
204
|
var rootFound = false;
|
|
253
|
-
|
|
254
205
|
if (!path.endsWith('/')) {
|
|
255
206
|
path += '/';
|
|
256
207
|
}
|
|
257
|
-
|
|
258
208
|
_tail(_split(path, '/')).reduce(function (acc, it) {
|
|
259
209
|
if (!rootFound) {
|
|
260
210
|
_forEach(rootPaths, function (rootPath) {
|
|
261
211
|
rootFound = rootFound || _startsWith(acc, rootPath) && rootPath;
|
|
262
212
|
});
|
|
263
213
|
}
|
|
264
|
-
|
|
265
214
|
if (rootFound && !_includes(openPaths, acc)) {
|
|
266
215
|
openPaths.push(acc);
|
|
267
|
-
|
|
268
216
|
if (!_includes(openPaths, rootFound)) {
|
|
269
217
|
openPaths.push(rootFound);
|
|
270
218
|
}
|
|
271
219
|
}
|
|
272
|
-
|
|
273
220
|
return acc + '/' + it;
|
|
274
221
|
}, '');
|
|
275
222
|
});
|
|
276
|
-
|
|
277
223
|
return openPaths;
|
|
278
224
|
}
|
|
279
225
|
}, {
|
|
280
226
|
key: "openPaths",
|
|
281
227
|
value: function openPaths(paths) {
|
|
282
228
|
var _this3 = this;
|
|
283
|
-
|
|
284
229
|
if (!(paths instanceof Array)) {
|
|
285
230
|
paths = [paths];
|
|
286
231
|
}
|
|
287
|
-
|
|
288
232
|
this.setState(function (prevState) {
|
|
289
233
|
var openPaths = _this3.addPathToOpenPath(paths, _this3.props.rootPaths, prevState.openPaths);
|
|
290
|
-
|
|
291
234
|
return {
|
|
292
235
|
openPaths: openPaths
|
|
293
236
|
};
|
|
@@ -297,22 +240,20 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
297
240
|
key: "render",
|
|
298
241
|
value: function render() {
|
|
299
242
|
var _this4 = this;
|
|
300
|
-
|
|
301
243
|
var selectedPaths = this.state.selectedPaths ? this.state.selectedPaths : this.props.selectedPaths;
|
|
302
244
|
var openPaths = this.state.openPaths ? this.state.openPaths : this.props.openPaths;
|
|
303
245
|
var setRefetch = this.props.setRefetch;
|
|
304
246
|
openPaths = _clone(openPaths);
|
|
305
247
|
var vars = this.getVariables(selectedPaths, openPaths);
|
|
306
|
-
return React.createElement(Query, {
|
|
248
|
+
return /*#__PURE__*/React.createElement(Query, {
|
|
307
249
|
query: this.query,
|
|
308
250
|
variables: vars,
|
|
309
251
|
fetchPolicy: "cache-first"
|
|
310
252
|
}, function (_ref) {
|
|
311
253
|
var error = _ref.error,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
254
|
+
loading = _ref.loading,
|
|
255
|
+
data = _ref.data,
|
|
256
|
+
refetch = _ref.refetch;
|
|
316
257
|
if (setRefetch) {
|
|
317
258
|
setRefetch({
|
|
318
259
|
query: _this4.query,
|
|
@@ -320,13 +261,10 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
320
261
|
refetch: refetch
|
|
321
262
|
});
|
|
322
263
|
}
|
|
323
|
-
|
|
324
264
|
var renderProp = _this4.props.children;
|
|
325
|
-
|
|
326
265
|
if (_this4.props.onLoading) {
|
|
327
266
|
_this4.props.onLoading(loading);
|
|
328
267
|
}
|
|
329
|
-
|
|
330
268
|
if (loading) {
|
|
331
269
|
if (_this4.previousEntries) {
|
|
332
270
|
return renderProp(_objectSpread({
|
|
@@ -334,13 +272,11 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
334
272
|
loading: loading
|
|
335
273
|
}, _this4.eventsHandlers));
|
|
336
274
|
}
|
|
337
|
-
|
|
338
275
|
return renderProp(_objectSpread({
|
|
339
276
|
pickerEntries: [],
|
|
340
277
|
loading: loading
|
|
341
278
|
}, _this4.eventsHandlers));
|
|
342
279
|
}
|
|
343
|
-
|
|
344
280
|
if (error) {
|
|
345
281
|
return renderProp(_objectSpread({
|
|
346
282
|
pickerEntries: [],
|
|
@@ -348,9 +284,7 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
348
284
|
loading: loading
|
|
349
285
|
}, _this4.eventsHandlers));
|
|
350
286
|
}
|
|
351
|
-
|
|
352
287
|
var pickerEntries = _this4.getPickerEntries(data, selectedPaths, openPaths);
|
|
353
|
-
|
|
354
288
|
_this4.previousEntries = pickerEntries;
|
|
355
289
|
return renderProp(_objectSpread({
|
|
356
290
|
pickerEntries: pickerEntries,
|
|
@@ -364,25 +298,19 @@ export var Picker = /*#__PURE__*/function (_React$Component) {
|
|
|
364
298
|
if (prevState.isOpenControlled !== (nextProps.openPaths !== null) || prevState.isSelectControlled !== (nextProps.selectedPaths !== null)) {
|
|
365
299
|
console.warn('Cannot change between controlled/uncontrolled modes');
|
|
366
300
|
}
|
|
367
|
-
|
|
368
301
|
var newState = {};
|
|
369
|
-
|
|
370
302
|
if (prevState.isOpenControlled && !_eq(nextProps.openPaths, prevState.openPaths)) {
|
|
371
303
|
newState.openPaths = nextProps.openPaths;
|
|
372
304
|
}
|
|
373
|
-
|
|
374
305
|
if (prevState.isSelectControlled && !_eq(nextProps.selectedPaths, prevState.selectedPaths)) {
|
|
375
306
|
newState.selectedPaths = nextProps.selectedPaths;
|
|
376
307
|
}
|
|
377
|
-
|
|
378
308
|
if (newState.openPaths || newState.selectedPaths) {
|
|
379
309
|
return newState;
|
|
380
310
|
}
|
|
381
|
-
|
|
382
311
|
return null;
|
|
383
312
|
}
|
|
384
313
|
}]);
|
|
385
|
-
|
|
386
314
|
return Picker;
|
|
387
315
|
}(React.Component);
|
|
388
316
|
Picker.defaultProps = {
|
|
@@ -405,47 +333,38 @@ Picker.propTypes = {
|
|
|
405
333
|
* List of root paths for the picker
|
|
406
334
|
*/
|
|
407
335
|
rootPaths: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
408
|
-
|
|
409
336
|
/**
|
|
410
337
|
* List of folder paths that are open by default (uncontrolled mode)
|
|
411
338
|
*/
|
|
412
339
|
defaultOpenPaths: PropTypes.arrayOf(PropTypes.string),
|
|
413
|
-
|
|
414
340
|
/**
|
|
415
341
|
* List of node types that can be "opened" (folders)
|
|
416
342
|
*/
|
|
417
343
|
openableTypes: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
418
|
-
|
|
419
344
|
/**
|
|
420
345
|
* List of open folders in controlled mode
|
|
421
346
|
*/
|
|
422
347
|
openPaths: PropTypes.arrayOf(PropTypes.string),
|
|
423
|
-
|
|
424
348
|
/**
|
|
425
349
|
* List of node types that can be "selected" (items)
|
|
426
350
|
*/
|
|
427
351
|
selectableTypes: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
428
|
-
|
|
429
352
|
/**
|
|
430
353
|
* Preselected items path (uncontrolled mode)
|
|
431
354
|
*/
|
|
432
355
|
defaultSelectedPaths: PropTypes.arrayOf(PropTypes.string),
|
|
433
|
-
|
|
434
356
|
/**
|
|
435
357
|
* List of selected path in controlled mode
|
|
436
358
|
*/
|
|
437
359
|
selectedPaths: PropTypes.arrayOf(PropTypes.string),
|
|
438
|
-
|
|
439
360
|
/**
|
|
440
361
|
* Callback when the selection has changed
|
|
441
362
|
*/
|
|
442
363
|
onSelectionChange: PropTypes.func,
|
|
443
|
-
|
|
444
364
|
/**
|
|
445
365
|
* Optional function which receives refetch function of the Query component when the component is strapped
|
|
446
366
|
*/
|
|
447
367
|
setRefetch: PropTypes.func,
|
|
448
|
-
|
|
449
368
|
/**
|
|
450
369
|
* Optional set of fragments to add to the graphQL query. Can be a string that identify a predefinedFragment or a fragment definition
|
|
451
370
|
*/
|
|
@@ -454,7 +373,6 @@ Picker.propTypes = {
|
|
|
454
373
|
variables: PropTypes.object,
|
|
455
374
|
gql: PropTypes.object.isRequired
|
|
456
375
|
})])),
|
|
457
|
-
|
|
458
376
|
/**
|
|
459
377
|
* Optional set of variable to pass to the graphQL query, in order to fulfill fragments needs
|
|
460
378
|
*/
|