@webiny/app-headless-cms 5.29.0 → 5.30.0

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 (107) hide show
  1. package/HeadlessCMS.js +5 -1
  2. package/HeadlessCMS.js.map +1 -1
  3. package/admin/components/ContentEntryForm/useBind.js +23 -1
  4. package/admin/components/ContentEntryForm/useBind.js.map +1 -1
  5. package/admin/components/ContentModelEditor/Editor.js +1 -1
  6. package/admin/components/ContentModelEditor/Editor.js.map +1 -1
  7. package/admin/components/FieldEditor/EditFieldDialog/AppearanceTab.js +1 -1
  8. package/admin/components/FieldEditor/EditFieldDialog/AppearanceTab.js.map +1 -1
  9. package/admin/components/FieldEditor/EditFieldDialog/GeneralTab.js +10 -5
  10. package/admin/components/FieldEditor/EditFieldDialog/GeneralTab.js.map +1 -1
  11. package/admin/components/FieldEditor/EditFieldDialog/ValidatorsTab.js +1 -0
  12. package/admin/components/FieldEditor/EditFieldDialog/ValidatorsTab.js.map +1 -1
  13. package/admin/components/FieldEditor/EditFieldDialog.js +8 -7
  14. package/admin/components/FieldEditor/EditFieldDialog.js.map +1 -1
  15. package/admin/contexts/Cms/index.d.ts +60 -0
  16. package/admin/contexts/Cms/index.js +107 -9
  17. package/admin/contexts/Cms/index.js.map +1 -1
  18. package/admin/plugins/editor/defaultBar/SaveContentModelButton.js +1 -0
  19. package/admin/plugins/editor/defaultBar/SaveContentModelButton.js.map +1 -1
  20. package/admin/plugins/entry/DefaultOnEntryDelete.d.ts +2 -0
  21. package/admin/plugins/entry/DefaultOnEntryDelete.js +204 -0
  22. package/admin/plugins/entry/DefaultOnEntryDelete.js.map +1 -0
  23. package/admin/plugins/entry/DefaultOnEntryPublish.d.ts +2 -0
  24. package/admin/plugins/entry/DefaultOnEntryPublish.js +176 -0
  25. package/admin/plugins/entry/DefaultOnEntryPublish.js.map +1 -0
  26. package/admin/plugins/fieldRenderers/Accordion.js +3 -0
  27. package/admin/plugins/fieldRenderers/Accordion.js.map +1 -1
  28. package/admin/plugins/fieldRenderers/DynamicSection.d.ts +11 -8
  29. package/admin/plugins/fieldRenderers/DynamicSection.js +0 -3
  30. package/admin/plugins/fieldRenderers/DynamicSection.js.map +1 -1
  31. package/admin/plugins/fieldRenderers/boolean/booleanSwitch.js +2 -1
  32. package/admin/plugins/fieldRenderers/boolean/booleanSwitch.js.map +1 -1
  33. package/admin/plugins/fieldRenderers/checkboxes.js +2 -1
  34. package/admin/plugins/fieldRenderers/checkboxes.js.map +1 -1
  35. package/admin/plugins/fieldRenderers/dateTime/Input.js +2 -1
  36. package/admin/plugins/fieldRenderers/dateTime/Input.js.map +1 -1
  37. package/admin/plugins/fieldRenderers/dateTime/Select.js +2 -1
  38. package/admin/plugins/fieldRenderers/dateTime/Select.js.map +1 -1
  39. package/admin/plugins/fieldRenderers/dateTime/utils.d.ts +3 -3
  40. package/admin/plugins/fieldRenderers/file/fileField.js +2 -1
  41. package/admin/plugins/fieldRenderers/file/fileField.js.map +1 -1
  42. package/admin/plugins/fieldRenderers/file/fileFields.js +4 -2
  43. package/admin/plugins/fieldRenderers/file/fileFields.js.map +1 -1
  44. package/admin/plugins/fieldRenderers/longText/longText.js +2 -1
  45. package/admin/plugins/fieldRenderers/longText/longText.js.map +1 -1
  46. package/admin/plugins/fieldRenderers/number/numberInput.js +2 -1
  47. package/admin/plugins/fieldRenderers/number/numberInput.js.map +1 -1
  48. package/admin/plugins/fieldRenderers/object/StyledComponents.d.ts +2 -0
  49. package/admin/plugins/fieldRenderers/object/StyledComponents.js +37 -2
  50. package/admin/plugins/fieldRenderers/object/StyledComponents.js.map +1 -1
  51. package/admin/plugins/fieldRenderers/object/arrow_drop_down.svg +1 -0
  52. package/admin/plugins/fieldRenderers/object/arrow_drop_up.svg +1 -0
  53. package/admin/plugins/fieldRenderers/object/multipleObjects.js +101 -47
  54. package/admin/plugins/fieldRenderers/object/multipleObjects.js.map +1 -1
  55. package/admin/plugins/fieldRenderers/radioButtons.js +2 -1
  56. package/admin/plugins/fieldRenderers/radioButtons.js.map +1 -1
  57. package/admin/plugins/fieldRenderers/ref/components/ContentEntriesAutocomplete.js +5 -5
  58. package/admin/plugins/fieldRenderers/ref/components/ContentEntriesAutocomplete.js.map +1 -1
  59. package/admin/plugins/fieldRenderers/ref/components/useReference.js +6 -1
  60. package/admin/plugins/fieldRenderers/ref/components/useReference.js.map +1 -1
  61. package/admin/plugins/fieldRenderers/richText/richTextInput.js +2 -1
  62. package/admin/plugins/fieldRenderers/richText/richTextInput.js.map +1 -1
  63. package/admin/plugins/fieldRenderers/richText/richTextInputs.js +2 -2
  64. package/admin/plugins/fieldRenderers/richText/richTextInputs.js.map +1 -1
  65. package/admin/plugins/fieldRenderers/select.js +2 -1
  66. package/admin/plugins/fieldRenderers/select.js.map +1 -1
  67. package/admin/plugins/fieldRenderers/text/textInput.js +2 -1
  68. package/admin/plugins/fieldRenderers/text/textInput.js.map +1 -1
  69. package/admin/plugins/fieldValidators/date/availableValidators.d.ts +1 -1
  70. package/admin/plugins/index.d.ts +1 -1
  71. package/admin/plugins/validators/unique.d.ts +1 -1
  72. package/admin/views/contentEntries/ContentEntriesList.js +7 -2
  73. package/admin/views/contentEntries/ContentEntriesList.js.map +1 -1
  74. package/admin/views/contentEntries/ContentEntry/ContentEntryContext.d.ts +4 -6
  75. package/admin/views/contentEntries/ContentEntry/ContentEntryContext.js +12 -71
  76. package/admin/views/contentEntries/ContentEntry/ContentEntryContext.js.map +1 -1
  77. package/admin/views/contentEntries/ContentEntry/PublishEntryRevisionListItem.d.ts +1 -0
  78. package/admin/views/contentEntries/ContentEntry/PublishEntryRevisionListItem.js +35 -0
  79. package/admin/views/contentEntries/ContentEntry/PublishEntryRevisionListItem.js.map +1 -0
  80. package/admin/views/contentEntries/ContentEntry/RevisionListItem.js +9 -11
  81. package/admin/views/contentEntries/ContentEntry/RevisionListItem.js.map +1 -1
  82. package/admin/views/contentEntries/ContentEntry/cache.js +47 -21
  83. package/admin/views/contentEntries/ContentEntry/cache.js.map +1 -1
  84. package/admin/views/contentEntries/ContentEntry/header/contentFormOptionsMenu/ContentFormOptionsMenu.js +32 -46
  85. package/admin/views/contentEntries/ContentEntry/header/contentFormOptionsMenu/ContentFormOptionsMenu.js.map +1 -1
  86. package/admin/views/contentEntries/ContentEntry/header/index.js +6 -6
  87. package/admin/views/contentEntries/ContentEntry/header/index.js.map +1 -1
  88. package/admin/views/contentEntries/ContentEntry/header/requestChanges/RequestChanges.d.ts +1 -2
  89. package/admin/views/contentEntries/ContentEntry/header/requestChanges/RequestChanges.js +6 -4
  90. package/admin/views/contentEntries/ContentEntry/header/requestChanges/RequestChanges.js.map +1 -1
  91. package/admin/views/contentEntries/ContentEntry/header/requestReview/RequestReview.d.ts +1 -3
  92. package/admin/views/contentEntries/ContentEntry/header/requestReview/RequestReview.js +6 -4
  93. package/admin/views/contentEntries/ContentEntry/header/requestReview/RequestReview.js.map +1 -1
  94. package/admin/views/contentEntries/ContentEntry/header/saveAndPublishContent/SaveAndPublishContent.d.ts +1 -3
  95. package/admin/views/contentEntries/ContentEntry/header/saveAndPublishContent/SaveAndPublishContent.js +45 -38
  96. package/admin/views/contentEntries/ContentEntry/header/saveAndPublishContent/SaveAndPublishContent.js.map +1 -1
  97. package/admin/views/contentEntries/ContentEntry/useRevision.js +57 -70
  98. package/admin/views/contentEntries/ContentEntry/useRevision.js.map +1 -1
  99. package/admin/views/contentEntries/ContentEntry.js +2 -4
  100. package/admin/views/contentEntries/ContentEntry.js.map +1 -1
  101. package/admin/views/contentEntries/hooks/useContentEntry.js +7 -1
  102. package/admin/views/contentEntries/hooks/useContentEntry.js.map +1 -1
  103. package/admin/views/contentModels/NewContentModelDialog.js +6 -3
  104. package/admin/views/contentModels/NewContentModelDialog.js.map +1 -1
  105. package/package.json +21 -20
  106. package/types.d.ts +10 -7
  107. package/types.js.map +1 -1
