@webiny/app-headless-cms 5.20.0-beta.0 → 5.20.0-beta.1

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.
@@ -134,7 +134,6 @@ var Field = function Field(props) {
134
134
  }
135
135
 
136
136
  var isTitleField = field.fieldId === data.titleFieldId && !parent;
137
- console.log(field.fieldId, isTitleField, parent);
138
137
  var lockedFields = data.lockedFields || [];
139
138
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(FieldContainer, null, /*#__PURE__*/React.createElement(Info, null, /*#__PURE__*/React.createElement(Typography, {
140
139
  use: "subtitle1"
@@ -1,5 +1,6 @@
1
1
  export { default as useCms } from "./useCms";
2
2
  export { default as useQuery } from "./useQuery";
3
+ export * from "./useQueryLocale";
3
4
  export { default as useLazyQuery } from "./useLazyQuery";
4
5
  export { default as useMutation } from "./useMutation";
5
6
  export { default as useApolloClient } from "./useApolloClient";
@@ -1,5 +1,6 @@
1
1
  export { default as useCms } from "./useCms";
2
2
  export { default as useQuery } from "./useQuery";
3
+ export * from "./useQueryLocale";
3
4
  export { default as useLazyQuery } from "./useLazyQuery";
4
5
  export { default as useMutation } from "./useMutation";
5
6
  export { default as useApolloClient } from "./useApolloClient";
@@ -0,0 +1,2 @@
1
+ import { DocumentNode } from "graphql";
2
+ export declare const useQueryLocale: (query: DocumentNode, locale: string, options?: {}) => import("@apollo/react-common").QueryResult<any, Record<string, any>>;
@@ -0,0 +1,15 @@
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import useCms from "./useCms";
3
+ import { useQuery as apolloUseQuery } from "@apollo/react-hooks";
4
+ export var useQueryLocale = function useQueryLocale(query, locale) {
5
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
6
+
7
+ var _useCms = useCms(),
8
+ getApolloClient = _useCms.getApolloClient;
9
+
10
+ var client = getApolloClient(locale);
11
+ return apolloUseQuery(query, _objectSpread({
12
+ client: client,
13
+ skip: !client
14
+ }, options));
15
+ };
@@ -3,7 +3,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _createForOfIteratorHelper from "@babel/runtime/helpers/createForOfIteratorHelper";
4
4
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
5
5
 
6
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7;
6
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
7
7
 
8
8
  import _regeneratorRuntime from "@babel/runtime/regenerator";
9
9
  import React, { useCallback } from "react";
@@ -16,13 +16,14 @@ import { Select } from "@webiny/ui/Select";
16
16
  import { useSnackbar } from "@webiny/app-admin/hooks/useSnackbar";
17
17
  import { CircularProgress } from "@webiny/ui/Progress";
18
18
  import { validation } from "@webiny/validation";
19
- import { useQuery, useMutation } from "../../hooks";
19
+ import { useMutation, useQueryLocale } from "../../hooks";
20
20
  import { i18n } from "@webiny/app/i18n";
21
21
  import { ButtonDefault } from "@webiny/ui/Button";
22
22
  import * as UID from "@webiny/ui/Dialog";
23
23
  import { Grid, Cell } from "@webiny/ui/Grid";
24
24
  import { addModelToGroupCache, addModelToListCache } from "./cache";
25
25
  import * as GQL from "../../viewsGraphql";
26
+ import { useI18N } from "@webiny/app-i18n/hooks/useI18N";
26
27
  var t = i18n.ns("app-headless-cms/admin/views/content-models/clone-content-model-dialog");
27
28
  var narrowDialog = /*#__PURE__*/css({
28
29
  ".mdc-dialog__surface": {
@@ -40,6 +41,26 @@ var noPadding = /*#__PURE__*/css({
40
41
  */
41
42
  var disallowedModelIdEndingList = ["Response", "List", "Meta", "Input", "Sorter"];
42
43
 
44
+ var getSelectedGroup = function getSelectedGroup(groups, model) {
45
+ if (groups.length === 0 || !model) {
46
+ return "";
47
+ }
48
+
49
+ var current = model.group.id;
50
+ var group = groups.find(function (g) {
51
+ return g.value === current;
52
+ });
53
+
54
+ if (group) {
55
+ return group.value;
56
+ }
57
+
58
+ var defaultSelected = groups.find(function () {
59
+ return true;
60
+ });
61
+ return defaultSelected ? defaultSelected.value : group.id;
62
+ };
63
+
43
64
  var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
44
65
  var open = _ref.open,
45
66
  onClose = _ref.onClose,
@@ -57,18 +78,39 @@ var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
57
78
  var _useRouter = useRouter(),
58
79
  history = _useRouter.history;
59
80
 
81
+ var _useI18N = useI18N(),
82
+ getLocales = _useI18N.getLocales,
83
+ getCurrentLocale = _useI18N.getCurrentLocale,
84
+ setCurrentLocale = _useI18N.setCurrentLocale;
85
+
86
+ var currentLocale = getCurrentLocale();
87
+
88
+ var _React$useState3 = React.useState(currentLocale),
89
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
90
+ locale = _React$useState4[0],
91
+ setLocale = _React$useState4[1];
92
+
60
93
  var _useMutation = useMutation(GQL.CREATE_CONTENT_MODEL_FROM, {
61
- update: function update(cache, _ref2) {
62
- var data = _ref2.data;
63
- var _data$createContentMo = data.createContentModelFrom,
64
- model = _data$createContentMo.data,
65
- error = _data$createContentMo.error;
94
+ onError: function onError(error) {
95
+ setLoading(false);
96
+ showSnackbar(error.message);
97
+ },
98
+ update: function update(cache, response) {
99
+ var _response$data$create = response.data.createContentModelFrom,
100
+ model = _response$data$create.data,
101
+ error = _response$data$create.error;
66
102
 
67
103
  if (error) {
68
104
  setLoading(false);
69
105
  return showSnackbar(error.message);
70
106
  }
71
107
 
108
+ if (currentLocale !== locale) {
109
+ setCurrentLocale(locale, "content");
110
+ window.location.reload();
111
+ return;
112
+ }
113
+
72
114
  addModelToListCache(cache, model);
73
115
  addModelToGroupCache(cache, model);
74
116
  history.push("/cms/content-models/");
@@ -78,10 +120,11 @@ var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
78
120
  _useMutation2 = _slicedToArray(_useMutation, 1),
79
121
  createContentModelFrom = _useMutation2[0];
80
122
 
81
- var _useQuery = useQuery(GQL.LIST_MENU_CONTENT_GROUPS_MODELS, {
123
+ var _useQueryLocale = useQueryLocale(GQL.LIST_MENU_CONTENT_GROUPS_MODELS, locale, {
82
124
  skip: !open
83
125
  }),
84
- data = _useQuery.data;
126
+ data = _useQueryLocale.data,
127
+ loadingGroups = _useQueryLocale.loading;
85
128
 
86
129
  var contentModelGroups = get(data, "listContentModelGroups.data", []).map(function (item) {
87
130
  return {
@@ -89,6 +132,7 @@ var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
89
132
  label: item.name
90
133
  };
91
134
  });
135
+ var selectedGroup = getSelectedGroup(contentModelGroups, contentModel);
92
136
  var nameValidator = useCallback(function (name) {
93
137
  var target = (name || "").trim();
94
138
 
@@ -123,17 +167,27 @@ var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
123
167
 
124
168
  return true;
125
169
  }, undefined);
170
+ var locales = getLocales().map(function (locale) {
171
+ return {
172
+ value: locale.code,
173
+ label: locale.code === currentLocale ? "Current locale" : locale.code
174
+ };
175
+ });
126
176
  return /*#__PURE__*/React.createElement(UID.Dialog, {
127
177
  open: open,
128
178
  onClose: onClose,
129
179
  className: narrowDialog,
130
180
  "data-testid": "cms-clone-content-model-modal"
131
- }, open && /*#__PURE__*/React.createElement(Form, {
181
+ }, loadingGroups && /*#__PURE__*/React.createElement(CircularProgress, {
182
+ label: "Please wait while we load required information."
183
+ }), open && /*#__PURE__*/React.createElement(Form, {
132
184
  data: {
133
- group: contentModel.group.id
185
+ group: selectedGroup,
186
+ locale: locale,
187
+ name: contentModel.name
134
188
  },
135
189
  onSubmit: /*#__PURE__*/function () {
136
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(data) {
190
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(data) {
137
191
  return _regeneratorRuntime.wrap(function _callee$(_context) {
138
192
  while (1) {
139
193
  switch (_context.prev = _context.next) {
@@ -156,13 +210,13 @@ var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
156
210
  }));
157
211
 
158
212
  return function (_x) {
159
- return _ref3.apply(this, arguments);
213
+ return _ref2.apply(this, arguments);
160
214
  };
161
215
  }()
162
- }, function (_ref4) {
163
- var Bind = _ref4.Bind,
164
- submit = _ref4.submit;
165
- return /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement(CircularProgress, null), /*#__PURE__*/React.createElement(UID.DialogTitle, null, t(_templateObject || (_templateObject = _taggedTemplateLiteral(["New Content Model From Existing"])))), /*#__PURE__*/React.createElement(UID.DialogContent, null, /*#__PURE__*/React.createElement(Grid, {
216
+ }, function (_ref3) {
217
+ var Bind = _ref3.Bind,
218
+ submit = _ref3.submit;
219
+ return /*#__PURE__*/React.createElement(React.Fragment, null, loading && /*#__PURE__*/React.createElement(CircularProgress, null), /*#__PURE__*/React.createElement(UID.DialogTitle, null, t(_templateObject || (_templateObject = _taggedTemplateLiteral(["Clone Content Model"])))), /*#__PURE__*/React.createElement(UID.DialogContent, null, /*#__PURE__*/React.createElement(Grid, {
166
220
  className: noPadding
167
221
  }, /*#__PURE__*/React.createElement(Cell, {
168
222
  span: 12
@@ -171,8 +225,7 @@ var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
171
225
  validators: [validation.create("required,maxLength:100"), nameValidator]
172
226
  }, /*#__PURE__*/React.createElement(Input, {
173
227
  label: t(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["Name"]))),
174
- description: t(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["The name of the content model"]))),
175
- placeholder: contentModel.name
228
+ description: t(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["The name of the content model"])))
176
229
  }))), /*#__PURE__*/React.createElement(Cell, {
177
230
  span: 12
178
231
  }, /*#__PURE__*/React.createElement(Bind, {
@@ -181,8 +234,23 @@ var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
181
234
  }, /*#__PURE__*/React.createElement(Select, {
182
235
  description: t(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["Choose a content model group"]))),
183
236
  label: t(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["Content model group"]))),
184
- options: contentModelGroups,
185
- value: contentModel.group.id
237
+ options: contentModelGroups
238
+ }))), /*#__PURE__*/React.createElement(Cell, {
239
+ span: 12
240
+ }, /*#__PURE__*/React.createElement(Bind, {
241
+ name: "locale",
242
+ validators: validation.create("required"),
243
+ afterChange: function afterChange(value) {
244
+ if (!value) {
245
+ return;
246
+ }
247
+
248
+ setLocale(value);
249
+ }
250
+ }, /*#__PURE__*/React.createElement(Select, {
251
+ description: t(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["Choose a locale into which you wish to clone the model"]))),
252
+ label: t(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["Content model locale"]))),
253
+ options: locales
186
254
  }))), /*#__PURE__*/React.createElement(Cell, {
187
255
  span: 12
188
256
  }, /*#__PURE__*/React.createElement(Bind, {
@@ -192,12 +260,12 @@ var CloneContentModelDialog = function CloneContentModelDialog(_ref) {
192
260
  rows: 4,
193
261
  maxLength: 200,
194
262
  characterCount: true,
195
- label: t(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["Description"]))),
263
+ label: t(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["Description"]))),
196
264
  value: contentModel.description
197
265
  }));
198
266
  })))), /*#__PURE__*/React.createElement(UID.DialogActions, null, /*#__PURE__*/React.createElement(ButtonDefault, {
199
267
  onClick: submit
200
- }, "+ ", t(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["Create"]))))));
268
+ }, "+ ", t(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["Clone"]))))));
201
269
  }));
