@guillotinaweb/react-gmi 0.29.2-alpha.2 → 0.29.2-alpha.3

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 (69) hide show
  1. package/README.md +2 -1
  2. package/dist/actions/copy_item.d.ts +2 -2
  3. package/dist/actions/move_item.d.ts +2 -2
  4. package/dist/actions/remove_item.d.ts +2 -2
  5. package/dist/components/behaviors/iattachment.d.ts +4 -2
  6. package/dist/components/behaviors/imultiimageorderedattachment.d.ts +3 -1
  7. package/dist/components/behaviors/iworkflow.d.ts +1 -1
  8. package/dist/components/context_toolbar.d.ts +1 -1
  9. package/dist/components/fields/editComponent.d.ts +5 -4
  10. package/dist/components/fields/editableField.d.ts +4 -2
  11. package/dist/components/fields/renderField.d.ts +8 -5
  12. package/dist/components/flash.d.ts +1 -1
  13. package/dist/components/index.d.ts +2 -0
  14. package/dist/components/input/email.d.ts +1 -1
  15. package/dist/components/input/form_builder.d.ts +2 -2
  16. package/dist/components/input/input.d.ts +1 -1
  17. package/dist/components/input/search_input.d.ts +1 -1
  18. package/dist/components/input/search_input_list.d.ts +2 -2
  19. package/dist/components/input/select_vocabulary.d.ts +2 -2
  20. package/dist/components/input/upload.d.ts +1 -2
  21. package/dist/components/pagination.d.ts +1 -1
  22. package/dist/components/panel/permissions.d.ts +1 -1
  23. package/dist/components/panel/permissions_prinperm.d.ts +2 -2
  24. package/dist/components/panel/permissions_prinrole.d.ts +1 -1
  25. package/dist/components/panel/permissions_roleperm.d.ts +1 -1
  26. package/dist/components/path.d.ts +1 -1
  27. package/dist/components/properties_view.d.ts +2 -2
  28. package/dist/components/search_labels.d.ts +1 -1
  29. package/dist/components/search_options_labels.d.ts +1 -1
  30. package/dist/components/search_vocabulary_labels.d.ts +2 -2
  31. package/dist/components/tabs.d.ts +4 -2
  32. package/dist/components/widgets/tags.d.ts +4 -1
  33. package/dist/contexts/index.d.ts +21 -19
  34. package/dist/forms/required_fields.d.ts +2 -3
  35. package/dist/forms/users.d.ts +1 -1
  36. package/dist/hooks/useClickAway.d.ts +2 -1
  37. package/dist/hooks/useConfig.d.ts +4 -2
  38. package/dist/hooks/useCrudContext.d.ts +11 -10
  39. package/dist/hooks/useInput.d.ts +4 -3
  40. package/dist/hooks/useRegistry.d.ts +29 -29
  41. package/dist/hooks/useSetState.d.ts +6 -1
  42. package/dist/hooks/useVocabulary.d.ts +1 -1
  43. package/dist/index.d.ts +0 -2
  44. package/dist/lib/auth.d.ts +14 -19
  45. package/dist/lib/client.d.ts +49 -36
  46. package/dist/lib/helpers.d.ts +10 -18
  47. package/dist/lib/processResponse.d.ts +9 -0
  48. package/dist/lib/rest.d.ts +9 -16
  49. package/dist/lib/utils.d.ts +3 -2
  50. package/dist/lib/validators.d.ts +1 -1
  51. package/dist/locales/generic_messages.d.ts +248 -0
  52. package/dist/models/index.d.ts +5 -5
  53. package/dist/models/sharing.d.ts +5 -5
  54. package/dist/react-gmi.esm.js +1215 -1041
  55. package/dist/react-gmi.esm.js.map +1 -1
  56. package/dist/react-gmi.js +1214 -1041
  57. package/dist/react-gmi.js.map +1 -1
  58. package/dist/react-gmi.modern.js +1182 -983
  59. package/dist/react-gmi.modern.js.map +1 -1
  60. package/dist/react-gmi.umd.js +1214 -1041
  61. package/dist/react-gmi.umd.js.map +1 -1
  62. package/dist/reducers/guillotina.d.ts +22 -8
  63. package/dist/types/global.d.ts +9 -0
  64. package/dist/types/guillotina.d.ts +153 -19
  65. package/dist/views/folder.d.ts +1 -1
  66. package/dist/views/groups.d.ts +1 -1
  67. package/dist/views/item.d.ts +1 -1
  68. package/dist/views/users.d.ts +1 -1
  69. package/package.json +2 -1
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import React, { createContext, useContext, useState, useCallback, useRef, useEffect, forwardRef, Children, isValidElement, cloneElement, Fragment as Fragment$1, Component, useReducer } from 'react';
2
+ import React, { createContext, useContext, useState, useCallback, useRef, useEffect, forwardRef, Children, isValidElement, cloneElement, Fragment as Fragment$1, useMemo, Component, useReducer } from 'react';
3
3
  import usePortal from 'react-useportal';
4
4
  import { defineMessages, useIntl, injectIntl, IntlProvider } from 'react-intl';
5
5
  import PropTypes from 'prop-types';
@@ -40,6 +40,97 @@ function _objectWithoutPropertiesLoose(source, excluded) {
40
40
  return target;
41
41
  }
42
42
 
43
+ const initialState = {
44
+ path: '',
45
+ loading: false,
46
+ context: undefined,
47
+ flash: {
48
+ message: undefined,
49
+ type: undefined
50
+ },
51
+ action: {
52
+ action: undefined,
53
+ params: undefined
54
+ },
55
+ permissions: [],
56
+ errorStatus: undefined,
57
+ registry: {},
58
+ refresh: undefined
59
+ };
60
+ var GuillotinaReducerActionTypes;
61
+
62
+ (function (GuillotinaReducerActionTypes) {
63
+ GuillotinaReducerActionTypes["SET_PATH"] = "SET_PATH";
64
+ GuillotinaReducerActionTypes["SET_CONTEXT"] = "SET_CONTEXT";
65
+ GuillotinaReducerActionTypes["SET_ERROR"] = "SET_ERROR";
66
+ GuillotinaReducerActionTypes["SET_FLASH"] = "SET_FLASH";
67
+ GuillotinaReducerActionTypes["CLEAR_FLASH"] = "CLEAR_FLASH";
68
+ GuillotinaReducerActionTypes["SET_ACTION"] = "SET_ACTION";
69
+ GuillotinaReducerActionTypes["CLEAR_ACTION"] = "CLEAR_ACTION";
70
+ GuillotinaReducerActionTypes["REFRESH"] = "REFRESH";
71
+ GuillotinaReducerActionTypes["APPLY"] = "APPLY";
72
+ })(GuillotinaReducerActionTypes || (GuillotinaReducerActionTypes = {}));
73
+
74
+ function guillotinaReducer(state, action) {
75
+ switch (action.type) {
76
+ case GuillotinaReducerActionTypes.SET_PATH:
77
+ return _extends({}, state, {
78
+ path: action.payload.path,
79
+ loading: true
80
+ });
81
+
82
+ case GuillotinaReducerActionTypes.SET_CONTEXT:
83
+ return _extends({}, state, action.payload, {
84
+ errorStatus: undefined,
85
+ loading: false
86
+ });
87
+
88
+ case GuillotinaReducerActionTypes.SET_ERROR:
89
+ return _extends({}, state, {
90
+ errorStatus: action.payload.errorStatus,
91
+ loading: false
92
+ });
93
+
94
+ case GuillotinaReducerActionTypes.SET_FLASH:
95
+ return _extends({}, state, action.payload);
96
+
97
+ case GuillotinaReducerActionTypes.CLEAR_FLASH:
98
+ return _extends({}, state, {
99
+ flash: {
100
+ message: undefined,
101
+ type: undefined
102
+ }
103
+ });
104
+
105
+ case GuillotinaReducerActionTypes.SET_ACTION:
106
+ return _extends({}, state, {
107
+ action: action.payload
108
+ });
109
+
110
+ case GuillotinaReducerActionTypes.CLEAR_ACTION:
111
+ return _extends({}, state, {
112
+ action: {
113
+ action: undefined,
114
+ params: undefined
115
+ }
116
+ });
117
+
118
+ case GuillotinaReducerActionTypes.REFRESH:
119
+ return _extends({}, state, {
120
+ refresh: Date.now(),
121
+ loading: !action.payload.transparent
122
+ });
123
+
124
+ case GuillotinaReducerActionTypes.APPLY:
125
+ return _extends({}, state, {
126
+ context: _extends({}, state.context, action.payload.context)
127
+ });
128
+
129
+ default:
130
+ return state;
131
+ }
132
+ }
133
+
43
134
  const AuthContext = createContext({});
44
135
  const ClientContext = createContext(null);