@@ -1,9 +1,68 @@
1
1
  import React from "react";
2
2
  import ApolloClient from "apollo-client";
3
+ import { CmsEditorContentEntry, CmsModel } from "../../../types";
4
+ import { MutationHookOptions } from "@apollo/react-hooks";
5
+ import { AsyncProcessor } from "@webiny/utils";
6
+ import { ListQueryVariables } from "../../views/contentEntries/ContentEntriesContext";
7
+ interface PublishEntryOptions {
8
+ mutationOptions?: MutationHookOptions;
9
+ }
10
+ declare type DeleteEntryOptions = PublishEntryOptions;
11
+ interface EntryError {
12
+ message: string;
13
+ code?: string;
14
+ data?: Record<string, any>;
15
+ }
16
+ export interface OnEntryPublishRequest {
17
+ model: CmsModel;
18
+ entry: CmsEditorContentEntry;
19
+ id: string;
20
+ options: PublishEntryOptions;
21
+ error?: EntryError | null;
22
+ locale: string;
23
+ client: ApolloClient<any>;
24
+ listQueryVariables: ListQueryVariables;
25
+ }
26
+ export interface OnEntryPublishResponse extends Omit<OnEntryPublishRequest, "entry"> {
27
+ entry: CmsEditorContentEntry | undefined;
28
+ }
29
+ export interface OnEntryDeleteRequest {
30
+ model: CmsModel;
31
+ entry: CmsEditorContentEntry;
32
+ id: string;
33
+ options: PublishEntryOptions;
34
+ error?: EntryError | null;
35
+ locale: string;
36
+ client: ApolloClient<any>;
37
+ listQueryVariables: ListQueryVariables;
38
+ }
39
+ export interface OnEntryDeleteResponse extends Omit<OnEntryDeleteRequest, "entry"> {
40
+ entry: CmsEditorContentEntry | undefined;
41
+ }
42
+ declare type OnEntryRevisionPublishSubscriber = AsyncProcessor<OnEntryPublishRequest, OnEntryPublishResponse>;
43
+ declare type OnEntryDeleteSubscriber = AsyncProcessor<OnEntryDeleteRequest, OnEntryDeleteResponse>;
44
+ interface PublishEntryRevisionParams {
45
+ model: CmsModel;
46
+ entry: CmsEditorContentEntry;
47
+ options?: PublishEntryOptions;
48
+ id: string;
49
+ listQueryVariables: ListQueryVariables;
50
+ }
51
+ interface DeleteEntryParams {
52
+ model: CmsModel;
53
+ entry: CmsEditorContentEntry;
54
+ id: string;
55
+ options?: DeleteEntryOptions;
56
+ listQueryVariables: ListQueryVariables;
57
+ }
3
58
  export interface CmsContext {
4
59
  getApolloClient(locale: string): ApolloClient<any>;
5
60
  createApolloClient: CmsProviderProps["createApolloClient"];
6
61
  apolloClient: ApolloClient<any>;
62
+ publishEntryRevision: (params: PublishEntryRevisionParams) => Promise<OnEntryPublishResponse>;
63
+ onEntryRevisionPublish: (fn: OnEntryRevisionPublishSubscriber) => () => void;
64
+ deleteEntry: (params: DeleteEntryParams) => Promise<OnEntryDeleteResponse>;
65
+ onEntryDelete: (fn: OnEntryDeleteSubscriber) => () => void;
7
66
  }