202
270
  };
203
271
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/app-headless-cms",
3
- "version": "5.20.0-beta.0",
3
+ "version": "5.20.0-beta.1",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,19 +24,19 @@
24
24
  "@fortawesome/react-fontawesome": "0.1.16",
25
25
  "@svgr/webpack": "4.3.3",
26
26
  "@types/react": "16.14.2",
27
- "@webiny/app": "5.20.0-beta.0",
28
- "@webiny/app-admin": "5.20.0-beta.0",
29
- "@webiny/app-graphql-playground": "5.20.0-beta.0",
30
- "@webiny/app-i18n": "5.20.0-beta.0",
31
- "@webiny/app-plugin-admin-welcome-screen": "5.20.0-beta.0",
32
- "@webiny/app-security": "5.20.0-beta.0",
33
- "@webiny/error": "5.20.0-beta.0",
34
- "@webiny/form": "5.20.0-beta.0",
35
- "@webiny/plugins": "5.20.0-beta.0",
36
- "@webiny/react-router": "5.20.0-beta.0",
37
- "@webiny/ui": "5.20.0-beta.0",
38
- "@webiny/utils": "5.20.0-beta.0",
39
- "@webiny/validation": "5.20.0-beta.0",
27
+ "@webiny/app": "5.20.0-beta.1",
28
+ "@webiny/app-admin": "5.20.0-beta.1",
29
+ "@webiny/app-graphql-playground": "5.20.0-beta.1",
30
+ "@webiny/app-i18n": "5.20.0-beta.1",
31
+ "@webiny/app-plugin-admin-welcome-screen": "5.20.0-beta.1",
32
+ "@webiny/app-security": "5.20.0-beta.1",
33
+ "@webiny/error": "5.20.0-beta.1",
34
+ "@webiny/form": "5.20.0-beta.1",
35
+ "@webiny/plugins": "5.20.0-beta.1",
36
+ "@webiny/react-router": "5.20.0-beta.1",
37
+ "@webiny/ui": "5.20.0-beta.1",
38
+ "@webiny/utils": "5.20.0-beta.1",
39
+ "@webiny/validation": "5.20.0-beta.1",
40
40
  "apollo-cache": "1.3.5",
41
41
  "apollo-client": "2.6.10",
42
42
  "apollo-link": "1.2.14",
@@ -68,8 +68,8 @@
68
68
  "@babel/preset-env": "^7.5.5",
69
69
  "@babel/preset-react": "^7.0.0",
70
70
  "@babel/preset-typescript": "^7.8.3",
71
- "@webiny/cli": "^5.20.0-beta.0",
72
- "@webiny/project-utils": "^5.20.0-beta.0",
71
+ "@webiny/cli": "^5.20.0-beta.1",
72
+ "@webiny/project-utils": "^5.20.0-beta.1",
73
73
  "babel-plugin-emotion": "^9.2.8",
74
74
  "babel-plugin-lodash": "^3.3.4",
75
75
  "babel-plugin-module-resolver": "^4.1.0",
@@ -107,5 +107,5 @@
107
107
  ]
108
108
  }
109
109
  },
110
- "gitHead": "2de02bc113e15e3ffa8e1d82deb9d27417787188"
110
+ "gitHead": "40e30fb4c778d0bcc773b3b8231ce8e0861b6d52"
111
111
  }