45
136
  class Traversal {
@@ -68,7 +159,7 @@ class Traversal {
68
159
  transparent = false
69
160
  } = {}) {
70
161
  this.dispatch({
71
- type: 'REFRESH',
162
+ type: GuillotinaReducerActionTypes.REFRESH,
72
163
  payload: {
73
164
  transparent
74
165
  }
@@ -84,6 +175,10 @@ class Traversal {
84
175
  }
85
176
 
86
177
  get context() {
178
+ if (this.state.context === undefined) {
179
+ throw new Error('Context is not loaded');
180
+ }
181
+
87
182
  return this.state.context;
88
183
  }
89
184
 
@@ -94,14 +189,16 @@ class Traversal {
94
189
  apply(data) {
95
190
  // apply a optimistic update to context
96
191
  this.dispatch({
97
- type: 'APPLY',
98
- payload: data
192
+ type: GuillotinaReducerActionTypes.APPLY,
193
+ payload: {
194
+ context: data
195
+ }
99
196
  });
100
197
  }
101
198
 
102
199
  flash(message, type) {
103
200
  this.dispatch({
104
- type: 'SET_FLASH',
201
+ type: GuillotinaReducerActionTypes.SET_FLASH,
105
202
  payload: {
106
203
  flash: {
107
204
  message,
@@ -118,13 +215,14 @@ class Traversal {
118
215
 
119
216
  clearFlash() {
120
217
  this.dispatch({
121
- type: 'CLEAR_FLASH'
218
+ type: GuillotinaReducerActionTypes.CLEAR_FLASH,
219
+ payload: {}
122
220
  });
123
221
  }
124
222
 
125
223
  doAction(action, params = {}) {
126
224
  this.dispatch({
127
- type: 'SET_ACTION',
225
+ type: GuillotinaReducerActionTypes.SET_ACTION,
128
226
  payload: {
129
227
  action,
130
228
  params
@@ -134,7 +232,8 @@ class Traversal {
134
232
 
135
233
  cancelAction() {
136
234
  this.dispatch({
137
- type: 'CLEAR_ACTION'
235
+ type: GuillotinaReducerActionTypes.CLEAR_ACTION,
236
+ payload: {}
138
237
  });
139
238
  }
140
239
 
@@ -170,7 +269,13 @@ function TraversalProvider(_ref2) {
170
269
  });
171
270
  }
172
271
  function useTraversal() {
173
- return useContext(TraversalContext);
272
+ const traversal = useContext(TraversalContext);
273
+
274
+ if (!traversal) {
275
+ throw new Error('useTraversal must be used within a TraversalProvider');
276
+ }
277
+
278
+ return traversal;
174
279
  }
175
280
  function ClientProvider({
176
281
  children,
@@ -182,7 +287,13 @@ function ClientProvider({
182
287
  });
183
288
  }
184
289
  function useGuillotinaClient() {
185
- return useContext(ClientContext);
290
+ const client = useContext(ClientContext);
291
+
292
+ if (!client) {
293
+ throw new Error('useGuillotinaClient must be used within a ClientProvider');
294
+ }
295
+
296
+ return client;
186
297
  }
187
298
 
188
299
  const genericMessages = defineMessages({
@@ -703,7 +814,7 @@ function stringToSlug(str) {
703
814
  function sleep(ms) {
704
815
  return new Promise(resolve => {
705
816
  setTimeout(function () {
706
- resolve(null);
817
+ resolve();
707
818
  }, ms);
708
819
  });
709
820
  }
@@ -734,7 +845,7 @@ const Button = ({
734
845
  disabled: _disabled = false,
735
846
  dataTest
736
847
  }) => {
737
- let css = [].concat('button', ..._className.split(' '));
848
+ let css = [..._className.split(' '), 'button'];
738
849
  if (_loading) css = css.concat('is-loading');
739
850
  return jsx("p", {
740
851
  className: "control",
@@ -749,6 +860,41 @@ const Button = ({
749
860
  });
750
861
  };
751
862
 
863
+ const formatDate = str => {
864
+ const d = new Date(str);
865
+ const minutes = d.getMinutes() < 10 ? `0${d.getMinutes()}` : d.getMinutes();
866
+ return `${d.getDate()}/${d.getMonth() + 1}/${d.getFullYear()} ${d.getHours()}:${minutes}`;
867
+ };
868
+ const get = (obj, path, defValue) => {
869
+ var _pathArray$reduce;
870
+
871
+ // If path is not defined or it has false value
872
+ if (!path) return defValue; // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
873
+ // Regex explained: https://regexr.com/58j0k
874
+
875
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g); // Find value if exist return otherwise return undefined value;
876
+
877
+ if (pathArray === null) return defValue;
878
+ return (_pathArray$reduce = pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj)) != null ? _pathArray$reduce : defValue;
879
+ };
880
+ function getNewId(id = '') {
881
+ const suffix = '-copy-';
882
+ const rgx = new RegExp(`($|${suffix}\\d*)`);
883
+ return stringToSlug(id).replace(rgx, r => {
884
+ const num = parseInt(r.replace(suffix, '') || '0');
885
+ return `${suffix}${num + 1}`;
886
+ });
887
+ }
888
+ function debounce(callback, wait) {
889
+ let timer;
890
+ return (...args) => {
891
+ clearTimeout(timer);
892
+ return new Promise(resolve => {
893
+ timer = setTimeout(() => resolve(callback(...args)), wait);
894
+ });
895
+ };
896
+ }
897
+
752
898
  function Modal(props) {
753
899
  const {
754
900
  isActive,
@@ -838,7 +984,7 @@ function PathTree({
838
984
  }), jsxs("form", {
839
985
  onSubmit: e => {
840
986
  e.preventDefault();
841
- onConfirm(e.target[0].value, e.target);
987
+ onConfirm(get(e, 'target.0.value', ''), e.target);
842
988
  },
843
989
  children: [jsx("small", {
844
990
  style: {
@@ -870,22 +1016,6 @@ function PathTree({
870
1016
  });
871
1017
  }
872
1018
 
873
- function useSetState(initialState) {
874
- const [state, set] = useState(initialState);
875
- const setState = useCallback(patch => {
876
- set(prevState => Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch));
877
- }, [set]);
878
- return [state, setState];
879
- }
880
-
881
- const initial = {
882
- loading: undefined,
883
- isError: false,
884
- errorMessage: undefined,
885
- result: undefined,
886
- response: undefined
887
- };
888
-
889
1019
  const getErrorMessage = (dataError, defaultValue) => {
890
1020
  if (dataError && dataError.details) {
891
1021
  return dataError.details;
@@ -896,7 +1026,7 @@ const getErrorMessage = (dataError, defaultValue) => {
896
1026
  return defaultValue;
897
1027
  };
898
1028
 
899
- const processResponse = async (res, ready_body = true) => {
1029
+ async function processResponse(res, ready_body = true) {
900
1030
  if (res.status < 400) return {
901
1031
  isError: false,
902
1032
  loading: false,
@@ -905,98 +1035,139 @@ const processResponse = async (res, ready_body = true) => {
905
1035
  };else return {
906
1036
  isError: true,
907
1037
  loading: false,
908
- errorMessage: getErrorMessage(await res.json(), res.status),
1038
+ errorMessage: getErrorMessage(await res.json(), res.status).toString(),
909
1039
  response: res
910
1040
  };
911
- };
1041
+ }
912
1042
 
913
- const patch = (setState, Ctx) => async (data, endpoint = undefined, body = false) => {
914
- setState({
915
- loading: true
916
- });
917
- let newState = {};
1043
+ /**
1044
+ * Do setState like react class component.
1045
+ */
918
1046
 
919
- try {
920
- const path = endpoint ? `${Ctx.path}${endpoint}` : Ctx.path;
921
- const res = await Ctx.client.patch(path, data);
922
- newState = await processResponse(res, body);
923
- } catch (e) {
924
- console.error('Error', e);
925
- newState = {
926
- isError: true,
927
- errorMessage: 'unhandled exception'
928
- };
929
- }
1047
+ function useSetState(initialState) {
1048
+ const [state, setState] = useState(initialState); // Function which accepts a partial state to merge
1049
+
1050
+ const setCustomState = useCallback(newPartialState => {
1051
+ try {
1052
+ setState(prevState => {
1053
+ return _extends({}, prevState, newPartialState);
1054
+ });
1055
+ } catch (error) {
1056
+ // eslint-disable-next-line no-console
1057
+ console.error(error);
1058
+ }
1059
+ }, []); // Return
1060
+
1061
+ return [state, setCustomState];
1062
+ } // **** Export Default **** //
930
1063
 
931
- setState(newState);
932
- return newState;
1064
+ const initial = {
1065
+ loading: undefined,
1066
+ isError: false,
1067
+ errorMessage: undefined,
1068
+ result: undefined,
1069
+ response: undefined
933
1070
  };
934
1071
 
935
- const del = (setState, Ctx) => async (data = {}, endpoint = undefined, body = false) => {
936
- setState({
937
- loading: true
938
- });
939
- let newState = {};
1072
+ function patch(setState, Ctx) {
1073
+ return async (data = {}, endpoint, body = false) => {
1074
+ setState({
1075
+ loading: true
1076
+ });
1077
+ let newState = {};
940
1078
 
941
- try {
942
- const path = endpoint ? `${Ctx.path}${endpoint}` : Ctx.path;
943
- const res = await Ctx.client.delete(path, data);
944
- newState = await processResponse(res, body);
945
- } catch (e) {
946
- console.error('Error', e);
947
- newState = {
948
- isError: true,
949
- errorMessage: 'unhandled exception'
950
- };
951
- }
1079
+ try {
1080
+ const path = endpoint ? `${Ctx.path}${endpoint}` : Ctx.path;
1081
+ const res = await Ctx.client.patch(path, data);
1082
+ newState = await processResponse(res, body);
1083
+ } catch (e) {
1084
+ console.error('Error', e);
1085
+ newState = {
1086
+ isError: true,
1087
+ errorMessage: 'unhandled exception'
1088
+ };
1089
+ }
952
1090
 
953
- setState(newState);
954
- return newState;
955
- };
1091
+ setState(newState);
1092
+ return newState;
1093
+ };
1094
+ }
956
1095
 
957
- const post = (setState, Ctx) => async (data, endpoint = undefined, body = true) => {
958
- setState({
959
- loading: true
960
- });
961
- let newState = {};
1096
+ function del(setState, Ctx) {
1097
+ return async (data = {}, endpoint, body = false) => {
1098
+ setState({
1099
+ loading: true
1100
+ });
1101
+ let newState = {};
962
1102
 
963
- try {
964
- const path = endpoint ? `${Ctx.path}${endpoint}` : Ctx.path;
965
- const res = await Ctx.client.post(path, data);
966
- newState = await processResponse(res, body);
967
- } catch (e) {
968
- console.error('Error', e);
969
- newState = {
970
- isError: true,
971
- errorMessage: 'unhandled exception'
972
- };
973
- }
1103
+ try {
1104
+ const path = endpoint ? `${Ctx.path}${endpoint}` : Ctx.path;
1105
+ const res = await Ctx.client.delete(path, data);
1106
+ newState = await processResponse(res, body);
1107
+ } catch (e) {
1108
+ console.error('Error', e);
1109
+ newState = {
1110
+ isError: true,
1111
+ errorMessage: 'unhandled exception'
1112
+ };
1113
+ }
974
1114
 
975
- setState(newState);
976
- return newState;
977
- };
1115
+ setState(newState);
1116
+ return newState;
1117
+ };
1118
+ }
978
1119
 
979
- const get = (setState, Ctx) => async (endpoint = undefined) => {
980
- setState({
981
- loading: true
982
- });
983
- let newState = {};
1120
+ function post(setState, Ctx) {
1121
+ return async (data = {}, endpoint, body = true) => {
1122
+ setState({
1123
+ loading: true
1124
+ });
1125
+ let newState = {};
984
1126
 
985
- try {
986
- const path = endpoint ? `${Ctx.path}${endpoint}` : Ctx.path;
987
- const res = await Ctx.client.get(path);
988
- newState = await processResponse(res, true);
989
- } catch (e) {
990
- console.error('Error', e);
991
- newState = {
992
- isError: true,
993
- errorMessage: 'unhandled exception'
994
- };
995
- }
1127
+ try {
1128
+ const path = endpoint ? `${Ctx.path}${endpoint}` : Ctx.path;
1129
+ const res = await Ctx.client.post(path, data);
1130
+ newState = await processResponse(res, body);
1131
+ } catch (e) {
1132
+ console.error('Error', e);
1133
+ newState = {
1134
+ isError: true,
1135
+ errorMessage: 'unhandled exception'
1136
+ };
1137
+ }
1138
+
1139
+ setState(newState);
1140
+ return newState;
1141
+ };
1142
+ }
1143
+
1144
+ function get$1(setState, Ctx) {
1145
+ return async endpoint => {
1146
+ setState({
1147
+ loading: true
1148
+ });
1149
+ let newState = {};
1150
+
1151
+ try {
1152
+ const path = endpoint ? `${Ctx.path}${endpoint}` : Ctx.path;
1153
+ const res = await Ctx.client.get(path);
1154
+ newState = await processResponse(res, true);
1155
+ } catch (e) {
1156
+ console.error('Error', e);
1157
+ newState = {
1158
+ isError: true,
1159
+ errorMessage: 'unhandled exception'
1160
+ };
1161
+ }
1162
+
1163
+ setState(newState);
1164
+ return newState;
1165
+ };
1166
+ } // const get = (
1167
+ // setState: (value: Partial<State>) => void,
1168
+ // Ctx: Traversal
1169
+ // ) =>
996
1170
 
997
- setState(newState);
998
- return newState;
999
- };
1000
1171
 
1001
1172
  function useCrudContext() {
1002
1173
  const Ctx = useTraversal();
@@ -1006,7 +1177,7 @@ function useCrudContext() {
1006
1177
  patch: patch(setState, Ctx),
1007
1178
  del: del(setState, Ctx),
1008
1179
  post: post(setState, Ctx),
1009
- get: get(setState, Ctx)
1180
+ get: get$1(setState, Ctx)
1010
1181
  });
1011
1182
  }
1012
1183
 
@@ -1053,7 +1224,6 @@ function AddItem(props) {
1053
1224
  children: jsx(Form, {
1054
1225
  loading: loading,
1055
1226
  onSubmit: doSubmit,
1056
- onError: err => console.log(err),
1057
1227
  actionName: 'Add ' + type,
1058
1228
  title: 'Add ' + type,
1059
1229
  type: type,
@@ -1063,7 +1233,7 @@ function AddItem(props) {
1063
1233
  }
1064
1234
 
1065
1235
  const Permissions = ['guillotina.AddContent', 'guillotina.ModifyContent', 'guillotina.ViewContent', 'guillotina.DeleteContent', 'guillotina.AccessContent', 'guillotina.SeePermissions', 'guillotina.ChangePermissions', 'guillotina.MoveContent', 'guillotina.DuplicateContent', 'guillotina.ReadConfiguration', 'guillotina.RegisterConfigurations', 'guillotina.WriteConfiguration', 'guillotina.ManageAddons', 'guillotina.swagger.View'];
1066
- const Config = {
1236
+ const defaultConfig = {
1067
1237
  DisabledTypes: ['UserManager', 'GroupManager'],
1068
1238
  PageSize: 10,
1069
1239
  DelayActions: 200,
@@ -1074,21 +1244,39 @@ const Config = {
1074
1244
  return (schema == null ? void 0 : schema.widget) === 'file' || (schema == null ? void 0 : schema.widget) === 'select' || (schema == null ? void 0 : schema.type) === 'array';
1075
1245
  }
1076
1246
  };
1077
- let calculated = Object.assign({}, Config);
1078
-
1079
- const addConfig = (additional, original) => {
1080
- const rest = Object.assign({}, original);
1081
- Object.keys(additional).forEach(item => {
1082
- if (typeof Config[item] === 'object' && Array.isArray(Config[item])) {
1083
- rest[item] = [].concat(Config[item], additional[item]);
1084
- } else if (typeof Config[item] === 'object') {
1085
- rest[item] = Object.assign({}, Config[item], additional[item]);
1247
+ let calculated = Object.assign({}, defaultConfig);
1248
+
1249
+ function addConfig(updates, currentConfig) {
1250
+ let updatedConfig = _extends({}, currentConfig);
1251
+
1252
+ Object.entries(updates).forEach(([key, value]) => {
1253
+ const currentKey = key;
1254
+ const currentValue = currentConfig[currentKey];
1255
+
1256
+ if (Array.isArray(value) && Array.isArray(currentValue)) {
1257
+ // Correctly type the array concatenation
1258
+ updatedConfig = _extends({}, updatedConfig, {
1259
+ [currentKey]: [...currentValue, ...value]
1260
+ });
1261
+ } else if (isPlainObject(value) && isPlainObject(currentValue)) {
1262
+ // Correctly type the object merging
1263
+ updatedConfig = _extends({}, updatedConfig, {
1264
+ [currentKey]: _extends({}, currentValue, value)
1265
+ });
1086
1266
  } else {
1087
- rest[item] = additional[item];
1267
+ // Directly assign all other types
1268
+ updatedConfig = _extends({}, updatedConfig, {
1269
+ [currentKey]: value
1270
+ });
1088
1271
  }
1089
1272
  });
1090
- return rest;
1091
- };
1273
+ return updatedConfig;
1274
+ } // Helper function to check if a value is a plain object (and not a React node, etc.)
1275
+
1276
+
1277
+ function isPlainObject(value) {
1278
+ return Object.prototype.toString.call(value) === '[object Object]';
1279
+ }
1092
1280
 
1093
1281
  function useConfig(cfg = {}) {
1094
1282
  const ref = useRef();
@@ -1108,14 +1296,14 @@ function RemoveItems(props) {
1108
1296
  const {
1109
1297
  items = []
1110
1298
  } = props;
1111
- const last = items[items.length - 1]['@name'];
1112
- const itemsNames = items.map(item => item['@name']).join(', ').replace(`, ${last}`, ` and ${last}`);
1299
+ const last = items[items.length - 1].id;
1300
+ const itemsNames = items.map(item => item.id).join(', ').replace(`, ${last}`, ` and ${last}`);
1113
1301
 
1114
1302
  async function removeItems() {
1115
1303
  const errors = [];
1116
1304
  setLoading(true);
1117
1305
  const actions = items.map(async item => {
1118
- const res = await Ctx.client.delete(`${Ctx.path}${item['@name']}`);
1306
+ const res = await Ctx.client.delete(`${Ctx.path}${item.id}`, {});
1119
1307
 
1120
1308
  if (!res.ok) {
1121
1309
  const err = await res.json();
@@ -1161,7 +1349,7 @@ const Checkbox = ({
1161
1349
  dataTest
1162
1350
  }) => {
1163
1351
  const inputRef = useRef(null);
1164
- const [state, setState] = useState(checked);
1352
+ const [state, setState] = useState(!!checked);
1165
1353
  useEffect(() => {
1166
1354
  if (inputRef.current) {
1167
1355
  inputRef.current.indeterminate = _indeterminate;
@@ -1177,13 +1365,13 @@ const Checkbox = ({
1177
1365
  className: "field",
1178
1366
  children: jsxs("label", {
1179
1367
  htmlFor: id,
1180
- className: classnames(['checkbox', className]),
1368
+ className: classnames(['checkbox', className != null ? className : '']),
1181
1369
  children: [jsx("input", {
1182
1370
  ref: inputRef,
1183
1371
  disabled: disabled || loading,
1184
1372
  id: id,
1185
1373
  type: "checkbox",
1186
- className: classnames(['checkbox', classNameInput]),
1374
+ className: classnames(['checkbox', classNameInput != null ? classNameInput : '']),
1187
1375
  checked: state,
1188
1376
  onChange: updateState,
1189
1377
  "data-test": dataTest
@@ -1221,14 +1409,14 @@ const applyValidators = (value, validators) => {
1221
1409
  return result;
1222
1410
  };
1223
1411
 
1224
- const useInput = (onChange, value, validator) => {
1412
+ const useInput = (onChange, value, validators) => {
1225
1413
  const [state, setState] = useState({
1226
1414
  hasError: false,
1227
1415
  value: value
1228
1416
  });
1229
1417
 
1230
1418
  const onUpdate = ev => {
1231
- const value = ev && ev.target ? ev.target.value : ev ? ev : '';
1419
+ const value = ev && ev.target ? ev.target.value : '';
1232
1420
  setState({
1233
1421
  value,
1234
1422
  hasError: false
@@ -1237,7 +1425,7 @@ const useInput = (onChange, value, validator) => {
1237
1425
  };
1238
1426
 
1239
1427
  const onBlur = () => {
1240
- const hasError = applyValidators(state.value, validator) === false;
1428
+ const hasError = applyValidators(state.value, validators) === false;
1241
1429
  if (hasError) setState({
1242
1430
  value: state.value,
1243
1431
  hasError
@@ -1307,10 +1495,10 @@ const Input = forwardRef(({
1307
1495
  disabled,
1308
1496
  onKeyUp
1309
1497
  }, ref) => {
1310
- let validatorFn = null;
1498
+ let validatorFn = [];
1311
1499
 
1312
1500
  if (_required) {
1313
- validatorFn = Array.isArray(_validator) ? _validator.push(notEmpty) : [_validator, notEmpty];
1501
+ validatorFn = Array.isArray(_validator) ? [..._validator, notEmpty] : [_validator, notEmpty];
1314
1502
  }
1315
1503
 
1316
1504
  const _useInput = useInput(onChange, value != null ? value : '', validatorFn),
@@ -1322,15 +1510,15 @@ const Input = forwardRef(({
1322
1510
  const [uid] = useState(generateUID('input'));
1323
1511
  const [mounted, setMounted] = useState(false); // eslint-disable-next-line
1324
1512
 
1325
- ref = ref || useRef();
1513
+ const newRef = ref || useRef();
1326
1514
  useEffect(() => {
1327
1515
  setMounted(true);
1328
1516
  }, []);
1329
1517
  useEffect(() => {
1330
- if (_autofocus && !error && ref != null && typeof ref !== 'function') {
1331
- ref.current.focus();
1518
+ if (_autofocus && !error && newRef != null && typeof newRef !== 'function' && newRef.current) {
1519
+ newRef.current.focus();
1332
1520
  }
1333
- }, [mounted, _autofocus, ref, error]);
1521
+ }, [mounted, _autofocus, newRef, error]);
1334
1522
  const theError = state.hasError ? errorMessage || 'invalid field' : '';
1335
1523
  const statusClasses = state.hasError ? 'is-danger' : '';
1336
1524
 
@@ -1369,10 +1557,10 @@ Input.displayName = 'Input';
1369
1557
 
1370
1558
  const Icon = ({
1371
1559
  icon,
1372
- className,
1560
+ className: _className = '',
1373
1561
  align
1374
1562
  }) => {
1375
- const addClass = className ? className.split(' ') : [className];
1563
+ const addClass = _className ? _className.split(' ') : [_className];
1376
1564
  align = align || 'is-right';
1377
1565
  return jsx("span", {
1378
1566
  className: classnames(['icon', align, ...addClass]),
@@ -1477,7 +1665,7 @@ function FormBuilder({
1477
1665
  remotes = {},
1478
1666
  submitButton = true
1479
1667
  }) {
1480
- const ref = useRef();
1668
+ const ref = useRef(null);
1481
1669
  const {
1482
1670
  properties,
1483
1671
  required
@@ -1490,7 +1678,7 @@ function FormBuilder({
1490
1678
  initialState[element] = values[element] || undefined;
1491
1679
  }); // Register remotes
1492
1680
 
1493
- if (!ref.current) {
1681
+ if (ref.current === null) {
1494
1682
  ref.current = {};
1495
1683
  Object.keys(remotes).forEach(item => ref.current[item] = remotes[item]);
1496
1684
  } else {
@@ -1504,15 +1692,16 @@ function FormBuilder({
1504
1692
 
1505
1693
  ref.current = ref.current || {};
1506
1694
 
1507
- const onUpdate = field => ev => {
1508
- ref.current[field] = ev.target ? ev.target.value : ev.value || ev;
1695
+ const onUpdate = field => value => {
1696
+ ref.current[field] = value;
1509
1697
  };
1510
1698
 
1511
1699
  const GetTag = ({
1512
1700
  field
1513
1701
  }) => {
1514
1702
  const property = properties[field];
1515
- const Tag = formComponents[property.widget || property.type];
1703
+ const key = property.widget || property.type;
1704
+ const Tag = formComponents[key];
1516
1705
  const props = {
1517
1706
  value: initialState[field],
1518
1707
  onChange: onUpdate(field),
@@ -1527,7 +1716,6 @@ function FormBuilder({
1527
1716
  props.placeholder += ' *';
1528
1717
  }
1529
1718
 
1530
- Tag.displayName = `${field}Field`;
1531
1719
  return jsx(Tag, _extends({}, props));
1532
1720
  };
1533
1721
 
@@ -1586,9 +1774,13 @@ const Select = forwardRef(({
1586
1774
  selectValue = selectValue.concat([ev.target.selectedOptions[i].value]);
1587
1775
  }
1588
1776
 
1589
- onChange(selectValue);
1777
+ if (onChange) {
1778
+ onChange(selectValue);
1779
+ }
1590
1780
  } else {
1591
- onChange(ev.target.value);
1781
+ if (onChange) {
1782
+ onChange(ev.target.value);
1783
+ }
1592
1784
  }
1593
1785
  };
1594
1786
 
@@ -1639,33 +1831,137 @@ const Select = forwardRef(({
1639
1831
  });
1640
1832
  Select.displayName = 'Select';
1641
1833
 
1642
- // https://github.com/molefrog/wouter
1643
-
1644
- const setURLParams = p => {
1645
- return window.history.pushState(0, '0', '' + '?' + p.toString().replace(/%2F/g, '/'));
1646
- };
1834
+ function useVocabulary(vocabularyName, path) {
1835
+ const traversal = useTraversal();
1836
+ const [vocabulary, setVocabulary] = useSetState({
1837
+ data: undefined,
1838
+ loading: false,
1839
+ error: undefined
1840
+ });
1647
1841
 
1648
- const clean = to => {
1649
- const current = new URLSearchParams();
1650
- Object.keys(to).forEach(_key => current.set(_key, to[_key]));
1651
- setURLParams(current);
1652
- };
1842
+ const getPath = () => {
1843
+ if (path) return path;
1844
+ return `${traversal.path}@vocabularies/${vocabularyName}`;
1845
+ };
1653
1846
 
1654
- const useLocation = () => {
1655
- const [path, update] = useState(currentSearchParams());
1656
- const prevPath = useRef(path);
1657
1847
  useEffect(() => {
1658
- patchHistoryEvents(); // this function checks if the location has been changed since the
1659
- // last render and updates the state only when needed.
1660
- // unfortunately, we can't rely on `path` value here, since it can be stale,
1661
- // that's why we store the last pathname in a ref.
1662
-
1663
- const checkForUpdates = () => {
1664
- const pathname = currentSearchParams();
1665
- prevPath.current !== pathname && update(prevPath.current = pathname);
1848
+ const getVocabulary = async () => {
1849
+ if (vocabularyName && vocabulary.data === undefined && !vocabulary.loading) {
1850
+ try {
1851
+ setVocabulary({
1852
+ loading: true
1853
+ });
1854
+ const data = await traversal.client.get(getPath());
1855
+ const dataJson = await data.json();
1856
+ setVocabulary({
1857
+ loading: false,
1858
+ data: dataJson
1859
+ });
1860
+ } catch (err) {
1861
+ setVocabulary({
1862
+ loading: false,
1863
+ error: err,
1864
+ data: undefined
1865
+ });
1866
+ }
1867
+ }
1666
1868
  };
1667
1869
 
1668
- const events = ['popstate', 'pushState', 'replaceState'];
1870
+ getVocabulary();
1871
+ }, [vocabularyName, vocabulary, path]);
1872
+ return vocabulary;
1873
+ }
1874
+
1875
+ const SelectVocabulary = forwardRef(({
1876
+ vocabularyName,
1877
+ className,
1878
+ classWrap,
1879
+ val,
1880
+ dataTest,
1881
+ multiple,
1882
+ onChange,
1883
+ id,
1884
+ placeholder
1885
+ }, ref) => {
1886
+ const vocabulary = useVocabulary(vocabularyName);
1887
+
1888
+ const getOptions = () => {
1889
+ if (get(vocabulary, 'data.items', null)) {
1890
+ var _vocabulary$data$item, _vocabulary$data;
1891
+
1892
+ const vocData = ((_vocabulary$data$item = vocabulary == null ? void 0 : (_vocabulary$data = vocabulary.data) == null ? void 0 : _vocabulary$data.items) != null ? _vocabulary$data$item : []).map(item => {
1893
+ return {
1894
+ text: item.title,
1895
+ value: item.token
1896
+ };
1897
+ });
1898
+ return vocData;
1899
+ }
1900
+
1901
+ return [];
1902
+ };
1903
+
1904
+ const getProps = () => {
1905
+ if (multiple) {
1906
+ const currentValue = val || [];
1907
+ return {
1908
+ multiple: true,
1909
+ size: 5,
1910
+ value: currentValue,
1911
+ options: getOptions()
1912
+ };
1913
+ }
1914
+
1915
+ return {
1916
+ value: val != null ? val : '',
1917
+ appendDefault: true,
1918
+ options: getOptions()
1919
+ };
1920
+ };
1921
+
1922
+ if (vocabulary.data === undefined || vocabulary.loading) {
1923
+ return jsx("div", {});
1924
+ }
1925
+
1926
+ return jsx(Select, _extends({}, getProps(), {
1927
+ className: className,
1928
+ classWrap: classWrap || 'is-fullwidth',
1929
+ dataTest: dataTest,
1930
+ ref: ref,
1931
+ onChange: onChange,
1932
+ id: id,
1933
+ placeholder: placeholder
1934
+ }));
1935
+ });
1936
+ SelectVocabulary.displayName = 'SelectVocabulary';
1937
+
1938
+ // https://github.com/molefrog/wouter
1939
+
1940
+ const setURLParams = p => {
1941
+ return window.history.pushState(0, '0', '' + '?' + p.toString().replace(/%2F/g, '/'));
1942
+ };
1943
+
1944
+ const clean = to => {
1945
+ const current = new URLSearchParams();
1946
+ Object.keys(to).forEach(_key => current.set(_key, to[_key]));
1947
+ setURLParams(current);
1948
+ };
1949
+
1950
+ const useLocation = () => {
1951
+ const [path, update] = useState(currentSearchParams());
1952
+ const prevPath = useRef(path);
1953
+ useEffect(() => {
1954
+ patchHistoryEvents(); // this function checks if the location has been changed since the
1955
+ // last render and updates the state only when needed.
1956
+ // unfortunately, we can't rely on `path` value here, since it can be stale,
1957
+ // that's why we store the last pathname in a ref.
1958
+
1959
+ const checkForUpdates = () => {
1960
+ const pathname = currentSearchParams();
1961
+ prevPath.current !== pathname && update(prevPath.current = pathname);
1962
+ };
1963
+
1964
+ const events = ['popstate', 'pushState', 'replaceState'];
1669
1965
  events.map(e => window.addEventListener(e, checkForUpdates)); // it's possible that an update has occurred between render and the effect handler,
1670
1966
  // so we run additional check on mount to catch these updates. Based on:
1671
1967
  // https://gist.github.com/bvaughn/e25397f70e8c65b0ae0d7c90b731b189
@@ -1706,18 +2002,28 @@ let patched = 0;
1706
2002
 
1707
2003
  const patchHistoryEvents = () => {
1708
2004
  if (patched) return;
1709
- ['pushState', 'replaceState'].map(type => {
1710
- const original = window.history[type];
2005
+ const originalPushState = window.history.pushState;
1711
2006
 
1712
- window.history[type] = function (...args) {
1713
- const result = original.apply(this, args); // eslint-disable-next-line @typescript-eslint/no-explicit-any
2007
+ window.history.pushState = function (...args) {
2008
+ const result = originalPushState.apply(this, args); // eslint-disable-next-line @typescript-eslint/no-explicit-any
2009
+
2010
+ const event = new Event('pushState');
2011
+ event.arguments = args;
2012
+ dispatchEvent(event);
2013
+ return result;
2014
+ };
2015
+
2016
+ const originalReplaceState = window.history.replaceState;
2017
+
2018
+ window.history.replaceState = function (...args) {
2019
+ const result = originalReplaceState.apply(this, args); // eslint-disable-next-line @typescript-eslint/no-explicit-any
2020
+
2021
+ const event = new Event('replaceState');
2022
+ event.arguments = args;
2023
+ dispatchEvent(event);
2024
+ return result;
2025
+ };
1714
2026
 
1715
- const event = new Event(type);
1716
- event.arguments = args;
1717
- dispatchEvent(event);
1718
- return result;
1719
- };
1720
- });
1721
2027
  return patched = 1;
1722
2028
  };
1723
2029
 
@@ -1765,7 +2071,7 @@ function TdLink({
1765
2071
  children,
1766
2072
  style = {}
1767
2073
  }) {
1768
- const link = useRef();
2074
+ const link = useRef(null);
1769
2075
 
1770
2076
  function onClick() {
1771
2077
  if (link && link.current) {
@@ -1861,7 +2167,7 @@ class RestClient {
1861
2167
  this.container = container;
1862
2168
  }
1863
2169
 
1864
- async request(path, data = undefined, headers = undefined) {
2170
+ async request(path, data, headers, signal) {
1865
2171
  if (path.indexOf(this.url) !== -1) {
1866
2172
  path = path.replace(this.url, '');
1867
2173
  }
@@ -1874,19 +2180,28 @@ class RestClient {
1874
2180
  path = `/${path}`;
1875
2181
  }
1876
2182
 
1877
- data = data || {};
1878
- data.headers = headers || this.getHeaders();
1879
- return await fetch(`${this.url}${path}`, data);
2183
+ const dataRequest = data || {};
2184
+ dataRequest.headers = this.getHeaders();
2185
+
2186
+ if (headers) {
2187
+ dataRequest.headers = _extends({}, dataRequest.headers, headers);
2188
+ }
2189
+
2190
+ if (signal) {
2191
+ dataRequest.signal = signal;
2192
+ }
2193
+
2194
+ return await fetch(`${this.url}${path}`, dataRequest);
1880
2195
  }
1881
2196
 
1882
2197
  getHeaders() {
1883
2198
  const authToken = this.auth.getToken();
1884
- if (!authToken) return {};
1885
- return {
1886
- Accept: 'application/json',
1887
- 'Content-Type': 'application/json',
1888
- Authorization: 'Bearer ' + authToken
1889
- };
2199
+ const headersInit = {};
2200
+ if (!authToken) return headersInit;
2201
+ headersInit.Accept = 'application/json';
2202
+ headersInit['Content-Type'] = 'application/json';
2203
+ headersInit.Authorization = 'Bearer ' + authToken;
2204
+ return headersInit;
1890
2205
  }
1891
2206
 
1892
2207
  async post(path, data) {
@@ -1896,8 +2211,8 @@ class RestClient {
1896
2211
  });
1897
2212
  }
1898
2213
 
1899
- async get(path) {
1900
- return await this.request(path);
2214
+ async get(path, signal) {
2215
+ return await this.request(path, undefined, undefined, signal);
1901
2216
  }
1902
2217
 
1903
2218
  async put(path, data) {
@@ -1916,17 +2231,17 @@ class RestClient {
1916
2231
 
1917
2232
  async upload(path, data) {
1918
2233
  const headers = this.getHeaders();
1919
- delete headers['Content-Type'];
1920
- headers['Content-Type'] = data['content-type'];
1921
- headers['X-UPLOAD-FILENAME'] = data.filename;
1922
- headers['Content-Encoding'] = 'base64';
2234
+ const newHeaders = {};
2235
+ newHeaders['Content-Type'] = data['content-type'];
2236
+ newHeaders['X-UPLOAD-FILENAME'] = data.filename;
2237
+ newHeaders['Content-Encoding'] = 'base64';
1923
2238
  return await this.request(path, {
1924
2239
  method: 'PATCH',
1925
2240
  body: data.data
1926
- }, headers);
2241
+ }, _extends({}, headers, newHeaders));
1927
2242
  }
1928
2243
 
1929
- async delete(path, data = undefined) {
2244
+ async delete(path, data) {
1930
2245
  return await this.request(path, {
1931
2246
  method: 'delete',
1932
2247
  body: JSON.stringify(data)
@@ -2033,6 +2348,14 @@ class GuillotinaClient {
2033
2348
  return await this.rest.get(path);
2034
2349
  }
2035
2350
 
2351
+ getQueryParamsSearchFunction(name) {
2352
+ if (name === 'getQueryParamsElasticsearch') {
2353
+ return this.getQueryParamsElasticsearch;
2354
+ }
2355
+
2356
+ return this.getQueryParamsPostresql;
2357
+ }
2358
+
2036
2359
  getQueryParamsPostresql({
2037
2360
  start = 0,
2038
2361
  pageSize = 10,
@@ -2116,7 +2439,7 @@ class GuillotinaClient {
2116
2439
  label: 'id/name',
2117
2440
  key: 'title',
2118
2441
  isSortable: true,
2119
- child: (m, navigate, search) => jsxs(TdLink, {
2442
+ child: (m, _navigate, search) => jsxs(TdLink, {
2120
2443
  model: m,
2121
2444
  children: [m.name, search && jsxs(React.Fragment, {
2122
2445
  children: [jsx("br", {}), jsx("span", {
@@ -2150,12 +2473,15 @@ class GuillotinaClient {
2150
2473
 
2151
2474
 
2152
2475
  applyCompat(data) {
2153
- data.member = data.items;
2154
- data.items_count = data.items_total;
2155
- return data;
2476
+ const result = _extends({}, data, {
2477
+ member: data.items,
2478
+ items_count: data.items_total
2479
+ });
2480
+
2481
+ return result;
2156
2482
  }
2157
2483
 
2158
- async search(path, params, container = false, prepare = true) {
2484
+ async search(path, params, container = false, prepare = true, signal) {
2159
2485
  if (path.startsWith('/')) {
2160
2486
  path = path.slice(1);
2161
2487
  }
@@ -2166,7 +2492,7 @@ class GuillotinaClient {
2166
2492
 
2167
2493
  const query = prepare ? toQueryString(params) : params;
2168
2494
  const url = `${path}@search?${query}`;
2169
- const res = await this.rest.get(url);
2495
+ const res = await this.rest.get(url, signal);
2170
2496
  const data = await res.json();
2171
2497
  return this.applyCompat(data);
2172
2498
  }
@@ -2273,10 +2599,36 @@ class GuillotinaClient {
2273
2599
  async getPrincipals(path) {
2274
2600
  const groups = this.getGroups(path);
2275
2601
  const users = this.getUsers(path);
2276
- const [gr, usr] = await Promise.all([groups, users]);
2602
+ const [responseGroups, responseUsers] = await Promise.all([groups, users]);
2603
+ let groupsData = [];
2604
+ let usersData = [];
2605
+
2606
+ if (responseGroups.ok) {
2607
+ const groupsDataResponse = await responseGroups.json();
2608
+ groupsData = groupsDataResponse.map(group => {
2609
+ return {
2610
+ '@name': group.id,
2611
+ user_roles: group.roles,
2612
+ users: group.users
2613
+ };
2614
+ });
2615
+ }
2616
+
2617
+ if (responseUsers) {
2618
+ const usersDataResponse = await responseUsers.json();
2619
+ usersData = usersDataResponse.map(user => {
2620
+ return {
2621
+ '@name': user.id,
2622
+ user_roles: user.roles,
2623
+ fullname: user.fullname,
2624
+ email: user.email
2625
+ };
2626
+ });
2627
+ }
2628
+
2277
2629
  return {
2278
- groups: gr.ok ? await gr.json() : [],
2279
- users: usr.ok ? await usr.json() : []
2630
+ groups: groupsData,
2631
+ users: usersData
2280
2632
  };
2281
2633
  }
2282
2634
 
@@ -2321,17 +2673,24 @@ function getClient(url, container, auth) {
2321
2673
  return new GuillotinaClient(new RestClient(url, container, auth), container === '/');
2322
2674
  }
2323
2675
  const lightFileReader = file => {
2324
- return new Promise(resolve => {
2676
+ return new Promise((resolve, reject) => {
2325
2677
  const reader = new FileReader();
2326
2678
  reader.readAsArrayBuffer(file);
2327
2679
 
2328
2680
  reader.onloadend = e => {
2329
- const fileData = e.target.result;
2330
- resolve({
2331
- filename: file.name.normalize('NFD').replace(/[\u0300-\u036f]/g, ''),
2332
- data: fileData,
2333
- 'content-type': file.type
2334
- });
2681
+ var _e$target;
2682
+
2683
+ const fileData = e == null ? void 0 : (_e$target = e.target) == null ? void 0 : _e$target.result;
2684
+
2685
+ if (fileData) {
2686
+ resolve({
2687
+ filename: file.name.normalize('NFD').replace(/[\u0300-\u036f]/g, ''),
2688
+ data: fileData,
2689
+ 'content-type': file.type
2690
+ });
2691
+ } else {
2692
+ reject('Error reading file');
2693
+ }
2335
2694
  };
2336
2695
  });
2337
2696
  };
@@ -2358,8 +2717,10 @@ function FileUpload({
2358
2717
  const intl = useIntl();
2359
2718
 
2360
2719
  const changed = async event => {
2361
- const fileToUpload = await lightFileReader(event.target.files[0]);
2362
- onChange(fileToUpload);
2720
+ if (event.target.files) {
2721
+ const fileToUpload = await lightFileReader(event.target.files[0]);
2722
+ onChange(fileToUpload);
2723
+ }
2363
2724
  };
2364
2725
 
2365
2726
  return jsx("div", {
@@ -2442,9 +2803,9 @@ Textarea.displayName = 'Textarea';
2442
2803
 
2443
2804
  const defaultEvents = ['mousedown', 'touchstart'];
2444
2805
 
2445
- const on = (obj, ...args) => obj.addEventListener(...args);
2806
+ const on = (obj, type, handler) => obj.addEventListener(type, handler);
2446
2807
 
2447
- const off = (obj, ...args) => obj.removeEventListener(...args);
2808
+ const off = (obj, type, handler) => obj.removeEventListener(type, handler);
2448
2809
 
2449
2810
  function useClickAway(ref, onClickAway, events = defaultEvents) {
2450
2811
  const savedCallback = useRef(onClickAway);
@@ -2471,50 +2832,7 @@ function useClickAway(ref, onClickAway, events = defaultEvents) {
2471
2832
  }, [events, ref]);
2472
2833
  }
2473
2834
 
2474
- const formatDate = str => {
2475
- const d = new Date(str);
2476
- const minutes = d.getMinutes() < 10 ? `0${d.getMinutes()}` : d.getMinutes();
2477
- return `${d.getDate()}/${d.getMonth() + 1}/${d.getFullYear()} ${d.getHours()}:${minutes}`;
2478
- };
2479
- const get$1 = (obj, path, defValue) => {
2480
- var _pathArray$reduce;
2481
-
2482
- // If path is not defined or it has false value
2483
- if (!path) return undefined; // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
2484
- // Regex explained: https://regexr.com/58j0k
2485
-
2486
- const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g); // Find value if exist return otherwise return undefined value;
2487
-
2488
- return (_pathArray$reduce = pathArray.reduce((prevObj, key) => prevObj && prevObj[key], obj)) != null ? _pathArray$reduce : defValue;
2489
- };
2490
- function getNewId(id = '') {
2491
- const suffix = '-copy-';
2492
- const rgx = new RegExp(`($|${suffix}\\d*)`);
2493
- return stringToSlug(id).replace(rgx, r => {
2494
- const num = parseInt(r.replace(suffix, '') || '0');
2495
- return `${suffix}${num + 1}`;
2496
- });
2497
- }
2498
-
2499
- function debounce(func, wait) {
2500
- let timeout;
2501
- return function () {
2502
- // eslint-disable-next-line @typescript-eslint/no-this-alias
2503
- const context = this; // eslint-disable-next-line prefer-rest-params
2504
-
2505
- const args = arguments;
2506
-
2507
- const later = function later() {
2508
- timeout = null;
2509
- func.apply(context, args);
2510
- };
2511
-
2512
- clearTimeout(timeout);
2513
- timeout = setTimeout(later, wait);
2514
- };
2515
- }
2516
-
2517
- const initialState = {
2835
+ const initialState$1 = {
2518
2836
  page: 0,
2519
2837
  items: undefined,
2520
2838
  loading: false,
@@ -2524,8 +2842,8 @@ const SearchInput = ({
2524
2842
  onChange,
2525
2843
  error,
2526
2844
  errorZoneClassName,
2527
- traversal: _traversal = null,
2528
- path: _path = null,
2845
+ traversal,
2846
+ path: _path = undefined,
2529
2847
  qs: _qs = [],
2530
2848
  queryCondition: _queryCondition = 'id__in',
2531
2849
  value,
@@ -2533,12 +2851,12 @@ const SearchInput = ({
2533
2851
  dataTestWrapper: _dataTestWrapper = 'wrapperSearchInputTest',
2534
2852
  dataTestSearchInput: _dataTestSearchInput = 'searchInputTest',
2535
2853
  dataTestItem: _dataTestItem = 'searchInputItemTest',
2536
- renderTextItemOption: _renderTextItemOption = null,
2537
- typeNameQuery: _typeNameQuery = null,
2854
+ renderTextItemOption: _renderTextItemOption = undefined,
2855
+ typeNameQuery: _typeNameQuery = undefined,
2538
2856
  labelProperty: _labelProperty = 'id'
2539
2857
  }) => {
2540
2858
  const intl = useIntl();
2541
- const [options, setOptions] = useSetState(initialState);
2859
+ const [options, setOptions] = useSetState(initialState$1);
2542
2860
  const [isOpen, setIsOpen] = useState(false);
2543
2861
  const [searchTerm, setSearchTerm] = useState('');
2544
2862
  const inputRef = useRef(null);
@@ -2573,16 +2891,14 @@ const SearchInput = ({
2573
2891
  const searchTermParsed = [`id`, value];
2574
2892
  const {
2575
2893
  get: getSearch
2576
- } = _traversal.registry;
2894
+ } = traversal.registry;
2577
2895
  const fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
2578
-
2579
- const qsParsed = _traversal.client[fnName]({
2580
- path: _traversal.path,
2896
+ const qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
2897
+ path: traversal.path,
2581
2898
  start: 0,
2582
2899
  pageSize: PageSize,
2583
2900
  withDepth: false
2584
2901
  });
2585
-
2586
2902
  let typeNameParsed = [];
2587
2903
 
2588
2904
  if (_typeNameQuery) {
@@ -2593,9 +2909,9 @@ const SearchInput = ({
2593
2909
  searchTermQs = buildQs([..._qs, searchTermParsed, ...qsParsed, ...typeNameParsed]);
2594
2910
  }
2595
2911
 
2596
- const data = await _traversal.client.search(_path ? _path : _traversal.client.getContainerFromPath(_traversal.path), searchTermQs, false, false);
2912
+ const data = await traversal.client.search(_path ? _path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false);
2597
2913
  const newValuesLabel = data.items.reduce((result, item) => {
2598
- result[item.id] = get$1(item, _labelProperty, item.id);
2914
+ result[item.id] = get(item, _labelProperty, item.id);
2599
2915
  return result;
2600
2916
  }, {});
2601
2917
  setValueLabel(newValuesLabel);
@@ -2605,6 +2921,7 @@ const SearchInput = ({
2605
2921
  const handleSearch = async (page = 0, concat = false, value = '') => {
2606
2922
  var _data$items_total;
2607
2923
 
2924
+ console.log('handle search input');
2608
2925
  setOptions({
2609
2926
  loading: true
2610
2927
  });
@@ -2617,16 +2934,14 @@ const SearchInput = ({
2617
2934
 
2618
2935
  const {
2619
2936
  get
2620
- } = _traversal.registry;
2937
+ } = traversal.registry;
2621
2938
  const fnName = get('searchEngineQueryParamsFunction', SearchEngine);
2622
-
2623
- const qsParsed = _traversal.client[fnName]({
2624
- path: _traversal.path,
2939
+ const qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
2940
+ path: traversal.path,
2625
2941
  start: page * PageSize,
2626
2942
  pageSize: PageSize,
2627
2943
  withDepth: false
2628
2944
  });
2629
-
2630
2945
  const sortParsed = parser(`_sort_des=${_labelProperty}`);
2631
2946
  let typeNameParsed = [];
2632
2947
 
@@ -2634,11 +2949,11 @@ const SearchInput = ({
2634
2949
  typeNameParsed = parser(`type_name__in=${_typeNameQuery}`);
2635
2950
  }
2636
2951
 
2637
- if (_qs.length > 0 || searchTermParsed.length > 0 || qsParsed.length > 0 || typeNameParsed.length > 0) {
2952
+ if (_qs.length > 0 || searchTermParsed.length > 0 || qsParsed.length > 0 || typeNameParsed.length > 0 || sortParsed.length > 0) {
2638
2953
  searchTermQs = buildQs([..._qs, ...searchTermParsed, ...qsParsed, ...typeNameParsed, ...sortParsed]);
2639
2954
  }
2640
2955
 
2641
- const data = await _traversal.client.search(_path ? _path : _traversal.client.getContainerFromPath(_traversal.path), searchTermQs, false, false);
2956
+ const data = await traversal.client.search(_path ? _path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false);
2642
2957
  const newItems = options.items && concat ? [...options.items, ...data.items] : data.items;
2643
2958
  setOptions({
2644
2959
  items: newItems != null ? newItems : [],
@@ -2653,7 +2968,7 @@ const SearchInput = ({
2653
2968
  return _renderTextItemOption(item);
2654
2969
  }
2655
2970
 
2656
- return get$1(item, _labelProperty, item.title) || item['@name'];
2971
+ return get(item, _labelProperty, item.title) || item['@name'];
2657
2972
  };
2658
2973
 
2659
2974
  useEffect(() => {
@@ -2679,7 +2994,7 @@ const SearchInput = ({
2679
2994
  if (!ev.currentTarget.contains(ev.relatedTarget)) {
2680
2995
  if (searchTerm !== '') {
2681
2996
  setSearchTerm('');
2682
- setOptions(initialState);
2997
+ setOptions(initialState$1);
2683
2998
  }
2684
2999
 
2685
3000
  setIsOpen(false);
@@ -2697,6 +3012,7 @@ const SearchInput = ({
2697
3012
  }
2698
3013
 
2699
3014
  setIsOpen(!isOpen);
3015
+ console.log('on clic btn', options);
2700
3016
 
2701
3017
  if (!options.loading && !options.items) {
2702
3018
  handleSearch(options.page);
@@ -2705,7 +3021,7 @@ const SearchInput = ({
2705
3021
  "aria-haspopup": "true",
2706
3022
  "aria-controls": "dropdown-menu",
2707
3023
  children: [jsx("span", {
2708
- children: value ? get$1(valueLabel, value, value) : intl.formatMessage(genericMessages.choose)
3024
+ children: value ? get(valueLabel, value, value) : intl.formatMessage(genericMessages.choose)
2709
3025
  }), jsx("span", {
2710
3026
  className: "icon",
2711
3027
  children: jsx("i", {
@@ -2779,25 +3095,7 @@ const SearchInput = ({
2779
3095
  });
2780
3096
  };
2781
3097
 
2782
- function debounce$1(func, wait) {
2783
- let timeout;
2784
- return function () {
2785
- // eslint-disable-next-line @typescript-eslint/no-this-alias
2786
- const context = this; // eslint-disable-next-line prefer-rest-params
2787
-
2788
- const args = arguments;
2789
-
2790
- const later = function later() {
2791
- timeout = null;
2792
- func.apply(context, args);
2793
- };
2794
-
2795
- clearTimeout(timeout);
2796
- timeout = setTimeout(later, wait);
2797
- };
2798
- }
2799
-
2800
- const initialState$1 = {
3098
+ const initialState$2 = {
2801
3099
  page: 0,
2802
3100
  items: undefined,
2803
3101
  loading: false,
@@ -2807,8 +3105,8 @@ const SearchInputList = ({
2807
3105
  onChange,
2808
3106
  error,
2809
3107
  errorZoneClassName,
2810
- traversal: _traversal = null,
2811
- path: _path = null,
3108
+ traversal,
3109
+ path: _path = undefined,
2812
3110
  qs: _qs = [],
2813
3111
  queryCondition: _queryCondition = 'id__in',
2814
3112
  value,
@@ -2816,12 +3114,12 @@ const SearchInputList = ({
2816
3114
  dataTestWrapper: _dataTestWrapper = 'wrapperSearchInputTest',
2817
3115
  dataTestSearchInput: _dataTestSearchInput = 'searchInputTest',
2818
3116
  dataTestItem: _dataTestItem = 'searchInputItemTest',
2819
- renderTextItemOption: _renderTextItemOption = null,
2820
- typeNameQuery: _typeNameQuery = null,
3117
+ renderTextItemOption: _renderTextItemOption = undefined,
3118
+ typeNameQuery: _typeNameQuery = undefined,
2821
3119
  labelProperty: _labelProperty = 'id'
2822
3120
  }) => {
2823
3121
  const intl = useIntl();
2824
- const [options, setOptions] = useSetState(initialState$1);
3122
+ const [options, setOptions] = useSetState(initialState$2);
2825
3123
  const [valuesLabel, setValuesLabels] = useState(undefined);
2826
3124
  const [isOpen, setIsOpen] = useState(false);
2827
3125
  const [searchTerm, setSearchTerm] = useState('');
@@ -2849,7 +3147,7 @@ const SearchInputList = ({
2849
3147
  };
2850
3148
  };
2851
3149
 
2852
- const delayedQuery = useCallback(debounce$1(value => handleSearch(0, false, value), 500), []);
3150
+ const delayedQuery = useCallback(debounce(value => handleSearch(0, false, value), 500), []);
2853
3151
 
2854
3152
  const handleSearch = async (page = 0, concat = false, value = '') => {
2855
3153
  var _data$items_total;
@@ -2866,16 +3164,14 @@ const SearchInputList = ({
2866
3164
 
2867
3165
  const {
2868
3166
  get
2869
- } = _traversal.registry;
3167
+ } = traversal.registry;
2870
3168
  const fnName = get('searchEngineQueryParamsFunction', SearchEngine);
2871
-
2872
- const qsParsed = _traversal.client[fnName]({
2873
- path: _traversal.path,
3169
+ const qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
3170
+ path: traversal.path,
2874
3171
  start: page * PageSize,
2875
3172
  pageSize: PageSize,
2876
3173
  withDepth: false
2877
3174
  });
2878
-
2879
3175
  const sortParsed = parser(`_sort_des=${_labelProperty}`);
2880
3176
  let typeNameParsed = [];
2881
3177
 
@@ -2887,7 +3183,7 @@ const SearchInputList = ({
2887
3183
  searchTermQs = buildQs([..._qs, ...searchTermParsed, ...qsParsed, ...typeNameParsed, ...sortParsed]);
2888
3184
  }
2889
3185
 
2890
- const data = await _traversal.client.search(_path ? _path : _traversal.client.getContainerFromPath(_traversal.path), searchTermQs, false, false);
3186
+ const data = await traversal.client.search(_path ? _path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false);
2891
3187
  const newItems = options.items && concat ? [...options.items, ...data.items] : data.items;
2892
3188
  setOptions({
2893
3189
  items: newItems != null ? newItems : [],
@@ -2904,16 +3200,14 @@ const SearchInputList = ({
2904
3200
  const searchTermParsed = ['__or', `id=${value.join('%26id=')}`];
2905
3201
  const {
2906
3202
  get: getSearch
2907
- } = _traversal.registry;
3203
+ } = traversal.registry;
2908
3204
  const fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
2909
-
2910
- const qsParsed = _traversal.client[fnName]({
2911
- path: _traversal.path,
3205
+ const qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
3206
+ path: traversal.path,
2912
3207
  start: 0,
2913
3208
  pageSize: 100,
2914
3209
  withDepth: false
2915
3210
  });
2916
-
2917
3211
  let typeNameParsed = [];
2918
3212
 
2919
3213
  if (_typeNameQuery) {
@@ -2924,9 +3218,9 @@ const SearchInputList = ({
2924
3218
  searchTermQs = buildQs([..._qs, searchTermParsed, ...qsParsed, ...typeNameParsed]);
2925
3219
  }
2926
3220
 
2927
- const data = await _traversal.client.search(_path ? _path : _traversal.client.getContainerFromPath(_traversal.path), searchTermQs, false, false, 0, 100);
3221
+ const data = await traversal.client.search(_path ? _path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false);
2928
3222
  const newValuesLabel = data.items.reduce((result, item) => {
2929
- result[item.id] = get$1(item, _labelProperty, item.id);
3223
+ result[item.id] = get(item, _labelProperty, item.id);
2930
3224
  return result;
2931
3225
  }, {});
2932
3226
  setValuesLabels(newValuesLabel);
@@ -2939,7 +3233,7 @@ const SearchInputList = ({
2939
3233
  return _renderTextItemOption(item);
2940
3234
  }
2941
3235
 
2942
- return get$1(item, _labelProperty, item.title) || item['@name'];
3236
+ return get(item, _labelProperty, item.title) || item['@name'];
2943
3237
  };
2944
3238
 
2945
3239
  useEffect(() => {
@@ -2961,7 +3255,7 @@ const SearchInputList = ({
2961
3255
  className: "tags mb-2",
2962
3256
  children: value.map((tag, index) => jsxs("div", {
2963
3257
  className: "tag is-info is-medium",
2964
- children: [get$1(valuesLabel, tag, tag), jsx("button", {
3258
+ children: [get(valuesLabel, tag, tag), jsx("button", {
2965
3259
  className: "delete is-small",
2966
3260
  onClick: ev => {
2967
3261
  ev.stopPropagation();
@@ -2978,7 +3272,7 @@ const SearchInputList = ({
2978
3272
  if (!ev.currentTarget.contains(ev.relatedTarget)) {
2979
3273
  if (searchTerm !== '') {
2980
3274
  setSearchTerm('');
2981
- setOptions(initialState$1);
3275
+ setOptions(initialState$2);
2982
3276
  }
2983
3277
 
2984
3278
  setIsOpen(false);
@@ -3041,7 +3335,7 @@ const SearchInputList = ({
3041
3335
 
3042
3336
  if (onChange && !value.includes(item.id)) {
3043
3337
  setValuesLabels(_extends({}, valuesLabel, {
3044
- [item.id]: get$1(item, _labelProperty, item.id)
3338
+ [item.id]: get(item, _labelProperty, item.id)
3045
3339
  }));
3046
3340
  onChange([...value, item.id]);
3047
3341
  }
@@ -3206,7 +3500,7 @@ function EditableField({
3206
3500
  ref.current.focus();
3207
3501
  }
3208
3502
  });
3209
- const canModified = modifyContent && !get$1(schema, 'readonly', false);
3503
+ const canModified = schema !== undefined && modifyContent && !get(schema, 'readonly', false);
3210
3504
 
3211
3505
  const saveField = async ev => {
3212
3506
  if (ev) ev.preventDefault();
@@ -3264,6 +3558,8 @@ function EditableField({
3264
3558
  };
3265
3559
 
3266
3560
  const deleteField = async ev => {
3561
+ var _schema$items;
3562
+
3267
3563
  if (ev) ev.preventDefault();
3268
3564
 
3269
3565
  if ((schema == null ? void 0 : schema.widget) === 'file') {
@@ -3297,7 +3593,7 @@ function EditableField({
3297
3593
  Ctx.refresh();
3298
3594
  } else if ((schema == null ? void 0 : schema.type) === 'string' && schema != null && schema.enum) {
3299
3595
  setValue(null);
3300
- } else if ((schema == null ? void 0 : schema.type) === 'array' && (schema == null ? void 0 : schema.items.type) === 'string') {
3596
+ } else if ((schema == null ? void 0 : schema.type) === 'array' && (schema == null ? void 0 : (_schema$items = schema.items) == null ? void 0 : _schema$items.type) === 'string') {
3301
3597
  setValue([]);
3302
3598
  }
3303
3599
  };
@@ -3348,7 +3644,7 @@ function EditableField({
3348
3644
  dataTest: "editableFieldBtnCancelTest",
3349
3645
  children: intl.formatMessage(genericMessages.cancel)
3350
3646
  })
3351
- }), !required && fieldHaveDeleteButton(schema) && jsx("div", {
3647
+ }), !required && schema && fieldHaveDeleteButton(schema) && jsx("div", {
3352
3648
  className: "control",
3353
3649
  children: jsx(Button, {
3354
3650
  className: "is-small is-danger",
@@ -3435,47 +3731,6 @@ const DownloadField = ({
3435
3731
  });
3436
3732
  };
3437
3733
 
3438
- function useVocabulary(vocabularyName, path = null) {
3439
- const traversal = useTraversal();
3440
- const [vocabulary, setVocabulary] = useSetState({
3441
- data: undefined,
3442
- loading: false,
3443
- error: undefined
3444
- });
3445
-
3446
- const getPath = () => {
3447
- if (path) return path;
3448
- return `${traversal.path}@vocabularies/${vocabularyName}`;
3449
- };
3450
-
3451
- useEffect(() => {
3452
- const getVocabulary = async () => {
3453
- if (vocabularyName && vocabulary.data === undefined && !vocabulary.loading) {
3454
- try {
3455
- setVocabulary({
3456
- loading: true
3457
- });
3458
- const data = await traversal.client.get(getPath());
3459
- const dataJson = await data.json();
3460
- setVocabulary({
3461
- loading: false,
3462
- data: dataJson
3463
- });
3464
- } catch (err) {
3465
- setVocabulary({
3466
- loading: false,
3467
- error: err,
3468
- data: undefined
3469
- });
3470
- }
3471
- }
3472
- };
3473
-
3474
- getVocabulary();
3475
- }, [vocabularyName, vocabulary, path]);
3476
- return vocabulary;
3477
- }
3478
-
3479
3734
  const plain = ['string', 'number', 'boolean'];
3480
3735
  function RenderField({
3481
3736
  value,
@@ -3498,19 +3753,23 @@ function RenderField({
3498
3753
  }
3499
3754
 
3500
3755
  if (type === 'object') {
3756
+ var _schema$properties;
3757
+
3501
3758
  if (Array.isArray(value)) {
3502
- return value.map(item => jsx("div", {
3759
+ return value.map((item, index) => jsx("div", {
3503
3760
  children: jsx(RenderField, {
3504
3761
  value: item
3505
3762
  })
3506
- }, item));
3763
+ }, `renderField_${index}_${schema == null ? void 0 : schema.title}`));
3507
3764
  }
3508
3765
 
3509
- return Object.keys(value).map(key => jsx(FieldValue, {
3510
- field: get$1(schema, `properties.${key}.title`, key),
3511
- schema: get$1(schema, `properties.${key}`, {}),
3512
- value: value[key]
3513
- }, key));
3766
+ if ((schema == null ? void 0 : (_schema$properties = schema.properties) == null ? void 0 : _schema$properties.key) !== undefined) {
3767
+ return Object.keys(value).map(key => jsx(FieldValue, {
3768
+ field: get(schema, `properties.${key}.title`, key),
3769
+ schema: schema.properties.key,
3770
+ value: get(value, key, {})
3771
+ }, key));
3772
+ }
3514
3773
  }
3515
3774
 
3516
3775
  return jsxs("p", {
@@ -3554,6 +3813,7 @@ const SearchRenderField = ({
3554
3813
  value,
3555
3814
  modifyContent
3556
3815
  }) => {
3816
+ console.log('search render fields');
3557
3817
  const intl = useIntl();
3558
3818
  const [valuesLabels, setValuesLabels] = useState([]);
3559
3819
  const [isLoadingData, setIsLoadingData] = useState(false);
@@ -3571,7 +3831,7 @@ const SearchRenderField = ({
3571
3831
  get: getSearch
3572
3832
  } = traversal.registry;
3573
3833
  const fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
3574
- const qsParsed = traversal.client[fnName]({
3834
+ const qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
3575
3835
  path: traversal.path,
3576
3836
  start: 0,
3577
3837
  pageSize: 100,
@@ -3582,23 +3842,25 @@ const SearchRenderField = ({
3582
3842
  searchTermQs = buildQs([searchTermParsed, ...qsParsed]);
3583
3843
  }
3584
3844
 
3585
- const data = await traversal.client.search(traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false, 0, 100);
3845
+ const data = await traversal.client.search(traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false);
3586
3846
  const newValuesLabel = data.items.map(item => {
3587
3847
  var _schema$labelProperty;
3588
3848
 
3589
- return get$1(item, (_schema$labelProperty = schema == null ? void 0 : schema.labelProperty) != null ? _schema$labelProperty : 'title', item.id);
3849
+ return get(item, (_schema$labelProperty = schema == null ? void 0 : schema.labelProperty) != null ? _schema$labelProperty : 'title', item.id);
3590
3850
  });
3591
3851
  setValuesLabels(newValuesLabel);
3592
3852
  setIsLoadingData(false);
3593
3853
  };
3594
3854
 
3595
- let valuesToSearch = value;
3855
+ let valuesToSearch = [];
3596
3856
 
3597
- if (typeof valuesToSearch === 'string') {
3598
- valuesToSearch = [valuesToSearch];
3857
+ if (typeof value === 'string' && value) {
3858
+ valuesToSearch = [value];
3859
+ } else if (Array.isArray(value)) {
3860
+ valuesToSearch = value;
3599
3861
  }
3600
3862
 
3601
- if (valuesToSearch !== undefined && valuesToSearch.length > 0) {
3863
+ if (valuesToSearch.length > 0) {
3602
3864
  fetchData(valuesToSearch);
3603
3865
  } else {
3604
3866
  setValuesLabels([]);
@@ -3634,7 +3896,7 @@ const VocabularyRenderField = ({
3634
3896
 
3635
3897
  const intl = useIntl();
3636
3898
  const DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl);
3637
- const vocabularyName = (schema == null ? void 0 : (_schema$items = schema.items) == null ? void 0 : _schema$items.vocabularyName) || (schema == null ? void 0 : schema.vocabularyName);
3899
+ const vocabularyName = (schema == null ? void 0 : (_schema$items = schema.items) == null ? void 0 : _schema$items.vocabularyName) || (schema == null ? void 0 : schema.vocabularyName) || '';
3638
3900
  const vocabulary = useVocabulary(vocabularyName);
3639
3901
 
3640
3902
  const getRenderProps = () => {
@@ -3645,7 +3907,7 @@ const VocabularyRenderField = ({
3645
3907
  if (schema != null && schema.vocabularyName) {
3646
3908
  var _vocabularyValue$titl;
3647
3909
 
3648
- const vocabularyValue = get$1(vocabulary, 'data.items', []).find(item => item.token === value);
3910
+ const vocabularyValue = get(vocabulary, 'data.items', []).find(item => item.token === value);
3649
3911
  renderProps['value'] = (_vocabularyValue$titl = vocabularyValue == null ? void 0 : vocabularyValue.title) != null ? _vocabularyValue$titl : '';
3650
3912
  } else {
3651
3913
  var _renderProps$value;
@@ -3653,7 +3915,7 @@ const VocabularyRenderField = ({
3653
3915
  renderProps['value'] = ((_renderProps$value = renderProps['value']) != null ? _renderProps$value : []).map(value => {
3654
3916
  var _get$find$title, _get$find;
3655
3917
 
3656
- return (_get$find$title = (_get$find = get$1(vocabulary, 'data.items', []).find(item => item.token === value)) == null ? void 0 : _get$find.title) != null ? _get$find$title : '';
3918
+ return (_get$find$title = (_get$find = get(vocabulary, 'data.items', []).find(item => item.token === value)) == null ? void 0 : _get$find.title) != null ? _get$find$title : '';
3657
3919
  });
3658
3920
  }
3659
3921
 
@@ -3704,76 +3966,15 @@ function RenderFieldComponent({
3704
3966
  return jsx(RenderField, _extends({}, getRenderProps()));
3705
3967
  }
3706
3968
 
3707
- const SelectVocabulary = forwardRef(({
3708
- vocabularyName,
3709
- className,
3710
- classWrap,
3969
+ const EditComponent = forwardRef(({
3970
+ schema,
3711
3971
  val,
3972
+ setValue,
3712
3973
  dataTest,
3713
- multiple,
3714
- onChange,
3974
+ className,
3975
+ placeholder,
3715
3976
  id,
3716
- placeholder
3717
- }, ref) => {
3718
- const vocabulary = useVocabulary(vocabularyName);
3719
-
3720
- const getOptions = () => {
3721
- if (get$1(vocabulary, 'data.items', null)) {
3722
- const vocData = vocabulary.data.items.map(item => {
3723
- return {
3724
- text: item.title,
3725
- value: item.token
3726
- };
3727
- });
3728
- return vocData;
3729
- }
3730
-
3731
- return [];
3732
- };
3733
-
3734
- const getProps = () => {
3735
- if (multiple) {
3736
- const currentValue = val || [];
3737
- return {
3738
- multiple: true,
3739
- size: 5,
3740
- value: currentValue,
3741
- options: getOptions()
3742
- };
3743
- }
3744
-
3745
- return {
3746
- value: val != null ? val : '',
3747
- appendDefault: true,
3748
- options: getOptions()
3749
- };
3750
- };
3751
-
3752
- if (vocabulary.data === undefined || vocabulary.loading) {
3753
- return jsx("div", {});
3754
- }
3755
-
3756
- return jsx(Select, _extends({}, getProps(), {
3757
- className: className,
3758
- classWrap: classWrap || 'is-fullwidth',
3759
- dataTest: dataTest,
3760
- ref: ref,
3761
- onChange: onChange,
3762
- id: id,
3763
- placeholder: placeholder
3764
- }));
3765
- });
3766
- SelectVocabulary.displayName = 'SelectVocabulary';
3767
-
3768
- const EditComponent = forwardRef(({
3769
- schema,
3770
- val,
3771
- setValue,
3772
- dataTest,
3773
- className,
3774
- placeholder,
3775
- id,
3776
- required
3977
+ required
3777
3978
  }, ref) => {
3778
3979
  const traversal = useTraversal();
3779
3980
 
@@ -3789,7 +3990,7 @@ const EditComponent = forwardRef(({
3789
3990
  queryCondition: schema != null && schema.queryCondition ? schema.queryCondition : 'title__in',
3790
3991
  path: schema.queryPath,
3791
3992
  labelProperty: schema != null && schema.labelProperty ? schema.labelProperty : 'title',
3792
- typeNameQuery: schema != null && schema.typeNameQuery ? schema.typeNameQuery : null
3993
+ typeNameQuery: schema == null ? void 0 : schema.typeNameQuery
3793
3994
  })]
3794
3995
  });
3795
3996
  } else if ((schema == null ? void 0 : schema.widget) === 'search') {
@@ -3804,7 +4005,7 @@ const EditComponent = forwardRef(({
3804
4005
  queryCondition: schema != null && schema.queryCondition ? schema.queryCondition : 'title__in',
3805
4006
  path: schema.queryPath,
3806
4007
  labelProperty: schema != null && schema.labelProperty ? schema.labelProperty : 'title',
3807
- typeNameQuery: schema != null && schema.typeNameQuery ? schema.typeNameQuery : null
4008
+ typeNameQuery: schema == null ? void 0 : schema.typeNameQuery
3808
4009
  })]
3809
4010
  });
3810
4011
  } else if ((schema == null ? void 0 : schema.widget) === 'textarea' || (schema == null ? void 0 : schema.widget) === 'richtext') {
@@ -3830,7 +4031,7 @@ const EditComponent = forwardRef(({
3830
4031
 
3831
4032
  if (schema.items.vocabularyName) {
3832
4033
  return jsx(SelectVocabulary, {
3833
- vocabularyName: get$1(schema, 'items.vocabularyName', null),
4034
+ vocabularyName: get(schema, 'items.vocabularyName', ''),
3834
4035
  val: val || [],
3835
4036
  className: className,
3836
4037
  classWrap: "is-fullwidth",
@@ -3867,18 +4068,21 @@ const EditComponent = forwardRef(({
3867
4068
  }), jsx(InputList, {
3868
4069
  value: val || [],
3869
4070
  className: className,
3870
- onChange: ev => setValue(ev),
4071
+ onChange: val => setValue(val),
3871
4072
  ref: ref,
3872
4073
  dataTest: dataTest
3873
4074
  })]
3874
4075
  });
3875
4076
  } else if ((schema == null ? void 0 : schema.widget) === 'file') {
4077
+ const value = val;
3876
4078
  return jsx(FileUpload, {
3877
4079
  onChange: ev => setValue(ev),
3878
- label: get$1(val, 'filename', null),
4080
+ label: get(value, 'filename', undefined),
3879
4081
  dataTest: dataTest
3880
4082
  });
3881
4083
  } else if ((schema == null ? void 0 : schema.widget) === 'select' && schema.type === 'string') {
4084
+ var _schema$vocabulary;
4085
+
3882
4086
  if (schema != null && schema.vocabularyName) {
3883
4087
  return jsx(SelectVocabulary, {
3884
4088
  val: val || '',
@@ -3887,7 +4091,7 @@ const EditComponent = forwardRef(({
3887
4091
  classWrap: "is-fullwidth",
3888
4092
  dataTest: dataTest,
3889
4093
  onChange: setValue,
3890
- vocabularyName: get$1(schema, 'vocabularyName', null),
4094
+ vocabularyName: get(schema, 'vocabularyName', ''),
3891
4095
  placeholder: placeholder,
3892
4096
  id: id
3893
4097
  });
@@ -3899,7 +4103,7 @@ const EditComponent = forwardRef(({
3899
4103
  appendDefault: true,
3900
4104
  classWrap: "is-fullwidth",
3901
4105
  dataTest: dataTest,
3902
- options: schema == null ? void 0 : schema.vocabulary.map(item => {
4106
+ options: ((_schema$vocabulary = schema == null ? void 0 : schema.vocabulary) != null ? _schema$vocabulary : []).map(item => {
3903
4107
  return {
3904
4108
  text: item,
3905
4109
  value: item
@@ -3915,11 +4119,12 @@ const EditComponent = forwardRef(({
3915
4119
  children: [schema.title && jsx("h4", {
3916
4120
  className: "subtitle mt-2",
3917
4121
  children: schema.title
3918
- }), Object.keys(get$1(schema, 'properties', {})).map(key => {
4122
+ }), Object.keys(get(schema, 'properties', {})).map(key => {
3919
4123
  var _subSchema$title;
3920
4124
 
3921
- const subSchema = get$1(schema, 'properties', {})[key];
3922
- const requiredFields = get$1(schema, 'required', []);
4125
+ const subSchema = get(schema, `properties.${key}`, null);
4126
+ const requiredFields = get(schema, 'required', []);
4127
+ if (!subSchema) return null;
3923
4128
  return jsx(EditComponent, {
3924
4129
  id: `${id}[${key}]`,
3925
4130
  schema: subSchema,
@@ -3989,9 +4194,9 @@ function IAttachment({
3989
4194
  }, 1), jsx("td", {
3990
4195
  children: jsx(EditableField, {
3991
4196
  field: key,
3992
- value: values[key],
4197
+ value: values.file,
3993
4198
  ns: "guillotina.behaviors.attachment.IAttachment",
3994
- schema: properties[key],
4199
+ schema: properties.file,
3995
4200
  modifyContent: modifyContent && ['file'].includes(key)
3996
4201
  })
3997
4202
  }, 2)]
@@ -4024,6 +4229,11 @@ function IMultiAttachment({
4024
4229
 
4025
4230
  setLoading(true);
4026
4231
  setError(undefined);
4232
+
4233
+ if (!file) {
4234
+ return;
4235
+ }
4236
+
4027
4237
  const endpoint = `${Ctx.path}@upload/files/${fileKey}`;
4028
4238
  const req = await Ctx.client.upload(endpoint, file);
4029
4239
 
@@ -4080,7 +4290,7 @@ function IMultiAttachment({
4080
4290
  field: `files/${key}`,
4081
4291
  value: values['files'][key],
4082
4292
  ns: "guillotina.behaviors.attachment.IMultiAttachment.files",
4083
- schema: properties['files']['additionalProperties'],
4293
+ schema: get(properties, 'files.additionalProperties', {}),
4084
4294
  modifyContent: false
4085
4295
  }), jsx("div", {
4086
4296
  className: "ml-5",
@@ -4158,6 +4368,11 @@ function IImageAttachment({
4158
4368
  ev.preventDefault();
4159
4369
  setLoading(true);
4160
4370
  setError(undefined);
4371
+
4372
+ if (!file) {
4373
+ return;
4374
+ }
4375
+
4161
4376
  const endpoint = `${Ctx.path}@upload/image`;
4162
4377
  const req = await Ctx.client.upload(endpoint, file);
4163
4378
 
@@ -4188,7 +4403,7 @@ function IImageAttachment({
4188
4403
  }
4189
4404
  }
4190
4405
 
4191
- setFile(undefined);
4406
+ setFile(null);
4192
4407
  setLoading(false);
4193
4408
  Ctx.flash(intl.formatMessage(genericFileMessages.image_uploaded), 'success');
4194
4409
  Ctx.refresh();
@@ -4287,7 +4502,7 @@ function IMultiImageAttachment({
4287
4502
  const intl = useIntl();
4288
4503
  const cfg = useConfig();
4289
4504
  const [fileKey, setFileKey] = useState('');
4290
- const [file, setFile] = useState(null);
4505
+ const [file, setFile] = useState(undefined);
4291
4506
  const [fileKeyToDelete, setFileKeyToDelete] = useState(undefined);
4292
4507
  const [loading, setLoading] = useState(false);
4293
4508
  const [error, setError] = useState(undefined);
@@ -4307,6 +4522,11 @@ function IMultiImageAttachment({
4307
4522
 
4308
4523
  setLoading(true);
4309
4524
  setError(undefined);
4525
+
4526
+ if (!file) {
4527
+ return;
4528
+ }
4529
+
4310
4530
  const endpoint = `${Ctx.path}@upload/images/${fileKey}`;
4311
4531
  const req = await Ctx.client.upload(endpoint, file);
4312
4532
 
@@ -4384,7 +4604,7 @@ function IMultiImageAttachment({
4384
4604
  field: `images/${key}`,
4385
4605
  value: values['images'][key],
4386
4606
  ns: "guillotina.contrib.image.behaviors.IMultiImageAttachment.images",
4387
- schema: properties['images']['additionalProperties'],
4607
+ schema: get(properties, 'images.additionalProperties', {}),
4388
4608
  modifyContent: false,
4389
4609
  required: false
4390
4610
  }), jsx("div", {
@@ -4500,7 +4720,7 @@ function IMultiImageOrderedAttachment({
4500
4720
  const intl = useIntl();
4501
4721
  const cfg = useConfig();
4502
4722
  const [sortedList, setSortedList] = useState(Object.keys(values['images']));
4503
- const [file, setFile] = useState(null);
4723
+ const [file, setFile] = useState(undefined);
4504
4724
  const [fileKeyToDelete, setFileKeyToDelete] = useState(undefined);
4505
4725
  const [loading, setLoading] = useState(false);
4506
4726
  const [error, setError] = useState(undefined);
@@ -4630,7 +4850,7 @@ function IMultiImageOrderedAttachment({
4630
4850
  field: `images/${key}`,
4631
4851
  value: values['images'][key],
4632
4852
  ns: "guillotina.contrib.image.behaviors.IMultiImageAttachment.images",
4633
- schema: properties['images']['additionalProperties'],
4853
+ schema: get(properties, 'images.additionalProperties', {}),
4634
4854
  modifyContent: false,
4635
4855
  required: false
4636
4856
  }), jsx("div", {
@@ -4680,140 +4900,6 @@ function IMultiImageOrderedAttachment({
4680
4900
  });
4681
4901
  }
4682
4902
 
4683
- const base = {
4684
- local: {
4685
- roleperm: {},
4686
- prinperm: {},
4687
- prinrole: {}
4688
- },
4689
- inherit: []
4690
- };
4691
- class Sharing {
4692
- constructor(element) {
4693
- this.local = void 0;
4694
- this.inherit = void 0;
4695
- Object.assign(this, element || base);
4696
- }
4697
-
4698
- get roles() {
4699
- return Object.keys(this.local.roleperm);
4700
- }
4701
-
4702
- getRole(role) {
4703
- return this.local.roleperm[role];
4704
- }
4705
-
4706
- get principals() {
4707
- return Object.keys(this.local.prinperm);
4708
- }
4709
-
4710
- getPrincipals(principal) {
4711
- return this.local.prinperm[principal];
4712
- }
4713
-
4714
- get prinrole() {
4715
- return Object.keys(this.local.prinrole);
4716
- }
4717
-
4718
- getPrinroles(role) {
4719
- return this.local.prinrole[role];
4720
- }
4721
-
4722
- }
4723
-
4724
- class ItemModel {
4725
- constructor(item, url = '') {
4726
- this.item = void 0;
4727
- this.url = void 0;
4728
- this.item = item;
4729
- this.url = url;
4730
- }
4731
-
4732
- get path() {
4733
- // Compat
4734
- const item = this.item['@id'] ? this.item['@id'] : this.item['@absolute_url'];
4735
- let path = item.split('//')[1].split('/').splice(1).join('/');
4736
- path = `/${path}/`;
4737
-
4738
- if (this.url.length > 0) {
4739
- if (this.url.startsWith('/')) {
4740
- path = path.replace(this.url.substring(1), '');
4741
- } else {
4742
- path = path.replace(this.url, '');
4743
- }
4744
- }
4745
-
4746
- return path;
4747
- }
4748
-
4749
- get name() {
4750
- return this.item.title || this.item['@name'];
4751
- }
4752
-
4753
- get icon() {
4754
- // eslint-disable-next-line
4755
- const cfg = useConfig();
4756
-
4757
- if (cfg.icons && cfg.icons[this.type]) {
4758
- return cfg.icons[this.type];
4759
- }
4760
-
4761
- switch (this.type) {
4762
- case 'GroupManager':
4763
- return 'fas fa-users-cog';
4764
-
4765
- case 'UserManager':
4766
- return 'fas fa-user-cog';
4767
-
4768
- case 'User':
4769
- return 'fas fa-user';
4770
-
4771
- case 'Group':
4772
- return 'fas fa-users';
4773
-
4774
- case 'Folder':
4775
- return 'fas fa-folder';
4776
-
4777
- default:
4778
- return 'fas fa-file';
4779
- }
4780
- }
4781
-
4782
- get fullPath() {
4783
- return this.url + this.item.id;
4784
- }
4785
-
4786
- get id() {
4787
- if (this.item.id) {
4788
- return this.item.id;
4789
- }
4790
-
4791
- const id = this.item['@id'].split('&')[0].split('/');
4792
- return id[id.length - 1];
4793
- }
4794
-
4795
- get uid() {
4796
- return this.item['@uid'];
4797
- }
4798
-
4799
- get type() {
4800
- return this.item['@type'] || this.item.type_name;
4801
- }
4802
-
4803
- get title() {
4804
- return this.item.title;
4805
- }
4806
-
4807
- get created() {
4808
- return this.item.creation_date ? formatDate(this.item.creation_date) : '';
4809
- }
4810
-
4811
- get updated() {
4812
- return this.item.modification_date ? formatDate(this.item.modification_date) : '';
4813
- }
4814
-
4815
- }
4816
-
4817
4903
  const messages$1 = defineMessages({
4818
4904
  status_changed_ok: {
4819
4905
  id: "status_changed_ok",
@@ -4872,10 +4958,9 @@ function IWorkflow() {
4872
4958
  } = useCrudContext();
4873
4959
  const modifyContent = Ctx.hasPerm('guillotina.ModifyContent');
4874
4960
  const [definition, setDefinition] = useState(undefined);
4875
- const [workflowAction, setWorkflowAction] = useState(null);
4876
- const model = new ItemModel(Ctx.context);
4961
+ const [workflowAction, setWorkflowAction] = useState(undefined);
4877
4962
  const vocabulary = useVocabulary('workflow_states');
4878
- const currentState = model.item['guillotina.contrib.workflows.interfaces.IWorkflowBehavior']['review_state'];
4963
+ const currentState = Ctx.context['guillotina.contrib.workflows.interfaces.IWorkflowBehavior']['review_state'];
4879
4964
 
4880
4965
  async function loadDefinition() {
4881
4966
  const response = await Ctx.client.get(`${Ctx.path}/@workflow`);
@@ -4903,23 +4988,25 @@ function IWorkflow() {
4903
4988
  }
4904
4989
 
4905
4990
  Ctx.refresh();
4906
- setWorkflowAction(null);
4991
+ setWorkflowAction(undefined);
4907
4992
  };
4908
4993
 
4909
4994
  const getStateTitle = () => {
4910
- var _vocabulary$data, _vocabulary$data$item;
4995
+ var _vocabulary$data$item, _vocabulary$data;
4996
+
4997
+ if (((_vocabulary$data$item = (_vocabulary$data = vocabulary.data) == null ? void 0 : _vocabulary$data.items) != null ? _vocabulary$data$item : []).length > 0) {
4998
+ var _vocabulary$data2;
4911
4999
 
4912
- if (((_vocabulary$data = vocabulary.data) == null ? void 0 : (_vocabulary$data$item = _vocabulary$data.items) == null ? void 0 : _vocabulary$data$item.length) > 0) {
4913
- const vocabularyValue = vocabulary.data.items.find(item => item.token === currentState);
5000
+ const vocabularyValue = vocabulary == null ? void 0 : (_vocabulary$data2 = vocabulary.data) == null ? void 0 : _vocabulary$data2.items.find(item => item.token === currentState);
4914
5001
 
4915
5002
  if (vocabularyValue) {
4916
- const translatedValue = get$1(vocabularyValue, `title.translated_title.${intl.locale}`, null);
5003
+ const translatedValue = get(vocabularyValue, `title.translated_title.${intl.locale}`, null);
4917
5004
 
4918
5005
  if (translatedValue !== null) {
4919
5006
  return translatedValue;
4920
5007
  }
4921
5008
 
4922
- const titleValue = get$1(vocabularyValue, `title.title.${intl.locale}`, null);
5009
+ const titleValue = get(vocabularyValue, `title.title.${intl.locale}`, null);
4923
5010
 
4924
5011
  if (titleValue !== null) {
4925
5012
  return titleValue;
@@ -4934,7 +5021,7 @@ function IWorkflow() {
4934
5021
  return jsxs(Fragment, {
4935
5022
  children: [workflowAction && jsx(Confirm, {
4936
5023
  loading: loading,
4937
- onCancel: () => setWorkflowAction(null),
5024
+ onCancel: () => setWorkflowAction(undefined),
4938
5025
  onConfirm: doWorkflowAction,
4939
5026
  message: intl.formatMessage(messages$1.confirm_message, {
4940
5027
  title: Ctx.context.title || Ctx.context['@name']
@@ -4957,7 +5044,7 @@ function IWorkflow() {
4957
5044
  return jsx("button", {
4958
5045
  className: "button mr-4",
4959
5046
  onClick: () => setWorkflowAction(transition['@id'].split('@workflow')[1].slice(1)),
4960
- children: get$1(transition, `metadata.translated_title.${intl.locale}`, transition.title)
5047
+ children: get(transition, `metadata.translated_title.${intl.locale}`, transition.title)
4961
5048
  }, transition['@id']);
4962
5049
  })]
4963
5050
  })]
@@ -4981,14 +5068,17 @@ function PanelActions() {
4981
5068
 
4982
5069
  return jsx(Fragment$1, {
4983
5070
  children: Object.keys(ACTIONS_OBJECT).map(actionKey => {
4984
- if (hasPerm(ACTIONS_OBJECT[actionKey].perms)) {
5071
+ const actionKeyTyped = actionKey;
5072
+ const actionObject = ACTIONS_OBJECT[actionKeyTyped];
5073
+
5074
+ if (hasPerm(actionObject.perms)) {
4985
5075
  return jsx("button", {
4986
5076
  className: "button mr-4",
4987
5077
  onClick: () => {
4988
- onAction(actionKey);
5078
+ onAction(actionKeyTyped);
4989
5079
  },
4990
- children: ACTIONS_OBJECT[actionKey].text
4991
- }, `panel_action_${ACTIONS_OBJECT[actionKey].text}`);
5080
+ children: actionObject.text
5081
+ }, `panel_action_${actionObject.text}`);
4992
5082
  }
4993
5083
  })
4994
5084
  });
@@ -5130,8 +5220,9 @@ const prepareData = result => {
5130
5220
  };
5131
5221
 
5132
5222
  const arrayToObject = array => array.reduce((obj, item) => {
5133
- obj[item.id] = item;
5134
- return obj;
5223
+ return _extends({}, obj, {
5224
+ [item.id]: item
5225
+ });
5135
5226
  }, {});
5136
5227
 
5137
5228
  function PanelBehaviors() {
@@ -5266,8 +5357,9 @@ function ItemsActionsProvider({
5266
5357
 
5267
5358
  function onSelectAllItems(checked) {
5268
5359
  setSelected(items.reduce((obj, item) => {
5269
- obj[`${item.path}/${item.id}`] = checked;
5270
- return obj;
5360
+ return _extends({}, obj, {
5361
+ [`${item.path}/${item.id}`]: checked
5362
+ });
5271
5363
  }, {
5272
5364
  all: checked
5273
5365
  }));
@@ -5296,18 +5388,39 @@ function ItemsActionsProvider({
5296
5388
  children: children
5297
5389
  });
5298
5390
  }
5391
+
5392
+ const useItemsActions = () => {
5393
+ const {
5394
+ onAction,
5395
+ onSelectOneItem,
5396
+ onSelectAllItems,
5397
+ selected
5398
+ } = useContext(ItemsActionsCtx);
5399
+
5400
+ if (!onAction || !onSelectOneItem || !onSelectAllItems || !selected) {
5401
+ throw new Error('useItemsActions must be used inside ItemsActionsProvider');
5402
+ }
5403
+
5404
+ return {
5405
+ onAction,
5406
+ onSelectOneItem,
5407
+ onSelectAllItems,
5408
+ selected
5409
+ };
5410
+ };
5299
5411
  /**
5300
5412
  * Checkbox component without props that consume the ItemsActionsContext
5301
5413
  * and it select/unselect all items of the page.
5302
5414
  */
5303
5415
 
5416
+
5304
5417
  function AllItemsCheckbox({
5305
5418
  dataTest
5306
5419
  }) {
5307
5420
  const {
5308
5421
  onSelectAllItems,
5309
5422
  selected
5310
- } = useContext(ItemsActionsCtx);
5423
+ } = useItemsActions();
5311
5424
  return jsx(Checkbox, {
5312
5425
  onChange: onSelectAllItems,
5313
5426
  checked: selected.all,
@@ -5321,7 +5434,7 @@ function ItemCheckbox({
5321
5434
  const {
5322
5435
  selected,
5323
5436
  onSelectOneItem
5324
- } = useContext(ItemsActionsCtx);
5437
+ } = useItemsActions();
5325
5438
  const absId = `${item.path}/${item.id}`;
5326
5439
  const value = selected[absId];
5327
5440
  return jsx(Checkbox, {
@@ -5341,7 +5454,7 @@ function ItemsActionsDropdown() {
5341
5454
  const {
5342
5455
  selected,
5343
5456
  onAction
5344
- } = useContext(ItemsActionsCtx);
5457
+ } = useItemsActions();
5345
5458
  const disabled = Object.values(selected).every(v => !v);
5346
5459
  const options = Object.keys(ACTIONS_OBJECT).map(action => ({
5347
5460
  text: ACTIONS_OBJECT[action].text,
@@ -5367,77 +5480,216 @@ function ItemsActionsDropdown() {
5367
5480
  });
5368
5481
  }
5369
5482
 
5370
- function Pagination({
5371
- current,
5372
- total,
5373
- doPaginate,
5374
- pager
5375
- }) {
5376
- const intl = useIntl();
5377
- const maxPages = Math.ceil(total / pager);
5483
+ function Pagination({
5484
+ current,
5485
+ total,
5486
+ doPaginate,
5487
+ pager
5488
+ }) {
5489
+ const intl = useIntl();
5490
+ const maxPages = Math.ceil(total / pager);
5491
+
5492
+ if (maxPages <= 1) {
5493
+ return null;
5494
+ }
5495
+
5496
+ return jsxs("div", {
5497
+ children: [jsx("p", {
5498
+ className: "level-right has-text-grey is-size-7",
5499
+ children: jsx("span", {
5500
+ children: intl.formatMessage({
5501
+ id: "pagination",
5502
+ defaultMessage: [{
5503
+ "type": 1,
5504
+ "value": "currentPage"
5505
+ }, {
5506
+ "type": 0,
5507
+ "value": " / "
5508
+ }, {
5509
+ "type": 1,
5510
+ "value": "totalPages"
5511
+ }, {
5512
+ "type": 0,
5513
+ "value": " of "
5514
+ }, {
5515
+ "type": 1,
5516
+ "value": "totalItems"
5517
+ }, {
5518
+ "type": 0,
5519
+ "value": " items"
5520
+ }]
5521
+ }, {
5522
+ currentPage: current + 1,
5523
+ totalPages: maxPages,
5524
+ totalItems: total
5525
+ })
5526
+ })
5527
+ }), jsxs("nav", {
5528
+ className: "pagination is-size-7",
5529
+ role: "navigation",
5530
+ "aria-label": "pagination",
5531
+ children: [jsx("a", {
5532
+ className: "pagination-previous is-small",
5533
+ // disabled={current === 0}
5534
+ onClick: () => current > 0 ? doPaginate(current - 1) : null,
5535
+ children: jsx("span", {
5536
+ className: "icon",
5537
+ children: jsx("i", {
5538
+ className: "fas fa-arrow-left"
5539
+ })
5540
+ })
5541
+ }), jsx("a", {
5542
+ className: "pagination-next is-small",
5543
+ // disabled={current >= maxPages - 1}
5544
+ onClick: () => doPaginate(current + 1),
5545
+ children: jsx("span", {
5546
+ className: "icon",
5547
+ children: jsx("i", {
5548
+ className: "fas fa-arrow-right"
5549
+ })
5550
+ })
5551
+ })]
5552
+ })]
5553
+ });
5554
+ }
5555
+
5556
+ const base = {
5557
+ local: {
5558
+ roleperm: {},
5559
+ prinperm: {},
5560
+ prinrole: {}
5561
+ },
5562
+ inherit: []
5563
+ };
5564
+ class Sharing {
5565
+ constructor(element) {
5566
+ this.local = void 0;
5567
+ this.inherit = void 0;
5568
+
5569
+ if (element === undefined) {
5570
+ throw new Error('Sharing element is undefined');
5571
+ }
5572
+
5573
+ this.local = element.local || base.local;
5574
+ this.inherit = element.inherit || base.inherit;
5575
+ }
5576
+
5577
+ get roles() {
5578
+ return Object.keys(this.local.roleperm);
5579
+ }
5580
+
5581
+ getRole(role) {
5582
+ return this.local.roleperm[role];
5583
+ }
5584
+
5585
+ get principals() {
5586
+ return Object.keys(this.local.prinperm);
5587
+ }
5588
+
5589
+ getPrincipals(principal) {
5590
+ return this.local.prinperm[principal];
5591
+ }
5592
+
5593
+ get prinrole() {
5594
+ return Object.keys(this.local.prinrole);
5595
+ }
5596
+
5597
+ getPrinroles(role) {
5598
+ return this.local.prinrole[role];
5599
+ }
5600
+
5601
+ }
5602
+
5603
+ class ItemModel {
5604
+ constructor(item, url = '') {
5605
+ this.item = void 0;
5606
+ this.url = void 0;
5607
+ this.item = item;
5608
+ this.url = url;
5609
+ }
5610
+
5611
+ get path() {
5612
+ // Compat
5613
+ const item = this.item['@id'] ? this.item['@id'] : this.item['@absolute_url'];
5614
+ let path = item.split('//')[1].split('/').splice(1).join('/');
5615
+ path = `/${path}/`;
5616
+
5617
+ if (this.url.length > 0) {
5618
+ if (this.url.startsWith('/')) {
5619
+ path = path.replace(this.url.substring(1), '');
5620
+ } else {
5621
+ path = path.replace(this.url, '');
5622
+ }
5623
+ }
5624
+
5625
+ return path;
5626
+ }
5627
+
5628
+ get name() {
5629
+ return this.item.title || this.item['@name'];
5630
+ }
5631
+
5632
+ get icon() {
5633
+ const cfg = useConfig();
5634
+
5635
+ if (cfg.icons && cfg.icons[this.type]) {
5636
+ return cfg.icons[this.type];
5637
+ }
5638
+
5639
+ switch (this.type) {
5640
+ case 'GroupManager':
5641
+ return 'fas fa-users-cog';
5642
+
5643
+ case 'UserManager':
5644
+ return 'fas fa-user-cog';
5645
+
5646
+ case 'User':
5647
+ return 'fas fa-user';
5648
+
5649
+ case 'Group':
5650
+ return 'fas fa-users';
5651
+
5652
+ case 'Folder':
5653
+ return 'fas fa-folder';
5654
+
5655
+ default:
5656
+ return 'fas fa-file';
5657
+ }
5658
+ }
5659
+
5660
+ get fullPath() {
5661
+ return this.url + this.id;
5662
+ }
5663
+
5664
+ get id() {
5665
+ if ('id' in this.item) {
5666
+ return this.item.id;
5667
+ }
5668
+
5669
+ const id = this.item['@id'].split('&')[0].split('/');
5670
+ return id[id.length - 1];
5671
+ }
5672
+
5673
+ get uid() {
5674
+ return this.item['@uid'];
5675
+ }
5378
5676
 
5379
- if (maxPages <= 1) {
5380
- return null;
5677
+ get type() {
5678
+ return this.item['@type'] || this.item.type_name;
5679
+ }
5680
+
5681
+ get title() {
5682
+ return this.item.title;
5683
+ }
5684
+
5685
+ get created() {
5686
+ return this.item.creation_date ? formatDate(this.item.creation_date) : '';
5687
+ }
5688
+
5689
+ get updated() {
5690
+ return this.item.modification_date ? formatDate(this.item.modification_date) : '';
5381
5691
  }
5382
5692
 
5383
- return jsxs("div", {
5384
- children: [jsx("p", {
5385
- className: "level-right has-text-grey is-size-7",
5386
- children: jsx("span", {
5387
- children: intl.formatMessage({
5388
- id: "pagination",
5389
- defaultMessage: [{
5390
- "type": 1,
5391
- "value": "currentPage"
5392
- }, {
5393
- "type": 0,
5394
- "value": " / "
5395
- }, {
5396
- "type": 1,
5397
- "value": "totalPages"
5398
- }, {
5399
- "type": 0,
5400
- "value": " of "
5401
- }, {
5402
- "type": 1,
5403
- "value": "totalItems"
5404
- }, {
5405
- "type": 0,
5406
- "value": " items"
5407
- }]
5408
- }, {
5409
- currentPage: current + 1,
5410
- totalPages: maxPages,
5411
- totalItems: total
5412
- })
5413
- })
5414
- }), jsxs("nav", {
5415
- className: "pagination is-size-7",
5416
- role: "navigation",
5417
- "aria-label": "pagination",
5418
- children: [jsx("a", {
5419
- className: "pagination-previous is-small",
5420
- // disabled={current === 0}
5421
- onClick: () => current > 0 ? doPaginate(current - 1) : null,
5422
- children: jsx("span", {
5423
- className: "icon",
5424
- children: jsx("i", {
5425
- className: "fas fa-arrow-left"
5426
- })
5427
- })
5428
- }), jsx("a", {
5429
- className: "pagination-next is-small",
5430
- // disabled={current >= maxPages - 1}
5431
- onClick: () => doPaginate(current + 1),
5432
- children: jsx("span", {
5433
- className: "icon",
5434
- children: jsx("i", {
5435
- className: "fas fa-arrow-right"
5436
- })
5437
- })
5438
- })]
5439
- })]
5440
- });
5441
5693
  }
5442
5694
 
5443
5695
  function Item({
@@ -5558,11 +5810,11 @@ function SearchOptionsLabels({
5558
5810
  }) {
5559
5811
  const [location,, del] = useLocation();
5560
5812
  const [renderValue, setRenderValue] = useState(undefined);
5561
- const defaultRenderValue = location.get(query);
5813
+ const defaultRenderValue = location.get(query) || '';
5562
5814
  useEffect(() => {
5563
5815
  let value = defaultRenderValue;
5564
5816
 
5565
- if ((options != null ? options : []).length > 0) {
5817
+ if (options && (options != null ? options : []).length > 0) {
5566
5818
  const option = options.find(item => item.value === value);
5567
5819
 
5568
5820
  if (option) {
@@ -5600,14 +5852,16 @@ function SearchVocabularyLabels({
5600
5852
  const [location,, del] = useLocation();
5601
5853
  const [renderValue, setRenderValue] = useState(undefined);
5602
5854
  const vocabulary = useVocabulary(vocabularyName);
5603
- const defaultRenderValue = location.get(query);
5855
+ const defaultRenderValue = location.get(query) || '';
5604
5856
  useEffect(() => {
5605
5857
  var _vocabulary$data$item, _vocabulary$data;
5606
5858
 
5607
5859
  let value = defaultRenderValue;
5608
5860
 
5609
5861
  if (((_vocabulary$data$item = vocabulary == null ? void 0 : (_vocabulary$data = vocabulary.data) == null ? void 0 : _vocabulary$data.items) != null ? _vocabulary$data$item : []).length > 0) {
5610
- const vocabularyValue = vocabulary.data.items.find(item => item.token === value);
5862
+ var _vocabulary$data2;
5863
+
5864
+ const vocabularyValue = vocabulary == null ? void 0 : (_vocabulary$data2 = vocabulary.data) == null ? void 0 : _vocabulary$data2.items.find(item => item.token === value);
5611
5865
 
5612
5866
  if (vocabularyValue) {
5613
5867
  value = vocabularyValue.title;
@@ -5637,7 +5891,7 @@ function SearchVocabularyLabels({
5637
5891
  return null;
5638
5892
  }
5639
5893
 
5640
- const initialState$2 = {
5894
+ const initialState$3 = {
5641
5895
  page: 0,
5642
5896
  items: [],
5643
5897
  loading: true,
@@ -5651,7 +5905,7 @@ function PanelItems() {
5651
5905
  } = useConfig();
5652
5906
  const intl = useIntl();
5653
5907
  const Ctx = useTraversal();
5654
- const [state, setState] = useSetState(initialState$2);
5908
+ const [state, setState] = useSetState(initialState$3);
5655
5909
  const {
5656
5910
  items,
5657
5911
  loading,
@@ -5666,7 +5920,7 @@ function PanelItems() {
5666
5920
  let page;
5667
5921
 
5668
5922
  try {
5669
- page = parseInt(location.get('page')) || 0;
5923
+ page = parseInt(location.get('page') || '0');
5670
5924
  } catch (_unused) {
5671
5925
  page = 0;
5672
5926
  }
@@ -5713,7 +5967,7 @@ function PanelItems() {
5713
5967
  let resultQueryParams = [];
5714
5968
  const resultDynamicLocation = [];
5715
5969
  filterSchema.forEach(filter => {
5716
- const itemParam = location.get(filter.attribute_key);
5970
+ const itemParam = location.get(filter.attribute_key) || '';
5717
5971
  resultDynamicLocation.push(itemParam);
5718
5972
 
5719
5973
  if (itemParam) {
@@ -5725,7 +5979,7 @@ function PanelItems() {
5725
5979
  const controller = new AbortController();
5726
5980
  if (Ctx.state.loading) return;
5727
5981
 
5728
- (async () => {
5982
+ const getData = async () => {
5729
5983
  setState({
5730
5984
  loading: true,
5731
5985
  total: Ctx.context.length
@@ -5736,14 +5990,11 @@ function PanelItems() {
5736
5990
  const fnName = get('searchEngineQueryParamsFunction', SearchEngine);
5737
5991
 
5738
5992
  if (sortParsed === undefined) {
5739
- const defaultSortValue = Ctx.registry.getDefaultSortValue(Ctx.context['@type'], {
5740
- key: 'id',
5741
- direction: 'des'
5742
- });
5993
+ const defaultSortValue = Ctx.registry.getDefaultSortValue(Ctx.context['@type']);
5743
5994
  sortParsed = parser(`_sort_${defaultSortValue.direction}=${defaultSortValue.key}`);
5744
5995
  }
5745
5996
 
5746
- const qsParsed = Ctx.client[fnName]({
5997
+ const qsParsed = Ctx.client.getQueryParamsSearchFunction(fnName)({
5747
5998
  path: Ctx.path,
5748
5999
  start: page * PageSize,
5749
6000
  pageSize: PageSize
@@ -5763,16 +6014,15 @@ function PanelItems() {
5763
6014
  const {
5764
6015
  signal
5765
6016
  } = controller;
5766
- const data = await Ctx.client.search(Ctx.path, qs, false, false, {
5767
- signal
5768
- });
6017
+ const data = await Ctx.client.search(Ctx.path, qs, false, false, signal);
5769
6018
  setState({
5770
- items: data.member,
6019
+ items: data.items,
5771
6020
  loading: false,
5772
6021
  total: data.items_count
5773
6022
  });
5774
- })();
6023
+ };
5775
6024
 
6025
+ getData();
5776
6026
  return () => {
5777
6027
  controller.abort();
5778
6028
  };
@@ -5817,12 +6067,14 @@ function PanelItems() {
5817
6067
  var _filter$values;
5818
6068
 
5819
6069
  if (filter.type === 'select' && ((_filter$values = filter.values) != null ? _filter$values : []).length > 0) {
6070
+ var _filter$values2;
6071
+
5820
6072
  return jsx(Select, {
5821
6073
  id: filter.attribute_key,
5822
6074
  placeholder: filter.label,
5823
6075
  appendDefault: true,
5824
6076
  classWrap: "is-size-7 is-fullwidth",
5825
- options: filter.values,
6077
+ options: (_filter$values2 = filter.values) != null ? _filter$values2 : [],
5826
6078
  value: location.get(filter.attribute_key) || '',
5827
6079
  dataTest: `filterInput${filter.attribute_key}`,
5828
6080
  onChange: value => {
@@ -5895,7 +6147,7 @@ function PanelItems() {
5895
6147
  const filterData = location.get(filter.attribute_key);
5896
6148
 
5897
6149
  if (filterData) {
5898
- var _filter$values2;
6150
+ var _filter$values3;
5899
6151
 
5900
6152
  if (filter.type === 'select' && filter.vocabulary) {
5901
6153
  return jsx("div", {
@@ -5904,7 +6156,7 @@ function PanelItems() {
5904
6156
  vocabularyName: filter == null ? void 0 : filter.vocabulary
5905
6157
  })
5906
6158
  }, filter.attribute_key);
5907
- } else if (filter.type === 'select' && ((_filter$values2 = filter.values) != null ? _filter$values2 : []).length > 0) {
6159
+ } else if (filter.type === 'select' && ((_filter$values3 = filter.values) != null ? _filter$values3 : []).length > 0) {
5908
6160
  return jsx("div", {
5909
6161
  children: jsx(SearchOptionsLabels, {
5910
6162
  query: filter.attribute_key,
@@ -5947,7 +6199,7 @@ function PanelItems() {
5947
6199
  className: "has-text-info is-flex is-align-items-center",
5948
6200
  children: [jsx("span", {
5949
6201
  children: column.label
5950
- }), getIcon(column.key, column.isSortable)]
6202
+ }), getIcon(column.key, !!column.isSortable)]
5951
6203
  })
5952
6204
  }, `table-col-${column.label}`)), jsx("th", {
5953
6205
  children: "\u00A0"
@@ -5956,7 +6208,7 @@ function PanelItems() {
5956
6208
  }), jsxs("tbody", {
5957
6209
  children: [items && items.map(item => jsx(RItem, {
5958
6210
  item: item,
5959
- search: search,
6211
+ search: search != null ? search : '',
5960
6212
  columns: columns
5961
6213
  }, item['@uid'])), items && items.length === 0 && jsx("tr", {
5962
6214
  children: jsx("td", {
@@ -5982,17 +6234,19 @@ function BehaviorsView({
5982
6234
  context,
5983
6235
  schema
5984
6236
  }) {
6237
+ var _context$__behaviors_;
6238
+
5985
6239
  const Ctx = useTraversal();
5986
6240
  const {
5987
6241
  getBehavior
5988
6242
  } = Ctx.registry;
5989
- const behaviors = [].concat(context.__behaviors__, context['@static_behaviors']);
6243
+ const behaviors = [...((_context$__behaviors_ = context.__behaviors__) != null ? _context$__behaviors_ : []), ...Object(context['@static_behaviors'])];
5990
6244
 
5991
- const GetBehavior = b => {
5992
- const Cls = getBehavior(b, BehaviorNotImplemented);
6245
+ const GetBehavior = behaviorName => {
6246
+ const Cls = getBehavior(behaviorName, BehaviorNotImplemented);
5993
6247
  return jsx(Cls, {
5994
- values: context[b],
5995
- properties: get$1(schema, ['definitions', b, 'properties'], {})
6248
+ values: context[behaviorName],
6249
+ properties: get(schema, ['definitions', behaviorName, 'properties'], {})
5996
6250
  });
5997
6251
  };
5998
6252
 
@@ -6069,10 +6323,14 @@ function PanelProperties() {
6069
6323
 
6070
6324
  const ignoreFields = Ctx.registry.getProperties(Ctx.context['@type']).ignoreField || cfg.properties_ignore_fields || _ignoreFields;
6071
6325
 
6072
- const properties = Object.keys((schema == null ? void 0 : (_schema$data = schema.data) == null ? void 0 : _schema$data.properties) || []).filter(key => !ignoreFields.includes(key)).map(key => ({
6073
- key,
6074
- value: schema.data.properties[key]
6075
- }));
6326
+ const properties = Object.keys((schema == null ? void 0 : (_schema$data = schema.data) == null ? void 0 : _schema$data.properties) || []).filter(key => !ignoreFields.includes(key)).map(key => {
6327
+ var _schema$data2;
6328
+
6329
+ return {
6330
+ key,
6331
+ value: schema == null ? void 0 : (_schema$data2 = schema.data) == null ? void 0 : _schema$data2.properties[key]
6332
+ };
6333
+ });
6076
6334
  useEffect(() => {
6077
6335
  async function getSchema() {
6078
6336
  if (!schema.loading && !schema.data && !schema.error) {
@@ -6080,7 +6338,7 @@ function PanelProperties() {
6080
6338
  setSchema({
6081
6339
  loading: true
6082
6340
  });
6083
- const dataJson = await Ctx.client.getTypeSchema(Ctx.path, model.type);
6341
+ const dataJson = await Ctx.client.getTypeSchema(Ctx.path, Ctx.context.type_name);
6084
6342
  setSchema({
6085
6343
  loading: false,
6086
6344
  data: dataJson
@@ -6145,7 +6403,7 @@ function PanelProperties() {
6145
6403
  }), jsx("td", {
6146
6404
  children: jsx(EditableField, {
6147
6405
  field: prop,
6148
- value: Ctx.context[prop],
6406
+ value: get(Ctx.context, prop, ''),
6149
6407
  modifyContent: false
6150
6408
  })
6151
6409
  })]
@@ -6171,7 +6429,7 @@ function PanelProperties() {
6171
6429
  key,
6172
6430
  value
6173
6431
  }) => {
6174
- var _schema$data$required, _schema$data2;
6432
+ var _schema$data$required, _schema$data3;
6175
6433
 
6176
6434
  return jsxs("tr", {
6177
6435
  children: [jsx("td", {
@@ -6182,10 +6440,10 @@ function PanelProperties() {
6182
6440
  }), jsx("td", {
6183
6441
  children: jsx(EditableField, {
6184
6442
  field: key,
6185
- value: Ctx.context[key],
6443
+ value: get(Ctx.context, key, ''),
6186
6444
  schema: value,
6187
6445
  modifyContent: modifyContent,
6188
- required: ((_schema$data$required = (_schema$data2 = schema.data) == null ? void 0 : _schema$data2.required) != null ? _schema$data$required : []).includes(key)
6446
+ required: ((_schema$data$required = (_schema$data3 = schema.data) == null ? void 0 : _schema$data3.required) != null ? _schema$data$required : []).includes(key)
6189
6447
  })
6190
6448
  })]
6191
6449
  }, 'prop' + key);
@@ -6219,12 +6477,6 @@ function PermissionPrinperm({
6219
6477
  error: undefined
6220
6478
  });
6221
6479
 
6222
- const getMultiples = (field, setter) => values => {
6223
- setter({
6224
- [field]: values
6225
- });
6226
- };
6227
-
6228
6480
  const savePermission = async () => {
6229
6481
  if (!state.principal || !state.setting || state.permission.length === 0) {
6230
6482
  setState({
@@ -6268,7 +6520,7 @@ function PermissionPrinperm({
6268
6520
  children: intl.formatMessage(genericMessages.select_principal)
6269
6521
  }), jsx(Select, {
6270
6522
  appendDefault: true,
6271
- options: principals,
6523
+ options: principals != null ? principals : [],
6272
6524
  onChange: value => setState({
6273
6525
  principal: value
6274
6526
  }),
@@ -6280,8 +6532,12 @@ function PermissionPrinperm({
6280
6532
  className: "label",
6281
6533
  children: intl.formatMessage(genericMessages.select_permissions)
6282
6534
  }), jsx(Select, {
6283
- options: permissions,
6284
- onChange: getMultiples('permission', setState),
6535
+ options: permissions != null ? permissions : [],
6536
+ onChange: values => {
6537
+ setState({
6538
+ permission: values
6539
+ });
6540
+ },
6285
6541
  size: 5,
6286
6542
  multiple: true,
6287
6543
  dataTest: "selectPermissionsTest"
@@ -6328,12 +6584,6 @@ function PermissionPrinrole({
6328
6584
  error: undefined
6329
6585
  });
6330
6586
 
6331
- const getMultiples = (field, setter) => values => {
6332
- setter({
6333
- [field]: values
6334
- });
6335
- };
6336
-
6337
6587
  const savePermission = async () => {
6338
6588
  if (!state.principal || !state.setting || state.roles.length === 0) {
6339
6589
  setState({
@@ -6377,7 +6627,7 @@ function PermissionPrinrole({
6377
6627
  children: intl.formatMessage(genericMessages.select_principal)
6378
6628
  }), jsx(Select, {
6379
6629
  appendDefault: true,
6380
- options: principals,
6630
+ options: principals != null ? principals : [],
6381
6631
  onChange: value => setState({
6382
6632
  principal: value
6383
6633
  }),
@@ -6390,7 +6640,11 @@ function PermissionPrinrole({
6390
6640
  children: intl.formatMessage(genericMessages.select_role)
6391
6641
  }), jsx(Select, {
6392
6642
  options: roles,
6393
- onChange: getMultiples('roles', setState),
6643
+ onChange: values => {
6644
+ setState({
6645
+ roles: values
6646
+ });
6647
+ },
6394
6648
  size: 5,
6395
6649
  multiple: true,
6396
6650
  dataTest: "selectRoleTest"
@@ -6437,12 +6691,6 @@ function PermissionRoleperm({
6437
6691
  error: undefined
6438
6692
  });
6439
6693
 
6440
- const getMultiples = (field, setter) => values => {
6441
- setter({
6442
- [field]: values
6443
- });
6444
- };
6445
-
6446
6694
  const savePermission = async () => {
6447
6695
  if (!state.role || !state.setting || state.permission.length === 0) {
6448
6696
  setState({
@@ -6498,8 +6746,12 @@ function PermissionRoleperm({
6498
6746
  className: "label",
6499
6747
  children: intl.formatMessage(genericMessages.select_permissions)
6500
6748
  }), jsx(Select, {
6501
- options: permissions,
6502
- onChange: getMultiples('permission', setState),
6749
+ options: permissions != null ? permissions : [],
6750
+ onChange: values => {
6751
+ setState({
6752
+ permission: values
6753
+ });
6754
+ },
6503
6755
  dataTest: "selectPermissionsTest",
6504
6756
  size: 5,
6505
6757
  multiple: true
@@ -6625,7 +6877,18 @@ function PanelPermissions() {
6625
6877
  useEffect(() => {
6626
6878
  get('@sharing');
6627
6879
  }, [reset]);
6628
- const perms = new Sharing(result);
6880
+ const perms = useMemo(() => {
6881
+ if (result) {
6882
+ return new Sharing(result);
6883
+ }
6884
+
6885
+ return null;
6886
+ }, [result]);
6887
+
6888
+ if (perms === null) {
6889
+ return null;
6890
+ }
6891
+
6629
6892
  return jsxs("div", {
6630
6893
  className: "columns",
6631
6894
  children: [!loading && jsxs("div", {
@@ -6762,12 +7025,12 @@ function AddPermission({
6762
7025
  let roles = [];
6763
7026
  const principalsData = await Ctx.client.getPrincipals(Ctx.path);
6764
7027
  const groups = principalsData.groups.map(group => ({
6765
- text: group.id,
6766
- value: group.id
7028
+ text: group['@name'],
7029
+ value: group['@name']
6767
7030
  }));
6768
7031
  const users = principalsData.users.map(user => ({
6769
- text: user.fullname || user.id,
6770
- value: user.id
7032
+ text: user.fullname || user['@name'],
7033
+ value: user['@name']
6771
7034
  }));
6772
7035
  principals = [...groups, ...users];
6773
7036
  const req = await Ctx.client.getRoles(Ctx.path);
@@ -6820,14 +7083,6 @@ const prepareAvailable = (items, already, title) => {
6820
7083
  text: `Add ${title}`
6821
7084
  };
6822
7085
  if (items.length === 0) return [];
6823
-
6824
- if (items[0] && typeof items[0] === 'string') {
6825
- return [def].concat(items.map(x => ({
6826
- value: x,
6827
- text: x
6828
- }))).filter(item => !already.includes(item.value));
6829
- }
6830
-
6831
7086
  return [def].concat(items).filter(item => !already.includes(item.value));
6832
7087
  };
6833
7088
 
@@ -6839,7 +7094,7 @@ function TagsWidget({
6839
7094
  onChange,
6840
7095
  loading
6841
7096
  }) {
6842
- const selectRef = useRef();
7097
+ const selectRef = useRef(null);
6843
7098
  const [result, setResult] = useState(items);
6844
7099
  const availableData = prepareAvailable(available || [], result, title);
6845
7100
 
@@ -6877,7 +7132,7 @@ function TagsWidget({
6877
7132
  marginBottom: '20px'
6878
7133
  },
6879
7134
  children: noData
6880
- }), available.length > 1 && jsx("li", {
7135
+ }), (available != null ? available : []).length > 1 && jsx("li", {
6881
7136
  className: "widget-list-add select is-small",
6882
7137
  children: jsx(Select, {
6883
7138
  options: availableData,
@@ -6895,12 +7150,12 @@ function TagsWidget({
6895
7150
  });
6896
7151
  }
6897
7152
 
6898
- const initialState$3 = {
6899
- types: undefined
7153
+ const initialState$4 = {
7154
+ types: []
6900
7155
  };
6901
7156
  function CreateButton() {
6902
7157
  const intl = useIntl();
6903
- const [state, setState] = useSetState(initialState$3);
7158
+ const [state, setState] = useSetState(initialState$4);
6904
7159
  const Ctx = useTraversal();
6905
7160
  const Config = useConfig();
6906
7161
  useEffect(() => {
@@ -6960,11 +7215,11 @@ function ContextToolbar({
6960
7215
  AddButton
6961
7216
  }) {
6962
7217
  const intl = useIntl();
6963
- const [state, setState] = useSetState(initialState$3);
7218
+ const [state, setState] = useSetState(initialState$4);
6964
7219
  const [location, setLocation, del] = useLocation();
6965
7220
  const traversal = useTraversal();
6966
7221
  const Config = useConfig();
6967
- const searchText = location.get('q');
7222
+ const searchText = location.get('q') || '';
6968
7223
  const [searchValue, setSearchValue] = useState(searchText || '');
6969
7224
  useEffect(() => {
6970
7225
  loadTypes();
@@ -6980,14 +7235,13 @@ function ContextToolbar({
6980
7235
  });
6981
7236
  }
6982
7237
 
6983
- const onSearchQuery = ev => {
6984
- const search = ev.target[0].value;
7238
+ const onSearchQuery = event => {
7239
+ event.preventDefault();
6985
7240
  setLocation({
6986
- q: search,
7241
+ q: event.currentTarget.elements.filterInput.value,
6987
7242
  tab: 'Items',
6988
7243
  page: 0
6989
7244
  });
6990
- ev.preventDefault();
6991
7245
  };
6992
7246
 
6993
7247
  const onSearchByType = typeText => {
@@ -7019,7 +7273,8 @@ function ContextToolbar({
7019
7273
  type: "text",
7020
7274
  className: "input is-size-7",
7021
7275
  placeholder: intl.formatMessage(genericMessages.search),
7022
- "data-test": "inputFilterTest"
7276
+ "data-test": "inputFilterTest",
7277
+ id: "filterInput"
7023
7278
  })
7024
7279
  }), jsx("div", {
7025
7280
  className: "control",
@@ -7044,7 +7299,7 @@ function ContextToolbar({
7044
7299
  text: item,
7045
7300
  value: item
7046
7301
  })),
7047
- onChange: onSearchByType
7302
+ onChange: value => onSearchByType(value)
7048
7303
  })
7049
7304
  }), traversal.hasPerm('guillotina.AddContent') && jsx("div", {
7050
7305
  className: "level-item",
@@ -7082,18 +7337,12 @@ function TabsPanel({
7082
7337
  fallback = FallbackTab
7083
7338
  }) {
7084
7339
  const [location, setLocation] = useLocation();
7085
-
7086
- if (location.get('tab')) {
7087
- currentTab = location.get('tab');
7088
- } else {
7089
- currentTab = currentTab || Object.keys(tabs)[0];
7090
- }
7340
+ currentTab = location.get('tab') || Object.keys(tabs)[0];
7091
7341
  /*if (!Object.keys(tabs).includes(currentTab)) {
7092
7342
  setLocation(defaultTab)
7093
7343
  currentTab = defaultTab
7094
7344
  }*/
7095
7345
 
7096
-
7097
7346
  const [current, setTab] = useState(currentTab);
7098
7347
  const CurrentComp = tabs[current] || fallback;
7099
7348
  React.useEffect(() => {
@@ -7153,14 +7402,14 @@ const tabsPermissions = {
7153
7402
  Behaviors: 'guillotina.ModifyContent',
7154
7403
  Permissions: 'guillotina.SeePermissions'
7155
7404
  };
7156
- function FolderCtx(props) {
7405
+ function FolderCtx() {
7157
7406
  const ctx = useTraversal();
7158
7407
  const calculated = ctx.filterTabs(tabs, tabsPermissions);
7159
- return jsx(TabsPanel, _extends({
7408
+ return jsx(TabsPanel, {
7160
7409
  tabs: calculated,
7161
7410
  currentTab: "Items",
7162
- rightToolbar: jsx(ContextToolbar, _extends({}, props))
7163
- }, props));
7411
+ rightToolbar: jsx(ContextToolbar, {})
7412
+ });
7164
7413
  }
7165
7414
 
7166
7415
  const tabs$1 = {
@@ -7174,21 +7423,22 @@ const tabsPermissions$1 = {
7174
7423
  Behaviors: 'guillotina.ModifyContent',
7175
7424
  Permissions: 'guillotina.SeePermissions'
7176
7425
  };
7177
- function ItemCtx(props) {
7426
+ function ItemCtx() {
7178
7427
  const ctx = useTraversal();
7179
7428
  const calculated = ctx.filterTabs(tabs$1, tabsPermissions$1);
7180
- return jsx(TabsPanel, _extends({
7429
+ return jsx(TabsPanel, {
7181
7430
  tabs: calculated,
7182
7431
  currentTab: "Properties"
7183
- }, props));
7432
+ });
7184
7433
  }
7185
7434
 
7186
7435
  function ApplicationCtx() {
7187
7436
  const intl = useIntl();
7188
- const context = useTraversal();
7437
+ const traversal = useTraversal();
7438
+ const appContext = traversal.state.context;
7189
7439
  const {
7190
7440
  databases
7191
- } = context.state.context;
7441
+ } = appContext;
7192
7442
  return jsxs(Fragment, {
7193
7443
  children: [jsx("h3", {
7194
7444
  children: intl.formatMessage({
@@ -7202,24 +7452,28 @@ function ApplicationCtx() {
7202
7452
  className: "container",
7203
7453
  children: [jsx(ItemTitle, {
7204
7454
  title: "Objects"
7205
- }), databases.map(db => jsx(Item, {
7206
- item: {
7207
- id: db,
7208
- path: `/${db}/`
7209
- },
7210
- icon: 'fas fa-database'
7211
- }, db))]
7455
+ }), jsx("table", {
7456
+ children: jsx("tbody", {
7457
+ children: databases.map(db => jsx(Item, {
7458
+ item: {
7459
+ id: db,
7460
+ path: `/${db}/`
7461
+ },
7462
+ icon: 'fas fa-database'
7463
+ }, db))
7464
+ })
7465
+ })]
7212
7466
  })]
7213
7467
  });
7214
7468
  }
7215
7469
  function DatabaseCtx() {
7216
- const context = useTraversal();
7470
+ const traversal = useTraversal();
7217
7471
  const {
7218
7472
  containers
7219
- } = context.state.context;
7473
+ } = traversal.state.context;
7220
7474
  const {
7221
7475
  path
7222
- } = context.state;
7476
+ } = traversal.state;
7223
7477
  return jsx(Fragment, {
7224
7478
  children: jsxs("div", {
7225
7479
  className: "container",
@@ -7477,18 +7731,17 @@ function UsersToolbar() {
7477
7731
  const [location, setLocation] = useLocation();
7478
7732
  const searchText = location.get('q');
7479
7733
 
7480
- const onSearchQuery = ev => {
7481
- const search = ev.target[0].value;
7734
+ const onSearchQuery = event => {
7735
+ event.preventDefault();
7482
7736
  setLocation({
7483
- q: search,
7737
+ q: event.currentTarget.elements.filterInput.value,
7484
7738
  page: 0
7485
7739
  });
7486
- ev.preventDefault();
7487
7740
  }; // cleanup form on state.search change
7488
7741
 
7489
7742
 
7490
7743
  useEffect(() => {
7491
- if (!searchText || searchText === '') {
7744
+ if (ref.current && (!searchText || searchText === '')) {
7492
7745
  ref.current.value = '';
7493
7746
  }
7494
7747
  }, [searchText]);
@@ -7508,7 +7761,8 @@ function UsersToolbar() {
7508
7761
  type: "text",
7509
7762
  className: "input is-size-7",
7510
7763
  placeholder: intl.formatMessage(genericMessages.search),
7511
- "data-test": "inputFilterTest"
7764
+ "data-test": "inputFilterTest",
7765
+ id: "filterInput"
7512
7766
  })
7513
7767
  }), jsx("div", {
7514
7768
  className: "control",
@@ -7538,12 +7792,12 @@ function UsersToolbar() {
7538
7792
  })]
7539
7793
  });
7540
7794
  }
7541
- function UsersCtx(props) {
7542
- return jsx(TabsPanel, _extends({
7795
+ function UsersCtx() {
7796
+ return jsx(TabsPanel, {
7543
7797
  tabs: tabs$3,
7544
7798
  currentTab: "Users",
7545
7799
  rightToolbar: jsx(UsersToolbar, {})
7546
- }, props));
7800
+ });
7547
7801
  }
7548
7802
  function UserCtx() {
7549
7803
  const intl = useIntl();
@@ -7556,9 +7810,10 @@ function UserCtx() {
7556
7810
  roles: [],
7557
7811
  groups: []
7558
7812
  });
7813
+ const userDataContext = Ctx.context;
7559
7814
  const fields = {
7560
7815
  user_groups: [],
7561
- user_roles: Ctx.context.user_roles
7816
+ user_roles: userDataContext.user_roles
7562
7817
  };
7563
7818
  const [remotes, updateRemote] = useRemoteField(fields);
7564
7819
  useEffect(() => {
@@ -7636,7 +7891,7 @@ function UserCtx() {
7636
7891
  "value": "Username"
7637
7892
  }]
7638
7893
  }), ":", ' ']
7639
- }), ' ', Ctx.context.username, " (", Ctx.context.email, ")"]
7894
+ }), ' ', userDataContext.username, " (", userDataContext.email, ")"]
7640
7895
  }), jsxs("p", {
7641
7896
  children: [jsxs("label", {
7642
7897
  children: [' ', intl.formatMessage({
@@ -7646,7 +7901,7 @@ function UserCtx() {
7646
7901
  "value": "Creation Date"
7647
7902
  }]
7648
7903
  }), ":", ' ']
7649
- }), ' ', formatDate(Ctx.context.creation_date)]
7904
+ }), ' ', formatDate(userDataContext.creation_date)]
7650
7905
  }), jsxs("p", {
7651
7906
  children: [jsxs("label", {
7652
7907
  children: [' ', intl.formatMessage({
@@ -7656,7 +7911,7 @@ function UserCtx() {
7656
7911
  "value": "Modification Date"
7657
7912
  }]
7658
7913
  }), ":", ' ']
7659
- }), ' ', formatDate(Ctx.context.modification_date)]
7914
+ }), ' ', formatDate(userDataContext.modification_date)]
7660
7915
  }), jsx(Button, {
7661
7916
  className: "is-size-7 is-info",
7662
7917
  onClick: () => {
@@ -7673,7 +7928,7 @@ function UserCtx() {
7673
7928
  }), jsx("hr", {}), jsx(UserForm, {
7674
7929
  actionName: "Save",
7675
7930
  onSubmit: ev => updateObject(ev),
7676
- formData: Ctx.context,
7931
+ formData: userDataContext,
7677
7932
  exclude: ['password'],
7678
7933
  remotes: remotes,
7679
7934
  submitButton: false,
@@ -7687,7 +7942,7 @@ function UserCtx() {
7687
7942
  className: "column",
7688
7943
  children: [jsx(TagsWidget, {
7689
7944
  onChange: updateRemote('user_groups'),
7690
- items: Ctx.context.user_groups,
7945
+ items: userDataContext.user_groups,
7691
7946
  title: "Groups",
7692
7947
  noData: intl.formatMessage({
7693
7948
  id: "there_is_no_groups_for_this_user",
@@ -7708,7 +7963,10 @@ function UserCtx() {
7708
7963
  "value": "The user doesn't have any role"
7709
7964
  }]
7710
7965
  }),
7711
- available: state.roles
7966
+ available: state.roles.map(x => ({
7967
+ value: x,
7968
+ text: x
7969
+ }))
7712
7970
  })]
7713
7971
  })]
7714
7972
  })]
@@ -7726,7 +7984,7 @@ function CopyItems(props) {
7726
7984
  async function copyItems(path, form) {
7727
7985
  const responses = await Promise.all(items.map((item, i) => {
7728
7986
  const input = form[i + 1] || {};
7729
- return Ctx.client.post(`${Ctx.path}${item['@name']}/@duplicate`, {
7987
+ return Ctx.client.post(`${Ctx.path}${item.id}/@duplicate`, {
7730
7988
  destination: path,
7731
7989
  new_id: input.value || getNewId(item.id)
7732
7990
  });
@@ -7762,7 +8020,7 @@ function CopyItems(props) {
7762
8020
  }), jsx("input", {
7763
8021
  type: "text",
7764
8022
  className: "input",
7765
- "data-test": `inputCopyIdTest-${item['@name']}`,
8023
+ "data-test": `inputCopyIdTest-${item.id}`,
7766
8024
  defaultValue: getNewId(item.id)
7767
8025
  })]
7768
8026
  }, item.id)), "\u00A0"]
@@ -7832,9 +8090,9 @@ function MoveItems(props) {
7832
8090
 
7833
8091
  async function moveItems(path) {
7834
8092
  const responses = await Promise.all(items.map(item => {
7835
- return Ctx.client.post(`${Ctx.path}${item['@name']}/@move`, {
8093
+ return Ctx.client.post(`${Ctx.path}${item.id}/@move`, {
7836
8094
  destination: path,
7837
- new_id: item['@name']
8095
+ new_id: item.id
7838
8096
  });
7839
8097
  }));
7840
8098
  Ctx.refresh();
@@ -8123,18 +8381,17 @@ function GroupToolbar() {
8123
8381
  const [location, setLocation] = useLocation();
8124
8382
  const searchText = location.get('q');
8125
8383
 
8126
- const onSearchQuery = ev => {
8127
- const search = ev.target[0].value;
8384
+ const onSearchQuery = event => {
8385
+ event.preventDefault();
8128
8386
  setLocation({
8129
- q: search,
8387
+ q: event.currentTarget.elements.filterInput.value,
8130
8388
  page: 0
8131
8389
  });
8132
- ev.preventDefault();
8133
8390
  }; // cleanup form on state.search change
8134
8391
 
8135
8392
 
8136
8393
  useEffect(() => {
8137
- if (!searchText || searchText === '') {
8394
+ if (ref.current && (!searchText || searchText === '')) {
8138
8395
  ref.current.value = '';
8139
8396
  }
8140
8397
  }, [searchText]);
@@ -8154,7 +8411,8 @@ function GroupToolbar() {
8154
8411
  type: "text",
8155
8412
  className: "input is-size-7",
8156
8413
  placeholder: intl.formatMessage(genericMessages.search),
8157
- "data-test": "inputFilterTest"
8414
+ "data-test": "inputFilterTest",
8415
+ id: "filterInput"
8158
8416
  })
8159
8417
  }), jsx("div", {
8160
8418
  className: "control",
@@ -8190,12 +8448,12 @@ function GroupToolbar() {
8190
8448
  })]
8191
8449
  });
8192
8450
  }
8193
- function GroupsCtx(props) {
8194
- return jsx(TabsPanel, _extends({
8451
+ function GroupsCtx() {
8452
+ return jsx(TabsPanel, {
8195
8453
  tabs: tabs$4,
8196
8454
  currentTab: "Groups",
8197
8455
  rightToolbar: jsx(GroupToolbar, {})
8198
- }, props));
8456
+ });
8199
8457
  }
8200
8458
  const sortParsed = parser(`_sort_asc=id`);
8201
8459
  const searchParsed = parser('type_name=User');
@@ -8206,6 +8464,7 @@ function GroupCtx() {
8206
8464
  patch
8207
8465
  } = useCrudContext();
8208
8466
  const [roles, setRoles] = useState([]);
8467
+ const groupDataContext = Ctx.context;
8209
8468
  useEffect(() => {
8210
8469
  async function getRoles() {
8211
8470
  const requestGetRoles = await Ctx.client.getRoles(Ctx.path);
@@ -8240,9 +8499,9 @@ function GroupCtx() {
8240
8499
  isError,
8241
8500
  errorMessage
8242
8501
  } = await patch({
8243
- user_roles: Ctx.context.user_roles.concat(role)
8502
+ user_roles: groupDataContext.user_roles.concat(role)
8244
8503
  });
8245
- handleResponse(isError, intl.formatMessage({
8504
+ handleResponse(!!isError, intl.formatMessage({
8246
8505
  id: "role_added_to_group",
8247
8506
  defaultMessage: [{
8248
8507
  "type": 0,
@@ -8256,7 +8515,7 @@ function GroupCtx() {
8256
8515
  }]
8257
8516
  }, {
8258
8517
  role
8259
- }), errorMessage);
8518
+ }), errorMessage != null ? errorMessage : '');
8260
8519
  };
8261
8520
 
8262
8521
  const removeRole = async role => {
@@ -8264,9 +8523,9 @@ function GroupCtx() {
8264
8523
  isError,
8265
8524
  errorMessage
8266
8525
  } = await patch({
8267
- user_roles: Ctx.context.user_roles.filter(r => r !== role)
8526
+ user_roles: groupDataContext.user_roles.filter(r => r !== role)
8268
8527
  });
8269
- handleResponse(isError, intl.formatMessage({
8528
+ handleResponse(!!isError, intl.formatMessage({
8270
8529
  id: "role_removed_from_group",
8271
8530
  defaultMessage: [{
8272
8531
  "type": 0,
@@ -8280,21 +8539,22 @@ function GroupCtx() {
8280
8539
  }]
8281
8540
  }, {
8282
8541
  role
8283
- }), errorMessage);
8542
+ }), errorMessage != null ? errorMessage : '');
8284
8543
  };
8285
8544
 
8286
8545
  const addUser = async newUserId => {
8287
8546
  const data = {};
8288
- Ctx.context.users.forEach(user => {
8547
+ groupDataContext.users.forEach(user => {
8289
8548
  data[user] = true;
8290
8549
  });
8291
8550
  data[newUserId] = true;
8551
+ const response = await Ctx.client.rest.patch(`${Ctx.containerPath}@groups/${Ctx.context['@name']}`, {
8552
+ users: data
8553
+ });
8292
8554
  const {
8293
8555
  isError,
8294
8556
  errorMessage
8295
- } = await Ctx.client.rest.patch(`${Ctx.containerPath}@groups/${Ctx.context['@name']}`, {
8296
- users: data
8297
- });
8557
+ } = await processResponse(response);
8298
8558
  handleResponse(isError, intl.formatMessage({
8299
8559
  id: "user_added_to_group",
8300
8560
  defaultMessage: [{
@@ -8309,20 +8569,21 @@ function GroupCtx() {
8309
8569
  }]
8310
8570
  }, {
8311
8571
  user: newUserId
8312
- }), errorMessage);
8572
+ }), errorMessage != null ? errorMessage : '');
8313
8573
  };
8314
8574
 
8315
8575
  const removeUser = async userToRemove => {
8316
8576
  const data = {};
8317
- Ctx.context.users.forEach(user => {
8577
+ groupDataContext.users.forEach(user => {
8318
8578
  data[user] = userToRemove !== user;
8319
8579
  });
8580
+ const response = await Ctx.client.rest.patch(`${Ctx.containerPath}@groups/${Ctx.context['@name']}`, {
8581
+ users: data
8582
+ });
8320
8583
  const {
8321
8584
  isError,
8322
8585
  errorMessage
8323
- } = await Ctx.client.rest.patch(`${Ctx.containerPath}@groups/${Ctx.context['@name']}`, {
8324
- users: data
8325
- });
8586
+ } = await processResponse(response);
8326
8587
  handleResponse(isError, intl.formatMessage({
8327
8588
  id: "user_removed_from_group",
8328
8589
  defaultMessage: [{
@@ -8337,7 +8598,7 @@ function GroupCtx() {
8337
8598
  }]
8338
8599
  }, {
8339
8600
  user: userToRemove
8340
- }), errorMessage);
8601
+ }), errorMessage != null ? errorMessage : '');
8341
8602
  };
8342
8603
 
8343
8604
  return jsxs("div", {
@@ -8387,10 +8648,10 @@ function GroupCtx() {
8387
8648
  }]
8388
8649
  })
8389
8650
  }), jsx(Select, {
8390
- options: roles.filter(role => !Ctx.context.user_roles.includes(role.value)),
8651
+ options: roles.filter(role => !groupDataContext.user_roles.includes(role.value)),
8391
8652
  appendDefault: true,
8392
- onChange: addRole
8393
- }), jsx("hr", {}), Ctx.context.user_roles.map(urole => jsx("p", {
8653
+ onChange: value => addRole(value)
8654
+ }), jsx("hr", {}), groupDataContext.user_roles.map(urole => jsx("p", {
8394
8655
  className: "control",
8395
8656
  children: jsx(Tag, {
8396
8657
  name: urole,
@@ -8418,7 +8679,7 @@ function GroupCtx() {
8418
8679
  traversal: Ctx,
8419
8680
  onChange: addUser,
8420
8681
  btnClass: "is-small"
8421
- }), jsx("hr", {}), Ctx.context.users.map(user => jsx("p", {
8682
+ }), jsx("hr", {}), groupDataContext.users.map(user => jsx("p", {
8422
8683
  className: "control",
8423
8684
  children: jsx(Tag, {
8424
8685
  name: user,
@@ -8549,7 +8810,7 @@ function Path() {
8549
8810
  const links = buildPaths(segments);
8550
8811
 
8551
8812
  if (segments.length === 1) {
8552
- return false;
8813
+ return null;
8553
8814
  }
8554
8815
 
8555
8816
  return jsx("nav", {
@@ -8704,11 +8965,15 @@ const getItemsColumn = type => {
8704
8965
  return undefined;
8705
8966
  };
8706
8967
 
8707
- const getForm = (type, fallback = BaseForm) => {
8708
- return registry.forms[type] || fallback;
8968
+ const getView = name => {
8969
+ return registry.views[name];
8970
+ };
8971
+
8972
+ const getForm = (type, fallback) => {
8973
+ return registry.forms[type] || fallback || BaseForm;
8709
8974
  };
8710
8975
 
8711
- const getAction = (type, fallback = undefined) => {
8976
+ const getAction = (type, fallback) => {
8712
8977
  return registry.actions[type] || fallback;
8713
8978
  };
8714
8979
 
@@ -8722,24 +8987,16 @@ const getProperties = type => {
8722
8987
 
8723
8988
  const getSchemas = type => {
8724
8989
  return registry.schemas[type] || {};
8725
- /*
8726
- filters: [
8727
- {
8728
- attribute_key: string,
8729
- label: string,
8730
- type: 'select' | 'input'
8731
- vocabulary: string | undefined
8732
- values: {[key:string]:any}[]
8733
- }
8734
- ]
8735
- */
8736
8990
  };
8737
8991
 
8738
- const getFieldsToFilter = (type, fallback) => {
8992
+ const getFieldsToFilter = (type, fallback = ['title']) => {
8739
8993
  return registry.fieldsToFilter[type] || fallback;
8740
8994
  };
8741
8995
 
8742
- const getDefaultSortValue = (type, fallback) => {
8996
+ const getDefaultSortValue = (type, fallback = {
8997
+ key: 'id',
8998
+ direction: 'des'
8999
+ }) => {
8743
9000
  return registry.defaultSortValue[type] || fallback;
8744
9001
  };
8745
9002
 
@@ -8752,7 +9009,10 @@ function useRegistry(data) {
8752
9009
 
8753
9010
  if (data && !ref.current) {
8754
9011
  ref.current = true;
8755
- Object.keys(data).map(key => registry[key] = _extends({}, registry[key], data[key]));
9012
+ Object.keys(data).map(key => {
9013
+ const registryKey = key;
9014
+ registry[registryKey] = _extends({}, registry[registryKey], data[registryKey]);
9015
+ });
8756
9016
  }
8757
9017
 
8758
9018
  return {
@@ -8766,7 +9026,8 @@ function useRegistry(data) {
8766
9026
  getItemsColumn,
8767
9027
  getFieldsToFilter,
8768
9028
  getDefaultSortValue,
8769
- getSchemas
9029
+ getSchemas,
9030
+ getView
8770
9031
  };
8771
9032
  }
8772
9033
  /*
@@ -8786,83 +9047,6 @@ const registry = {
8786
9047
 
8787
9048
  */
8788
9049
 
8789
- const initialState$4 = {
8790
- path: '',
8791
- loading: false,
8792
- context: undefined,
8793
- flash: {
8794
- message: undefined,
8795
- type: undefined
8796
- },
8797
- action: {
8798
- action: undefined,
8799
- params: undefined
8800
- },
8801
- permissions: undefined,
8802
- errorStatus: undefined,
8803
- registry: {},
8804
- refresh: undefined
8805
- };
8806
- function guillotinaReducer(state, action) {
8807
- switch (action.type) {
8808
- case 'SET_PATH':
8809
- return _extends({}, state, {
8810
- path: action.payload,
8811
- loading: true
8812
- });
8813
-
8814
- case 'SET_CONTEXT':
8815
- return _extends({}, state, action.payload, {
8816
- errorStatus: undefined,
8817
- loading: false
8818
- });
8819
-
8820
- case 'SET_ERROR':
8821
- return _extends({}, state, {
8822
- errorStatus: action.payload,
8823
- loading: false
8824
- });
8825
-
8826
- case 'SET_FLASH':
8827
- return _extends({}, state, action.payload);
8828
-
8829
- case 'CLEAR_FLASH':
8830
- return _extends({}, state, {
8831
- flash: {
8832
- message: undefined,
8833
- type: undefined
8834
- }
8835
- });
8836
-
8837
- case 'SET_ACTION':
8838
- return _extends({}, state, {
8839
- action: action.payload
8840
- });
8841
-
8842
- case 'CLEAR_ACTION':
8843
- return _extends({}, state, {
8844
- action: {
8845
- action: undefined,
8846
- params: undefined
8847
- }
8848
- });
8849
-
8850
- case 'REFRESH':
8851
- return _extends({}, state, {
8852
- refresh: Date.now(),
8853
- loading: !action.payload.transparent
8854
- });
8855
-
8856
- case 'APPLY':
8857
- return _extends({}, state, {
8858
- context: _extends({}, state.context, action.payload)
8859
- });
8860
-
8861
- default:
8862
- return state;
8863
- }
8864
- }
8865
-
8866
9050
  var actions = [
8867
9051
  {
8868
9052
  type: 0,
@@ -11681,25 +11865,27 @@ function Guillotina(_ref) {
11681
11865
  const {
11682
11866
  Permissions
11683
11867
  } = useConfig(config);
11684
- const registry = useRegistry(props.registry || {}); // Location is cooked routing solution (only uses search params)
11868
+ const registry = useRegistry(props.registry); // Location is cooked routing solution (only uses search params)
11685
11869
 
11686
11870
  const [location] = useLocation(); // if there is no path provided just go to root
11687
11871
 
11688
11872
  const searchPath = location.get('path') || '/';
11689
11873
 
11690
11874
  if (searchPath && searchPath !== '') {
11691
- initialState$4.path = searchPath;
11875
+ initialState.path = searchPath;
11692
11876
  }
11693
11877
 
11694
- const [state, dispatch] = useReducer(guillotinaReducer, initialState$4);
11878
+ const [state, dispatch] = useReducer(guillotinaReducer, initialState);
11695
11879
  const {
11696
11880
  path,
11697
11881
  refresh
11698
11882
  } = state;
11699
11883
  useEffect(() => {
11700
11884
  dispatch({
11701
- type: 'SET_PATH',
11702
- payload: searchPath
11885
+ type: GuillotinaReducerActionTypes.SET_PATH,
11886
+ payload: {
11887
+ path: searchPath
11888
+ }
11703
11889
  });
11704
11890
  }, [searchPath]);
11705
11891
  useEffect(() => {
@@ -11708,14 +11894,18 @@ function Guillotina(_ref) {
11708
11894
 
11709
11895
  if (data.status === 401) {
11710
11896
  dispatch({
11711
- type: 'SET_ERROR',
11712
- payload: 'notallowed'
11897
+ type: GuillotinaReducerActionTypes.SET_ERROR,
11898
+ payload: {
11899
+ errorStatus: 'notallowed'
11900
+ }
11713
11901
  });
11714
11902
  return;
11715
11903
  } else if (data.status === 404) {
11716
11904
  dispatch({
11717
- type: 'SET_ERROR',
11718
- payload: 'notfound'
11905
+ type: GuillotinaReducerActionTypes.SET_ERROR,
11906
+ payload: {
11907
+ errorStatus: 'notallowed'
11908
+ }
11719
11909
  });
11720
11910
  return;
11721
11911
  }
@@ -11724,7 +11914,7 @@ function Guillotina(_ref) {
11724
11914
  const pr = await client.canido(path, Permissions);
11725
11915
  const permissions = await pr.json();
11726
11916
  dispatch({
11727
- type: 'SET_CONTEXT',
11917
+ type: GuillotinaReducerActionTypes.SET_CONTEXT,
11728
11918
  payload: {
11729
11919
  context,
11730
11920
  permissions
@@ -11734,9 +11924,9 @@ function Guillotina(_ref) {
11734
11924
 
11735
11925
  initContext();
11736
11926
  }, [path, refresh, client]);
11737
- const ErrorBoundary = registry.get('views', 'ErrorBoundary');
11738
- const NotAllowed = registry.get('views', 'NotAllowed');
11739
- const NotFound = registry.get('views', 'NotFound');
11927
+ const ErrorBoundary = registry.getView('ErrorBoundary');
11928
+ const NotAllowed = registry.getView('NotAllowed');
11929
+ const NotFound = registry.getView('NotFound');
11740
11930
  const Path = registry.get('components', 'Path');
11741
11931
  const contextData = {
11742
11932
  url,
@@ -11761,7 +11951,7 @@ function Guillotina(_ref) {
11761
11951
  children: jsxs(ErrorBoundary, {
11762
11952
  children: [!errorStatus && jsx(TraversalProvider, _extends({}, contextData, {
11763
11953
  children: permissions && jsxs(React.Fragment, {
11764
- children: [action.action && jsx(Action, _extends({}, action.params)), jsx("div", {
11954
+ children: [action.action && Action !== null && jsx(Action, _extends({}, action.params)), jsx("div", {
11765
11955
  className: "level",
11766
11956
  children: jsx("div", {
11767
11957
  className: "level-left",
@@ -11770,7 +11960,7 @@ function Guillotina(_ref) {
11770
11960
  children: jsx(Path, {})
11771
11961
  })
11772
11962
  })
11773
- }), jsx(Flash, {}), Main && jsx(ErrorBoundary, {
11963
+ }), jsx(Flash, {}), Main !== undefined && jsx(ErrorBoundary, {
11774
11964
  children: jsxs("div", {
11775
11965
  className: "box main-panel",
11776
11966
  children: [state.loading && jsx(Loading, {}), !state.loading && jsx(Main, {
@@ -11876,7 +12066,7 @@ const ERRORS = {
11876
12066
  const initialState$5 = {
11877
12067
  username: '',
11878
12068
  password: '',
11879
- loading: undefined,
12069
+ loading: false,
11880
12070
  errors: undefined
11881
12071
  };
11882
12072
  const Login = ({
@@ -11889,7 +12079,7 @@ const Login = ({
11889
12079
  const [state, setState] = useSetState(initialState$5);
11890
12080
  const inputRef = useRef(null);
11891
12081
  useEffect(() => {
11892
- if (inputRef) {
12082
+ if (inputRef && inputRef.current) {
11893
12083
  inputRef.current.focus();
11894
12084
  }
11895
12085
  }, [inputRef]);
@@ -12066,28 +12256,28 @@ function RequiredFieldsForm({
12066
12256
  dataTest: dataTest,
12067
12257
  children: [schema && schema.data && !schema.loading && schema.formFields.map(key => {
12068
12258
  if (!ignoreFiels.includes(key)) {
12069
- var _value$title;
12259
+ var _schema$data, _value$title, _schema$data2;
12070
12260
 
12071
- const value = schema.data.properties[key];
12261
+ const value = (_schema$data = schema.data) == null ? void 0 : _schema$data.properties[key];
12072
12262
  return jsx(EditComponent, {
12073
12263
  id: key,
12074
12264
  placeholder: (_value$title = value == null ? void 0 : value.title) != null ? _value$title : '',
12075
12265
  className: "",
12076
12266
  required: true,
12077
- schema: schema.data.properties[key],
12078
- setValue: ev => {
12267
+ schema: (_schema$data2 = schema.data) == null ? void 0 : _schema$data2.properties[key],
12268
+ setValue: value => {
12079
12269
  if (key === 'title') {
12080
12270
  setFormData(_extends({}, formData, {
12081
- uuid: stringToSlug(ev),
12082
- [key]: ev
12271
+ uuid: stringToSlug(value),
12272
+ [key]: value
12083
12273
  }));
12084
12274
  } else if (key === 'uuid') {
12085
12275
  setFormData(_extends({}, formData, {
12086
- uuid: stringToSlug(ev)
12276
+ uuid: stringToSlug(value)
12087
12277
  }));
12088
12278
  } else {
12089
12279
  setFormData(_extends({}, formData, {
12090
- [key]: ev
12280
+ [key]: value
12091
12281
  }));
12092
12282
  }
12093
12283
  },
@@ -12264,7 +12454,7 @@ class Auth {
12264
12454
 
12265
12455
  if (!authToken) return {};
12266
12456
 
12267
- if (this.willExpire(expires) && this.retryRefresh < this.maxRetry) {
12457
+ if (this.willExpire(expires != null ? expires : '') && this.retryRefresh < this.maxRetry) {
12268
12458
 
12269
12459
  (async function () {
12270
12460
  return await _this.refreshToken();
@@ -12280,5 +12470,14 @@ class Auth {
12280
12470
 
12281
12471
  }
12282
12472
 
12283
- export { AddItem, AddPermission, AllItemsCheckbox, ApplicationCtx, Auth, AuthContext, BaseForm, BehaviorNotImplemented, BehaviorsView, Button, Checkbox, ClientContext, ClientProvider, Config, Confirm, ContainerCtx, ContextToolbar, CreateButton, CreateContainer, DatabaseCtx, Delete, DownloadField, EditComponent, EditableField, EmailInput, FileUpload, Flash, FolderCtx, Form, FormBuilder, GroupCtx, GroupToolbar, GroupsCtx, Guillotina, GuillotinaClient, IAttachment, IImageAttachment, IMultiAttachment, IMultiImageAttachment, IMultiImageOrderedAttachment, IWorkflow, Icon, Input, InputList, Item, ItemCheckbox, ItemCtx, ItemModel, ItemTitle, ItemsActionsDropdown, ItemsActionsProvider, Layout, Link, Loading, Login, Modal, NotAllowed, Notification, Pagination, PanelActions, PanelAddons, PanelBehaviors, PanelItems, PanelNotImplemented, PanelPermissions, PanelProperties, PasswordInput, Path, PathTree, PermissionPrinperm, PermissionPrinrole, PermissionRoleperm, Permissions, PropertiesButtonView, PropertiesView, REGEX_EMAIL, REGEX_HEX_COLOR, REGEX_NUMBER, REGEX_URL, RItem, RemoveItems, RenderField, RenderFieldComponent, RequiredFieldsForm, RestClient, SearchInput, SearchInputList, SearchLabels, SearchOptionsLabels, SearchRenderField, SearchVocabularyLabels, Select, SelectVocabulary, Sharing, Table, TabsPanel, Tag, TagsWidget, TdLink, Textarea, Traversal, TraversalContext, TraversalProvider, UserCtx, UserForm, UsersCtx, UsersToolbar, VocabularyRenderField, base64ToArrayBuffer, buildQs, classnames, defaultComponent, formatDate, generateUID, genericFileMessages, genericMessages, get$1 as get, getActionsObject, getClient, getNewId, isEmail, isEmpty, isHexColor, isNumber, isURL, lightFileReader, maxLength, messages$4 as messages, minLength, noop, notEmpty, parser, sleep, stringToSlug, toQueryString, useConfig, useCrudContext, useGuillotinaClient, useLocation, useRegistry, useRemoteField, useTraversal, useVocabulary };
12473
+ var Setting;
12474
+
12475
+ (function (Setting) {
12476
+ Setting["Allow"] = "Allow";
12477
+ Setting["AllowSingle"] = "AllowSingle";
12478
+ Setting["Deny"] = "Deny";
12479
+ Setting["Unset"] = "Unset";
12480
+ })(Setting || (Setting = {}));
12481
+
12482
+ export { AddItem, AddPermission, AllItemsCheckbox, ApplicationCtx, Auth, AuthContext, BaseForm, BehaviorNotImplemented, BehaviorsView, Button, Checkbox, ClientContext, ClientProvider, Confirm, ContainerCtx, ContextToolbar, CreateButton, CreateContainer, DatabaseCtx, Delete, DownloadField, EditComponent, EditableField, EmailInput, FileUpload, Flash, FolderCtx, Form, FormBuilder, GroupCtx, GroupToolbar, GroupsCtx, Guillotina, GuillotinaClient, IAttachment, IImageAttachment, IMultiAttachment, IMultiImageAttachment, IMultiImageOrderedAttachment, IWorkflow, Icon, Input, InputList, Item, ItemCheckbox, ItemCtx, ItemModel, ItemTitle, ItemsActionsDropdown, ItemsActionsProvider, Layout, Link, Loading, Login, Modal, NotAllowed, Notification, Pagination, PanelActions, PanelAddons, PanelBehaviors, PanelItems, PanelNotImplemented, PanelPermissions, PanelProperties, PasswordInput, Path, PathTree, PermissionPrinperm, PermissionPrinrole, PermissionRoleperm, Permissions, PropertiesButtonView, PropertiesView, REGEX_EMAIL, REGEX_HEX_COLOR, REGEX_NUMBER, REGEX_URL, RItem, RemoveItems, RenderField, RenderFieldComponent, RequiredFieldsForm, RestClient, SearchInput, SearchInputList, SearchLabels, SearchOptionsLabels, SearchRenderField, SearchVocabularyLabels, Select, SelectVocabulary, Setting, Sharing, Table, TabsPanel, Tag, TagsWidget, TdLink, Textarea, Traversal, TraversalContext, TraversalProvider, UserCtx, UserForm, UsersCtx, UsersToolbar, VocabularyRenderField, base64ToArrayBuffer, buildQs, classnames, debounce, defaultComponent, defaultConfig, formatDate, generateUID, genericFileMessages, genericMessages, get, getActionsObject, getClient, getNewId, isEmail, isEmpty, isHexColor, isNumber, isURL, lightFileReader, maxLength, messages$4 as messages, minLength, noop, notEmpty, parser, sleep, stringToSlug, toQueryString, useConfig, useCrudContext, useGuillotinaClient, useLocation, useRegistry, useRemoteField, useTraversal, useVocabulary };
12284
12483
  //# sourceMappingURL=react-gmi.modern.js.map