8
67
  export declare const CmsContext: React.Context<CmsContext>;
9
68
  export interface CmsProviderProps {
@@ -13,3 +72,4 @@ export interface CmsProviderProps {
13
72
  children: React.ReactNode;
14
73
  }
15
74
  export declare const CmsProvider: React.FC<CmsProviderProps>;
75
+ export {};
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
3
5
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
6
 
5
7
  Object.defineProperty(exports, "__esModule", {
@@ -7,7 +9,15 @@ Object.defineProperty(exports, "__esModule", {
7
9
  });
8
10
  exports.CmsProvider = exports.CmsContext = void 0;
9
11
 
10
- var _react = _interopRequireDefault(require("react"));
12
+ var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
13
+
14
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
15
+
16
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
17
+
18
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
19
+
20
+ var _react = _interopRequireWildcard(require("react"));
11
21
 
12
22
  var _useI18N2 = require("@webiny/app-i18n/hooks/useI18N");
13
23
 
@@ -15,6 +25,8 @@ var _Progress = require("@webiny/ui/Progress");
15
25
 
16
26
  var _config = require("@webiny/app/config");
17
27
 
28
+ var _utils = require("@webiny/utils");
29
+
18
30
  var CmsContext = /*#__PURE__*/_react.default.createContext({
19
31
  getApolloClient: function getApolloClient() {
20
32
  return null;
@@ -38,6 +50,10 @@ var CmsProvider = function CmsProvider(props) {
38
50
  var _useI18N = (0, _useI18N2.useI18N)(),
39
51
  getCurrentLocale = _useI18N.getCurrentLocale;
40
52
 
53
+ var _onEntryRevisionPublish = (0, _react.useRef)([]);
54
+
55
+ var _onEntryDelete = (0, _react.useRef)([]);
56
+
41
57
  var currentLocale = getCurrentLocale("content");
42
58
 
43
59
  if (currentLocale && !apolloClientsCache[currentLocale]) {
@@ -50,18 +66,100 @@ var CmsProvider = function CmsProvider(props) {
50
66
  return /*#__PURE__*/_react.default.createElement(_Progress.CircularProgress, null);
51
67
  }
52
68
 
69
+ var getApolloClient = function getApolloClient(locale) {
70
+ if (!apolloClientsCache[locale]) {
71
+ apolloClientsCache[locale] = props.createApolloClient({
72
+ uri: "".concat(apiUrl, "/cms/manage/").concat(locale)
73
+ });
74
+ }
75
+
76
+ return apolloClientsCache[locale];
77
+ };
78
+
53
79
  var value = {
54
- getApolloClient: function getApolloClient(locale) {
55
- if (!apolloClientsCache[locale]) {
56
- apolloClientsCache[locale] = props.createApolloClient({
57
- uri: "".concat(apiUrl, "/cms/manage/").concat(locale)
58
- });
80
+ getApolloClient: getApolloClient,
81
+ createApolloClient: props.createApolloClient,
82
+ apolloClient: getApolloClient(currentLocale),
83
+ publishEntryRevision: function () {
84
+ var _publishEntryRevision = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(params) {
85
+ return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
86
+ while (1) {
87
+ switch (_context.prev = _context.next) {
88
+ case 0:
89
+ _context.next = 2;
90
+ return (0, _utils.composeAsync)((0, _toConsumableArray2.default)(_onEntryRevisionPublish.current).reverse())((0, _objectSpread2.default)((0, _objectSpread2.default)({
91
+ locale: currentLocale
92
+ }, params), {}, {
93
+ client: getApolloClient(currentLocale),
94
+ options: params.options || {}
95
+ }));
96
+
97
+ case 2:
98
+ return _context.abrupt("return", _context.sent);
99
+
100
+ case 3:
101
+ case "end":
102
+ return _context.stop();
103
+ }
104
+ }
105
+ }, _callee);
106
+ }));
107
+
108
+ function publishEntryRevision(_x) {
109
+ return _publishEntryRevision.apply(this, arguments);
59
110
  }
60
111
 
61
- return apolloClientsCache[locale];
112
+ return publishEntryRevision;
113
+ }(),
114
+ onEntryRevisionPublish: function onEntryRevisionPublish(fn) {
115
+ _onEntryRevisionPublish.current.push(fn);
116
+
117
+ return function () {
118
+ var index = _onEntryRevisionPublish.current.length;
119
+
120
+ _onEntryRevisionPublish.current.splice(index, 1);
121
+ };
62
122
  },
63
- createApolloClient: props.createApolloClient,
64
- apolloClient: apolloClientsCache[currentLocale]
123
+ deleteEntry: function () {
124
+ var _deleteEntry = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee2(params) {
125
+ return (0, _regeneratorRuntime2.default)().wrap(function _callee2$(_context2) {
126
+ while (1) {
127
+ switch (_context2.prev = _context2.next) {
128
+ case 0:
129
+ _context2.next = 2;
130
+ return (0, _utils.composeAsync)((0, _toConsumableArray2.default)(_onEntryDelete.current).reverse())((0, _objectSpread2.default)((0, _objectSpread2.default)({
131
+ locale: currentLocale
132
+ }, params), {}, {
133
+ client: getApolloClient(currentLocale),
134
+ options: params.options || {}
135
+ }));
136
+
137
+ case 2:
138
+ return _context2.abrupt("return", _context2.sent);
139
+
140
+ case 3:
141
+ case "end":
142
+ return _context2.stop();
143
+ }
144
+ }
145
+ }, _callee2);
146
+ }));
147
+
148
+ function deleteEntry(_x2) {
149
+ return _deleteEntry.apply(this, arguments);
150
+ }
151
+
152
+ return deleteEntry;
153
+ }(),
154
+ onEntryDelete: function onEntryDelete(fn) {
155
+ _onEntryDelete.current.push(fn);
156
+
157
+ return function () {
158
+ var index = _onEntryDelete.current.length;
159
+
160
+ _onEntryDelete.current.splice(index, 1);
161
+ };
162
+ }
65
163
  };
66
164
  return /*#__PURE__*/_react.default.createElement(CmsContext.Provider, Object.assign({
67
165
  value: value
@@ -1 +1 @@
1
- {"version":3,"names":["CmsContext","React","createContext","getApolloClient","createApolloClient","apolloClient","apolloClientsCache","CmsProvider","props","apiUrl","appConfig","getKey","process","env","REACT_APP_API_URL","useI18N","getCurrentLocale","currentLocale","uri","value","locale"],"sources":["index.tsx"],"sourcesContent":["import React from \"react\";\nimport ApolloClient from \"apollo-client\";\nimport { useI18N } from \"@webiny/app-i18n/hooks/useI18N\";\nimport { CircularProgress } from \"@webiny/ui/Progress\";\nimport { config as appConfig } from \"@webiny/app/config\";\n\nexport interface CmsContext {\n getApolloClient(locale: string): ApolloClient<any>;\n createApolloClient: CmsProviderProps[\"createApolloClient\"];\n apolloClient: ApolloClient<any>;\n}\n\nexport const CmsContext = React.createContext<CmsContext>({\n getApolloClient: () => {\n return null;\n },\n createApolloClient: () => {\n return null;\n },\n apolloClient: null\n /**\n * Safe to cast.\n */\n} as unknown as CmsContext);\n\ninterface ApolloClientsCache {\n [locale: string]: ApolloClient<any>;\n}\n\nconst apolloClientsCache: ApolloClientsCache = {};\n\nexport interface CmsProviderProps {\n createApolloClient: (params: { uri: string }) => ApolloClient<any>;\n children: React.ReactNode;\n}\n\nexport const CmsProvider: React.FC<CmsProviderProps> = props => {\n const apiUrl = appConfig.getKey(\"API_URL\", process.env.REACT_APP_API_URL);\n const { getCurrentLocale } = useI18N();\n\n const currentLocale = getCurrentLocale(\"content\");\n\n if (currentLocale && !apolloClientsCache[currentLocale]) {\n apolloClientsCache[currentLocale] = props.createApolloClient({\n uri: `${apiUrl}/cms/manage/${currentLocale}`\n });\n }\n\n if (!currentLocale) {\n return <CircularProgress />;\n }\n\n const value = {\n getApolloClient(locale: string) {\n if (!apolloClientsCache[locale]) {\n apolloClientsCache[locale] = props.createApolloClient({\n uri: `${apiUrl}/cms/manage/${locale}`\n });\n }\n return apolloClientsCache[locale];\n },\n createApolloClient: props.createApolloClient,\n apolloClient: apolloClientsCache[currentLocale]\n };\n\n return <CmsContext.Provider value={value} {...props} />;\n};\n"],"mappings":";;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AAQO,IAAMA,UAAU,gBAAGC,cAAA,CAAMC,aAAN,CAAgC;EACtDC,eAAe,EAAE,2BAAM;IACnB,OAAO,IAAP;EACH,CAHqD;EAItDC,kBAAkB,EAAE,8BAAM;IACtB,OAAO,IAAP;EACH,CANqD;EAOtDC,YAAY,EAAE;EACd;AACJ;AACA;;AAV0D,CAAhC,CAAnB;;;AAiBP,IAAMC,kBAAsC,GAAG,EAA/C;;AAOO,IAAMC,WAAuC,GAAG,SAA1CA,WAA0C,CAAAC,KAAK,EAAI;EAC5D,IAAMC,MAAM,GAAGC,cAAA,CAAUC,MAAV,CAAiB,SAAjB,EAA4BC,OAAO,CAACC,GAAR,CAAYC,iBAAxC,CAAf;;EACA,eAA6B,IAAAC,iBAAA,GAA7B;EAAA,IAAQC,gBAAR,YAAQA,gBAAR;;EAEA,IAAMC,aAAa,GAAGD,gBAAgB,CAAC,SAAD,CAAtC;;EAEA,IAAIC,aAAa,IAAI,CAACX,kBAAkB,CAACW,aAAD,CAAxC,EAAyD;IACrDX,kBAAkB,CAACW,aAAD,CAAlB,GAAoCT,KAAK,CAACJ,kBAAN,CAAyB;MACzDc,GAAG,YAAKT,MAAL,yBAA0BQ,aAA1B;IADsD,CAAzB,CAApC;EAGH;;EAED,IAAI,CAACA,aAAL,EAAoB;IAChB,oBAAO,6BAAC,0BAAD,OAAP;EACH;;EAED,IAAME,KAAK,GAAG;IACVhB,eADU,2BACMiB,MADN,EACsB;MAC5B,IAAI,CAACd,kBAAkB,CAACc,MAAD,CAAvB,EAAiC;QAC7Bd,kBAAkB,CAACc,MAAD,CAAlB,GAA6BZ,KAAK,CAACJ,kBAAN,CAAyB;UAClDc,GAAG,YAAKT,MAAL,yBAA0BW,MAA1B;QAD+C,CAAzB,CAA7B;MAGH;;MACD,OAAOd,kBAAkB,CAACc,MAAD,CAAzB;IACH,CARS;IASVhB,kBAAkB,EAAEI,KAAK,CAACJ,kBAThB;IAUVC,YAAY,EAAEC,kBAAkB,CAACW,aAAD;EAVtB,CAAd;EAaA,oBAAO,6BAAC,UAAD,CAAY,QAAZ;IAAqB,KAAK,EAAEE;EAA5B,GAAuCX,KAAvC,EAAP;AACH,CA9BM"}
1
+ {"version":3,"names":["CmsContext","React","createContext","getApolloClient","createApolloClient","apolloClient","apolloClientsCache","CmsProvider","props","apiUrl","appConfig","getKey","process","env","REACT_APP_API_URL","useI18N","getCurrentLocale","onEntryRevisionPublish","useRef","onEntryDelete","currentLocale","uri","locale","value","publishEntryRevision","params","composeAsync","current","reverse","client","options","fn","push","index","length","splice","deleteEntry"],"sources":["index.tsx"],"sourcesContent":["import React, { useRef } from \"react\";\nimport ApolloClient from \"apollo-client\";\nimport { useI18N } from \"@webiny/app-i18n/hooks/useI18N\";\nimport { CircularProgress } from \"@webiny/ui/Progress\";\nimport { config as appConfig } from \"@webiny/app/config\";\nimport { CmsEditorContentEntry, CmsModel } from \"~/types\";\nimport { MutationHookOptions } from \"@apollo/react-hooks\";\nimport { AsyncProcessor, composeAsync } from \"@webiny/utils\";\nimport { ListQueryVariables } from \"~/admin/views/contentEntries/ContentEntriesContext\";\n\ninterface PublishEntryOptions {\n mutationOptions?: MutationHookOptions;\n}\n\ntype DeleteEntryOptions = PublishEntryOptions;\n\ninterface EntryError {\n message: string;\n code?: string;\n data?: Record<string, any>;\n}\n\nexport interface OnEntryPublishRequest {\n model: CmsModel;\n entry: CmsEditorContentEntry;\n id: string;\n options: PublishEntryOptions;\n // TODO: Maybe a different input and output type for compose.\n error?: EntryError | null;\n locale: string;\n client: ApolloClient<any>;\n listQueryVariables: ListQueryVariables;\n}\n\nexport interface OnEntryPublishResponse extends Omit<OnEntryPublishRequest, \"entry\"> {\n entry: CmsEditorContentEntry | undefined;\n}\n\nexport interface OnEntryDeleteRequest {\n model: CmsModel;\n entry: CmsEditorContentEntry;\n id: string;\n options: PublishEntryOptions;\n // TODO: Maybe a different input and output type for compose.\n error?: EntryError | null;\n locale: string;\n client: ApolloClient<any>;\n listQueryVariables: ListQueryVariables;\n}\n\nexport interface OnEntryDeleteResponse extends Omit<OnEntryDeleteRequest, \"entry\"> {\n entry: CmsEditorContentEntry | undefined;\n}\n\ntype OnEntryRevisionPublishSubscriber = AsyncProcessor<\n OnEntryPublishRequest,\n OnEntryPublishResponse\n>;\ntype OnEntryDeleteSubscriber = AsyncProcessor<OnEntryDeleteRequest, OnEntryDeleteResponse>;\n\ninterface PublishEntryRevisionParams {\n model: CmsModel;\n entry: CmsEditorContentEntry;\n options?: PublishEntryOptions;\n id: string;\n listQueryVariables: ListQueryVariables;\n}\ninterface DeleteEntryParams {\n model: CmsModel;\n entry: CmsEditorContentEntry;\n id: string;\n options?: DeleteEntryOptions;\n listQueryVariables: ListQueryVariables;\n}\nexport interface CmsContext {\n getApolloClient(locale: string): ApolloClient<any>;\n createApolloClient: CmsProviderProps[\"createApolloClient\"];\n apolloClient: ApolloClient<any>;\n publishEntryRevision: (params: PublishEntryRevisionParams) => Promise<OnEntryPublishResponse>;\n onEntryRevisionPublish: (fn: OnEntryRevisionPublishSubscriber) => () => void;\n deleteEntry: (params: DeleteEntryParams) => Promise<OnEntryDeleteResponse>;\n onEntryDelete: (fn: OnEntryDeleteSubscriber) => () => void;\n}\n\nexport const CmsContext = React.createContext<CmsContext>({\n getApolloClient: () => {\n return null;\n },\n createApolloClient: () => {\n return null;\n },\n apolloClient: null\n /**\n * Safe to cast.\n */\n} as unknown as CmsContext);\n\ninterface ApolloClientsCache {\n [locale: string]: ApolloClient<any>;\n}\n\nconst apolloClientsCache: ApolloClientsCache = {};\n\nexport interface CmsProviderProps {\n createApolloClient: (params: { uri: string }) => ApolloClient<any>;\n children: React.ReactNode;\n}\n\nexport const CmsProvider: React.FC<CmsProviderProps> = props => {\n const apiUrl = appConfig.getKey(\"API_URL\", process.env.REACT_APP_API_URL);\n const { getCurrentLocale } = useI18N();\n\n const onEntryRevisionPublish = useRef<OnEntryRevisionPublishSubscriber[]>([]);\n const onEntryDelete = useRef<OnEntryDeleteSubscriber[]>([]);\n\n const currentLocale = getCurrentLocale(\"content\");\n\n if (currentLocale && !apolloClientsCache[currentLocale]) {\n apolloClientsCache[currentLocale] = props.createApolloClient({\n uri: `${apiUrl}/cms/manage/${currentLocale}`\n });\n }\n\n if (!currentLocale) {\n return <CircularProgress />;\n }\n\n const getApolloClient = (locale: string) => {\n if (!apolloClientsCache[locale]) {\n apolloClientsCache[locale] = props.createApolloClient({\n uri: `${apiUrl}/cms/manage/${locale}`\n });\n }\n return apolloClientsCache[locale];\n };\n\n const value: CmsContext = {\n getApolloClient,\n createApolloClient: props.createApolloClient,\n apolloClient: getApolloClient(currentLocale),\n publishEntryRevision: async params => {\n return await composeAsync([...onEntryRevisionPublish.current].reverse())({\n locale: currentLocale,\n ...params,\n client: getApolloClient(currentLocale),\n options: params.options || {}\n });\n },\n onEntryRevisionPublish: fn => {\n onEntryRevisionPublish.current.push(fn);\n return () => {\n const index = onEntryRevisionPublish.current.length;\n onEntryRevisionPublish.current.splice(index, 1);\n };\n },\n deleteEntry: async params => {\n return await composeAsync([...onEntryDelete.current].reverse())({\n locale: currentLocale,\n ...params,\n client: getApolloClient(currentLocale),\n options: params.options || {}\n });\n },\n onEntryDelete: fn => {\n onEntryDelete.current.push(fn);\n return () => {\n const index = onEntryDelete.current.length;\n onEntryDelete.current.splice(index, 1);\n };\n }\n };\n\n return <CmsContext.Provider value={value} {...props} />;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AAGA;;AA6EO,IAAMA,UAAU,gBAAGC,cAAA,CAAMC,aAAN,CAAgC;EACtDC,eAAe,EAAE,2BAAM;IACnB,OAAO,IAAP;EACH,CAHqD;EAItDC,kBAAkB,EAAE,8BAAM;IACtB,OAAO,IAAP;EACH,C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2BD,EAA3B;;MACA,OAAO,YAAM;QACT,IAAME,KAAK,GAAGd,cAAa,CAACQ,OAAd,CAAsBO,MAApC;;QACAf,cAAa,CAACQ,OAAd,CAAsBQ,MAAtB,CAA6BF,KAA7B,EAAoC,CAApC;MACH,CAHD;IAIH;EAjCqB,CAA1B;EAoCA,oBAAO,6BAAC,UAAD,CAAY,QAAZ;IAAqB,KAAK,EAAEV;EAA5B,GAAuCf,KAAvC,EAAP;AACH,CAjEM"}
@@ -77,6 +77,7 @@ var SaveContentModelButton = function SaveContentModelButton() {
77
77
  })), [saveContentModel]);
78
78
 
79
79
  return /*#__PURE__*/_react.default.createElement(_Button.ButtonPrimary, {
80
+ "data-testid": "cms.editor.defaultbar.save",
80
81
  disabled: loading,
81
82
  onClick: function onClick() {
82
83
  _onClick();
@@ -1 +1 @@
1
- {"version":3,"names":["t","i18n","namespace","SaveContentModelButton","useContentModelEditor","saveContentModel","useState","loading","setLoading","useSnackbar","showSnackbar","onClick","useCallback","response","error","message"],"sources":["SaveContentModelButton.tsx"],"sourcesContent":["import React, { useCallback, useState } from \"react\";\nimport { ButtonPrimary } from \"@webiny/ui/Button\";\nimport { useSnackbar } from \"@webiny/app-admin/hooks/useSnackbar\";\nimport { i18n } from \"@webiny/app/i18n\";\nimport { useContentModelEditor } from \"~/admin/components/ContentModelEditor/useContentModelEditor\";\n\nconst t = i18n.namespace(\"app-headless-cms/admin/editor/top-bar/save-button\");\n\nconst SaveContentModelButton: React.FC = () => {\n const { saveContentModel } = useContentModelEditor();\n const [loading, setLoading] = useState<boolean>(false);\n const { showSnackbar } = useSnackbar();\n\n const onClick = useCallback(async () => {\n setLoading(true);\n const response = await saveContentModel();\n setLoading(false);\n\n if (response.error) {\n showSnackbar(response.error.message);\n return;\n }\n\n showSnackbar(t`Your content model was saved successfully!`);\n }, [saveContentModel]);\n\n return (\n <ButtonPrimary\n disabled={loading}\n onClick={() => {\n onClick();\n }}\n >\n {t`Save`}\n </ButtonPrimary>\n );\n};\n\nexport default SaveContentModelButton;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAEA,IAAMA,CAAC,GAAGC,UAAA,CAAKC,SAAL,CAAe,mDAAf,CAAV;;AAEA,IAAMC,sBAAgC,GAAG,SAAnCA,sBAAmC,GAAM;EAC3C,4BAA6B,IAAAC,4CAAA,GAA7B;EAAA,IAAQC,gBAAR,yBAAQA,gBAAR;;EACA,gBAA8B,IAAAC,eAAA,EAAkB,KAAlB,CAA9B;EAAA;EAAA,IAAOC,OAAP;EAAA,IAAgBC,UAAhB;;EACA,mBAAyB,IAAAC,yBAAA,GAAzB;EAAA,IAAQC,YAAR,gBAAQA,YAAR;;EAEA,IAAMC,QAAO,GAAG,IAAAC,kBAAA,uGAAY;IAAA;IAAA;MAAA;QAAA;UAAA;YACxBJ,UAAU,CAAC,IAAD,CAAV;YADwB;YAAA,OAEDH,gBAAgB,EAFf;;UAAA;YAElBQ,QAFkB;YAGxBL,UAAU,CAAC,KAAD,CAAV;;YAHwB,KAKpBK,QAAQ,CAACC,KALW;cAAA;cAAA;YAAA;;YAMpBJ,YAAY,CAACG,QAAQ,CAACC,KAAT,CAAeC,OAAhB,CAAZ;YANoB;;UAAA;YAUxBL,YAAY,CAACV,CAAD,8HAAZ;;UAVwB;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CAAZ,IAWb,CAACK,gBAAD,CAXa,CAAhB;;EAaA,oBACI,6BAAC,qBAAD;IACI,QAAQ,EAAEE,OADd;IAEI,OAAO,EAAE,mBAAM;MACXI,QAAO;IACV;EAJL,GAMKX,CANL,0FADJ;AAUH,CA5BD;;eA8BeG,sB"}
1
+ {"version":3,"names":["t","i18n","namespace","SaveContentModelButton","useContentModelEditor","saveContentModel","useState","loading","setLoading","useSnackbar","showSnackbar","onClick","useCallback","response","error","message"],"sources":["SaveContentModelButton.tsx"],"sourcesContent":["import React, { useCallback, useState } from \"react\";\nimport { ButtonPrimary } from \"@webiny/ui/Button\";\nimport { useSnackbar } from \"@webiny/app-admin/hooks/useSnackbar\";\nimport { i18n } from \"@webiny/app/i18n\";\nimport { useContentModelEditor } from \"~/admin/components/ContentModelEditor/useContentModelEditor\";\n\nconst t = i18n.namespace(\"app-headless-cms/admin/editor/top-bar/save-button\");\n\nconst SaveContentModelButton: React.FC = () => {\n const { saveContentModel } = useContentModelEditor();\n const [loading, setLoading] = useState<boolean>(false);\n const { showSnackbar } = useSnackbar();\n\n const onClick = useCallback(async () => {\n setLoading(true);\n const response = await saveContentModel();\n setLoading(false);\n\n if (response.error) {\n showSnackbar(response.error.message);\n return;\n }\n\n showSnackbar(t`Your content model was saved successfully!`);\n }, [saveContentModel]);\n\n return (\n <ButtonPrimary\n data-testid=\"cms.editor.defaultbar.save\"\n disabled={loading}\n onClick={() => {\n onClick();\n }}\n >\n {t`Save`}\n </ButtonPrimary>\n );\n};\n\nexport default SaveContentModelButton;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;AAEA,IAAMA,CAAC,GAAGC,UAAA,CAAKC,SAAL,CAAe,mDAAf,CAAV;;AAEA,IAAMC,sBAAgC,GAAG,SAAnCA,sBAAmC,GAAM;EAC3C,4BAA6B,IAAAC,4CAAA,GAA7B;EAAA,IAAQC,gBAAR,yBAAQA,gBAAR;;EACA,gBAA8B,IAAAC,eAAA,EAAkB,KAAlB,CAA9B;EAAA;EAAA,IAAOC,OAAP;EAAA,IAAgBC,UAAhB;;EACA,mBAAyB,IAAAC,yBAAA,GAAzB;EAAA,IAAQC,YAAR,gBAAQA,YAAR;;EAEA,IAAMC,QAAO,GAAG,IAAAC,kBAAA,uGAAY;IAAA;IAAA;MAAA;QAAA;UAAA;YACxBJ,UAAU,CAAC,IAAD,CAAV;YADwB;YAAA,OAEDH,gBAAgB,EAFf;;UAAA;YAElBQ,QAFkB;YAGxBL,UAAU,CAAC,KAAD,CAAV;;YAHwB,KAKpBK,QAAQ,CAACC,KALW;cAAA;cAAA;YAAA;;YAMpBJ,YAAY,CAACG,QAAQ,CAACC,KAAT,CAAeC,OAAhB,CAAZ;YANoB;;UAAA;YAUxBL,YAAY,CAACV,CAAD,8HAAZ;;UAVwB;UAAA;YAAA;QAAA;MAAA;IAAA;EAAA,CAAZ,IAWb,CAACK,gBAAD,CAXa,CAAhB;;EAaA,oBACI,6BAAC,qBAAD;IACI,eAAY,4BADhB;IAEI,QAAQ,EAAEE,OAFd;IAGI,OAAO,EAAE,mBAAM;MACXI,QAAO;IACV;EALL,GAOKX,CAPL,0FADJ;AAWH,CA7BD;;eA+BeG,sB"}
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare const DefaultOnEntryDelete: React.NamedExoticComponent<{}>;
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.DefaultOnEntryDelete = void 0;
11
+
12
+ var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
13
+
14
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
15
+
16
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
17
+
18
+ var _react = _interopRequireWildcard(require("react"));
19
+
20
+ var _hooks = require("../../hooks");
21
+
22
+ var _contentEntries = require("../../graphql/contentEntries");
23
+
24
+ var GQLCache = _interopRequireWildcard(require("../../views/contentEntries/ContentEntry/cache"));
25
+
26
+ var _utils = require("@webiny/utils");
27
+
28
+ var createMutationKey = function createMutationKey(params) {
29
+ var model = params.model,
30
+ locale = params.locale;
31
+ return "".concat(model.modelId, "_").concat(locale, "_").concat(model.savedOn);
32
+ };
33
+
34
+ var OnEntryDelete = function OnEntryDelete() {
35
+ var _useCms = (0, _hooks.useCms)(),
36
+ onEntryDelete = _useCms.onEntryDelete;
37
+
38
+ var mutations = (0, _react.useRef)({});
39
+
40
+ var getMutation = function getMutation(model, locale) {
41
+ var key = createMutationKey({
42
+ model: model,
43
+ locale: locale
44
+ });
45
+
46
+ if (!mutations.current[key]) {
47
+ mutations.current[key] = (0, _contentEntries.createDeleteMutation)(model);
48
+ }
49
+
50
+ return mutations.current[key];
51
+ };
52
+
53
+ var handleOnDelete = /*#__PURE__*/function () {
54
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee(_ref) {
55
+ var entry, model, id, client, _ref$listQueryVariabl, listQueryVariables, locale, mutation, response, _error, error, _parseIdentifier, version, revisions;
56
+
57
+ return (0, _regeneratorRuntime2.default)().wrap(function _callee$(_context) {
58
+ while (1) {
59
+ switch (_context.prev = _context.next) {
60
+ case 0:
61
+ entry = _ref.entry, model = _ref.model, id = _ref.id, client = _ref.client, _ref$listQueryVariabl = _ref.listQueryVariables, listQueryVariables = _ref$listQueryVariabl === void 0 ? {} : _ref$listQueryVariabl, locale = _ref.locale;
62
+ mutation = getMutation(model, locale);
63
+ _context.next = 4;
64
+ return client.mutate({
65
+ mutation: mutation,
66
+ variables: {
67
+ revision: id
68
+ }
69
+ });
70
+
71
+ case 4:
72
+ response = _context.sent;
73
+
74
+ if (response.data) {
75
+ _context.next = 8;
76
+ break;
77
+ }
78
+
79
+ _error = {
80
+ message: "Missing response data on Delete Entry Mutation.",
81
+ code: "MISSING_RESPONSE_DATA",
82
+ data: {}
83
+ };
84
+ return _context.abrupt("return", {
85
+ error: _error
86
+ });
87
+
88
+ case 8:
89
+ error = response.data.content.error;
90
+
91
+ if (!error) {
92
+ _context.next = 11;
93
+ break;
94
+ }
95
+
96
+ return _context.abrupt("return", {
97
+ error: error
98
+ });
99
+
100
+ case 11:
101
+ /**
102
+ * TODO figure out how to do this in a smart way.
103
+ * If there is no version in the ID, we are deleting whole entry.
104
+ */
105
+ _parseIdentifier = (0, _utils.parseIdentifier)(id), version = _parseIdentifier.version;
106
+
107
+ if (!(version === null)) {
108
+ _context.next = 15;
109
+ break;
110
+ }
111
+
112
+ GQLCache.removeEntryFromListCache(model, client.cache, entry, listQueryVariables);
113
+ return _context.abrupt("return", {
114
+ data: true,
115
+ error: null
116
+ });
117
+
118
+ case 15:
119
+ // We have other revisions, update entry's cache
120
+ revisions = GQLCache.removeRevisionFromEntryCache(model, client.cache, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, entry), {}, {
121
+ id: id
122
+ }));
123
+
124
+ if (!(entry.id !== id)) {
125
+ _context.next = 18;
126
+ break;
127
+ }
128
+
129
+ return _context.abrupt("return", {
130
+ data: true,
131
+ error: null
132
+ });
133
+
134
+ case 18:
135
+ GQLCache.updateLatestRevisionInListCache(model, client.cache, revisions[0], listQueryVariables);
136
+ return _context.abrupt("return", {
137
+ entry: revisions[0] || entry,
138
+ data: true,
139
+ error: null
140
+ });
141
+
142
+ case 20:
143
+ case "end":
144
+ return _context.stop();
145
+ }
146
+ }
147
+ }, _callee);
148
+ }));
149
+
150
+ return function handleOnDelete(_x) {
151
+ return _ref2.apply(this, arguments);
152
+ };
153
+ }();
154
+
155
+ (0, _react.useEffect)(function () {
156
+ return onEntryDelete(function (next) {
157
+ return /*#__PURE__*/function () {
158
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee2(params) {
159
+ var result, response;
160
+ return (0, _regeneratorRuntime2.default)().wrap(function _callee2$(_context2) {
161
+ while (1) {
162
+ switch (_context2.prev = _context2.next) {
163
+ case 0:
164
+ _context2.next = 2;
165
+ return next(params);
166
+
167
+ case 2:
168
+ result = _context2.sent;
169
+
170
+ if (!result.error) {
171
+ _context2.next = 5;
172
+ break;
173
+ }
174
+
175
+ return _context2.abrupt("return", result);
176
+
177
+ case 5:
178
+ _context2.next = 7;
179
+ return handleOnDelete((0, _objectSpread2.default)({}, params));
180
+
181
+ case 7:
182
+ response = _context2.sent;
183
+ return _context2.abrupt("return", (0, _objectSpread2.default)((0, _objectSpread2.default)({}, result), response));
184
+
185
+ case 9:
186
+ case "end":
187
+ return _context2.stop();
188
+ }
189
+ }
190
+ }, _callee2);
191
+ }));
192
+
193
+ return function (_x2) {
194
+ return _ref3.apply(this, arguments);
195
+ };
196
+ }();
197
+ });
198
+ }, []);
199
+ return null;
200
+ };
201
+
202
+ var DefaultOnEntryDelete = /*#__PURE__*/_react.default.memo(OnEntryDelete);
203
+
204
+ exports.DefaultOnEntryDelete = DefaultOnEntryDelete;
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createMutationKey","params","model","locale","modelId","savedOn","OnEntryDelete","useCms","onEntryDelete","mutations","useRef","getMutation","key","current","createDeleteMutation","handleOnDelete","entry","id","client","listQueryVariables","mutation","mutate","variables","revision","response","data","error","message","code","content","parseIdentifier","version","GQLCache","removeEntryFromListCache","cache","revisions","removeRevisionFromEntryCache","updateLatestRevisionInListCache","useEffect","next","result","DefaultOnEntryDelete","React","memo"],"sources":["DefaultOnEntryDelete.tsx"],"sourcesContent":["import React, { useEffect, useRef } from \"react\";\nimport { useCms } from \"~/admin/hooks\";\nimport { CmsErrorResponse, CmsModel } from \"~/types\";\nimport {\n CmsEntryDeleteMutationResponse,\n CmsEntryDeleteMutationVariables,\n createDeleteMutation\n} from \"~/admin/graphql/contentEntries\";\nimport { DocumentNode } from \"graphql\";\nimport { OnEntryDeleteRequest } from \"~/admin/contexts/Cms\";\nimport * as GQLCache from \"~/admin/views/contentEntries/ContentEntry/cache\";\nimport { parseIdentifier } from \"@webiny/utils\";\n\ninterface Mutations {\n [key: string]: DocumentNode;\n}\n\ninterface CreateMutationKeyParams {\n model: CmsModel;\n locale: string;\n}\n\nconst createMutationKey = (params: CreateMutationKeyParams): string => {\n const { model, locale } = params;\n return `${model.modelId}_${locale}_${model.savedOn}`;\n};\n\nconst OnEntryDelete: React.FC = () => {\n const { onEntryDelete } = useCms();\n\n const mutations = useRef<Mutations>({});\n\n const getMutation = (model: CmsModel, locale: string) => {\n const key = createMutationKey({ model, locale });\n if (!mutations.current[key]) {\n mutations.current[key] = createDeleteMutation(model);\n }\n return mutations.current[key];\n };\n\n const handleOnDelete = async ({\n entry,\n model,\n id,\n client,\n listQueryVariables = {},\n locale\n }: OnEntryDeleteRequest) => {\n const mutation = getMutation(model, locale);\n\n const response = await client.mutate<\n CmsEntryDeleteMutationResponse,\n CmsEntryDeleteMutationVariables\n >({\n mutation,\n variables: {\n revision: id\n }\n });\n\n if (!response.data) {\n const error: CmsErrorResponse = {\n message: \"Missing response data on Delete Entry Mutation.\",\n code: \"MISSING_RESPONSE_DATA\",\n data: {}\n };\n return {\n error\n };\n }\n const { error } = response.data.content;\n if (error) {\n return {\n error\n };\n }\n /**\n * TODO figure out how to do this in a smart way.\n * If there is no version in the ID, we are deleting whole entry.\n */\n const { version } = parseIdentifier(id);\n if (version === null) {\n GQLCache.removeEntryFromListCache(model, client.cache, entry, listQueryVariables);\n return {\n data: true,\n error: null\n };\n }\n\n // We have other revisions, update entry's cache\n const revisions = GQLCache.removeRevisionFromEntryCache(model, client.cache, {\n ...entry,\n id\n });\n\n if (entry.id !== id) {\n return {\n data: true,\n error: null\n };\n }\n GQLCache.updateLatestRevisionInListCache(\n model,\n client.cache,\n revisions[0],\n listQueryVariables\n );\n\n return {\n entry: revisions[0] || entry,\n data: true,\n error: null\n };\n };\n\n useEffect(() => {\n return onEntryDelete(next => async params => {\n const result = await next(params);\n\n if (result.error) {\n return result;\n }\n\n const response = await handleOnDelete({\n ...params\n });\n return {\n ...result,\n ...response\n };\n });\n }, []);\n\n return null;\n};\n\nexport const DefaultOnEntryDelete = React.memo(OnEntryDelete);\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;AAOA;;AACA;;AAWA,IAAMA,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,MAAD,EAA6C;EACnE,IAAQC,KAAR,GAA0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