@griddo/ax 11.7.12-rc.4 → 11.7.13-rc.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "11.7.12-rc.4",
4
+ "version": "11.7.13-rc.0",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -223,5 +223,5 @@
223
223
  "publishConfig": {
224
224
  "access": "public"
225
225
  },
226
- "gitHead": "96f4a36f82c95316a44143e8eeec2b0d8fae9ed6"
226
+ "gitHead": "5a9e624c2b0b432051abcac24ffdb6da14aa95c0"
227
227
  }
@@ -47,6 +47,7 @@ const Field = (props: IFieldProps): JSX.Element => {
47
47
  selectedContent,
48
48
  isTemplateActivated,
49
49
  theme,
50
+ moduleCopy,
50
51
  disabled,
51
52
  site,
52
53
  errors,
@@ -45,6 +45,7 @@ import {
45
45
  getPageNavigation,
46
46
  getStateValues,
47
47
  protectFormKeys,
48
+ addElementToCollection,
48
49
  } from "./utils";
49
50
  import {
50
51
  SET_BREADCRUMB,
@@ -679,7 +680,7 @@ function duplicatePage(pageID: number, data: any, siteID?: number): (dispatch: D
679
680
 
680
681
  const callback = async () => pages.duplicatePage(pageID, data, siteID);
681
682
 
682
- return await handleRequest(callback, responseActions, [])(dispatch);
683
+ return await handleRequest(callback, responseActions, [appActions.setIsSaving])(dispatch);
683
684
  } catch (e) {
684
685
  console.log(e);
685
686
  return false;
@@ -708,27 +709,37 @@ function addComponent(
708
709
  type,
709
710
  };
710
711
 
711
- const updatedObj = getUpdatedComponents(sections, component, key);
712
- const updatedSections = updatedObj.updatedSections;
712
+ let lastElementEditorID = null;
713
713
 
714
- const updatedPageContent = {
715
- ...editorContent,
716
- template: {
717
- ...editorContent.template,
718
- ...updatedSections,
719
- },
720
- };
714
+ if (sections.length) {
715
+ const updatedObj = getUpdatedComponents(sections, component, key);
716
+ const updatedSections = updatedObj.updatedSections;
721
717
 
722
- generatePageContent(updatedPageContent)(dispatch, getState);
718
+ const updatedPageContent = {
719
+ ...editorContent,
720
+ template: {
721
+ ...editorContent.template,
722
+ ...updatedSections,
723
+ },
724
+ };
725
+
726
+ generatePageContent(updatedPageContent)(dispatch, getState);
727
+
728
+ if (typeof type === "object" && Object.prototype.hasOwnProperty.call(type, "editorID")) {
729
+ setSelectedContent(type.editorID)(dispatch, getState);
730
+ } else {
731
+ const { sections: generatedSections } = getStateValues(getState);
723
732
 
724
- if (typeof type === "object" && Object.prototype.hasOwnProperty.call(type, "editorID")) {
725
- setSelectedContent(type.editorID)(dispatch, getState);
733
+ lastElementEditorID = getLastComponentEditorID(generatedSections, component.editorID, key);
734
+ dispatch(setLastElementAddedId(lastElementEditorID));
735
+ localStorage.setItem("selectedID", `${lastElementEditorID}`);
736
+ }
726
737
  } else {
727
- const { sections: generatedSections } = getStateValues(getState);
728
- const lastElementEditorID = getLastComponentEditorID(generatedSections, component.editorID, key);
729
- dispatch(setLastElementAddedId(lastElementEditorID));
730
- localStorage.setItem("selectedID", `${lastElementEditorID}`);
738
+ lastElementEditorID = addElementToCollection(type as string, key, dispatch, getState);
731
739
  }
740
+
741
+ dispatch(setLastElementAddedId(lastElementEditorID));
742
+ localStorage.setItem("selectedID", `${lastElementEditorID}`);
732
743
  };
733
744
  }
734
745
 
@@ -747,36 +758,42 @@ function addModule(
747
758
  return;
748
759
  }
749
760
 
750
- const componentModule = {
751
- editorID,
752
- type,
753
- };
761
+ let lastModuleEditorID = null;
754
762
 
755
- let updatedSections,
756
- updatedSectionIndex = 0;
763
+ if (sections.length) {
764
+ const componentModule = {
765
+ editorID,
766
+ type,
767
+ };
757
768
 
758
- if (isComponentModule) {
759
- const updatedObj = getUpdatedComponents(sections, componentModule, key);
760
- updatedSections = updatedObj.updatedSections;
761
- updatedSectionIndex = updatedObj.selectedIndex;
762
- } else {
763
- const updatedObj = getUpdatedSections(sections, selectedID, type);
764
- updatedSections = updatedObj.updatedSections;
765
- updatedSectionIndex = updatedObj.selectedIndex;
766
- }
769
+ let updatedSections,
770
+ updatedSectionIndex = 0;
767
771
 
768
- const updatedPageContent = {
769
- ...editorContent,
770
- template: {
771
- ...editorContent.template,
772
- ...updatedSections,
773
- },
774
- };
772
+ if (isComponentModule) {
773
+ const updatedObj = getUpdatedComponents(sections, componentModule, key);
774
+ updatedSections = updatedObj.updatedSections;
775
+ updatedSectionIndex = updatedObj.selectedIndex;
776
+ } else {
777
+ const updatedObj = getUpdatedSections(sections, selectedID, type);
778
+ updatedSections = updatedObj.updatedSections;
779
+ updatedSectionIndex = updatedObj.selectedIndex;
780
+ }
775
781
 
776
- generatePageContent(updatedPageContent)(dispatch, getState);
782
+ const updatedPageContent = {
783
+ ...editorContent,
784
+ template: {
785
+ ...editorContent.template,
786
+ ...updatedSections,
787
+ },
788
+ };
777
789
 
778
- const { sections: generatedSections } = getStateValues(getState);
779
- const lastModuleEditorID = getLastModuleEditorID(generatedSections, updatedSectionIndex);
790
+ generatePageContent(updatedPageContent)(dispatch, getState);
791
+
792
+ const { sections: generatedSections } = getStateValues(getState);
793
+ lastModuleEditorID = getLastModuleEditorID(generatedSections, updatedSectionIndex);
794
+ } else {
795
+ lastModuleEditorID = addElementToCollection(type, key, dispatch, getState);
796
+ }
780
797
 
781
798
  dispatch(setLastElementAddedId(lastModuleEditorID));
782
799
  localStorage.setItem("selectedID", `${lastModuleEditorID}`);
@@ -833,12 +850,17 @@ function deleteModule(editorID: number[], key?: string): (dispatch: Dispatch, ge
833
850
  return (dispatch, getState) => {
834
851
  const { sections, editorContent, errors } = getStateValues(getState);
835
852
 
836
- const updatedSections: any = [...sections];
837
- const { parent, grandParent } = findByEditorID(updatedSections, editorID[0]);
838
- const parentModule = Array.isArray(parent) ? grandParent : parent;
853
+ let itemsArr: IModule[] = [];
854
+ if (sections.length) {
855
+ const updatedSections: any = [...sections];
856
+ const { parent, grandParent } = findByEditorID(updatedSections, editorID[0]);
857
+ const parentModule = Array.isArray(parent) ? grandParent : parent;
839
858
 
840
- const parentKey = key ? key : getParentKey(parentModule, editorID[0]);
841
- const itemsArr = parentModule[parentKey];
859
+ const parentKey = key ? key : getParentKey(parentModule, editorID[0]);
860
+ itemsArr = parentModule[parentKey];
861
+ } else {
862
+ itemsArr = editorContent.template[key as string];
863
+ }
842
864
 
843
865
  editorID.forEach((moduleID) => {
844
866
  const index = itemsArr.findIndex((module: IModule) => module.editorID === moduleID);
@@ -863,7 +885,7 @@ function duplicateModule(editorID: number[], key?: string): (dispatch: Dispatch,
863
885
  return (dispatch, getState) => {
864
886
  const { sections, editorContent } = getStateValues(getState);
865
887
 
866
- const updatedSections: any = [...sections];
888
+ const updatedSections: any[] = sections.length ? [...sections] : [editorContent.template];
867
889
 
868
890
  const { parent, grandParent } = findByEditorID(updatedSections, editorID[0]);
869
891
  const parentModule = Array.isArray(parent) ? grandParent : parent;
@@ -891,9 +913,10 @@ function duplicateModule(editorID: number[], key?: string): (dispatch: Dispatch,
891
913
 
892
914
  generatePageContent(updatedPageContent)(dispatch, getState);
893
915
 
894
- const { sections: generatedSections } = getStateValues(getState);
916
+ const { sections: generatedSections, editorContent: generatedEditor } = getStateValues(getState);
917
+ const generatedContent = generatedSections.length ? generatedSections : generatedEditor.template;
895
918
  const { parent: generatedParent, grandParent: generatedGrandParent } = findByEditorID(
896
- generatedSections,
919
+ generatedContent,
897
920
  editorID[0]
898
921
  );
899
922
  const section = Array.isArray(generatedParent) ? generatedGrandParent : generatedParent;
@@ -907,11 +930,12 @@ function duplicateModule(editorID: number[], key?: string): (dispatch: Dispatch,
907
930
 
908
931
  function copyModule(editorID: number[]): (dispatch: Dispatch, getState: () => IRootState) => boolean | number {
909
932
  return (dispatch, getState) => {
910
- const { sections } = getStateValues(getState);
933
+ const { sections, editorContent } = getStateValues(getState);
911
934
  const modulesToCopy: Record<string, unknown>[] = [];
912
935
 
936
+ const content = sections.length ? sections : editorContent.template;
913
937
  editorID.forEach((id) => {
914
- const { element: originalElement } = findByEditorID(sections, id);
938
+ const { element: originalElement } = findByEditorID(content, id);
915
939
  if (originalElement) {
916
940
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
917
941
  const { editorID, parentEditorID, ...element } = originalElement;
@@ -948,7 +972,7 @@ function pasteModule(
948
972
 
949
973
  const updatedSections: any = [...sections];
950
974
  const { element: originalElement } = findByEditorID(updatedSections, editorID);
951
- const itemsArr = originalElement[key];
975
+ const itemsArr = sections.length ? originalElement[key] : editorContent.template[key];
952
976
 
953
977
  let error: INotification | undefined;
954
978
 
@@ -994,8 +1018,9 @@ function pasteModule(
994
1018
 
995
1019
  generatePageContent(updatedPageContent)(dispatch, getState);
996
1020
 
997
- const { sections: generatedSections } = getStateValues(getState);
998
- const { element: generatedElement } = findByEditorID(generatedSections, editorID);
1021
+ const { sections: generatedSections, editorContent: generatedEditorContent } = getStateValues(getState);
1022
+ const generatedContent = generatedSections.length ? generatedSections : generatedEditorContent;
1023
+ const { element: generatedElement } = findByEditorID(generatedContent, editorID);
999
1024
  const pastedEditorID = generatedElement[key][itemsArr.length - 1].editorID;
1000
1025
 
1001
1026
  localStorage.setItem("selectedID", `${pastedEditorID}`);
@@ -1,5 +1,7 @@
1
- import { IIntegration, ISavePageParams } from "@ax/types";
2
- import { cleanContent, findByComponent } from "@ax/forms";
1
+ import { IIntegration, IRootState, ISavePageParams } from "@ax/types";
2
+ import { cleanContent, findByComponent, updateElementCollection } from "@ax/forms";
3
+ import { Dispatch } from "redux";
4
+ import { generatePageContent } from "./actions";
3
5
 
4
6
  const getPageParams = (getState: any): ISavePageParams => {
5
7
  const {
@@ -135,6 +137,18 @@ const protectFormKeys = (content: any, key: string) => {
135
137
  return content;
136
138
  };
137
139
 
140
+ const addElementToCollection = (type: string, key: string, dispatch: Dispatch, getState: () => IRootState) => {
141
+ const { editorContent } = getStateValues(getState);
142
+ const updatedComponent = updateElementCollection(type, editorContent.template[key]);
143
+ const updatedPageContent = { ...editorContent, template: { ...editorContent.template, [key]: updatedComponent } };
144
+ generatePageContent(updatedPageContent)(dispatch, getState);
145
+
146
+ const { editorContent: generatedEditor } = getStateValues(getState);
147
+ const generatedElement = generatedEditor.template[key];
148
+ const lastModuleEditorID = generatedElement[generatedElement.length - 1].editorID as number;
149
+ return lastModuleEditorID;
150
+ };
151
+
138
152
  export {
139
153
  getPageParams,
140
154
  getPageData,
@@ -143,4 +157,5 @@ export {
143
157
  getDefaultIntegrations,
144
158
  getDefaultPageNavigation,
145
159
  protectFormKeys,
160
+ addElementToCollection,
146
161
  };
@@ -27,6 +27,7 @@ const DEFAULT_PARAMS = {
27
27
  pagination: true,
28
28
  deleted: false,
29
29
  include_draft: true,
30
+ relatedFields: true,
30
31
  };
31
32
 
32
33
  export {
@@ -149,8 +149,9 @@ const getLastModuleEditorID = (sections: any, sectionIndex: number) => {
149
149
  return updatedModules[lastModuleIndex].editorID;
150
150
  };
151
151
 
152
- const getLastComponentEditorID = (sections: any, parentEditorID: number, key: string) => {
152
+ const getLastComponentEditorID = (sections: any, parentEditorID: number, key: string): number | null => {
153
153
  const { element: module } = findByEditorID(sections, parentEditorID);
154
+ if (!module || module[key] === undefined) return null;
154
155
  const lastElementIndex = module[key].length - 1;
155
156
  return module[key][lastElementIndex].editorID;
156
157
  };
@@ -4,7 +4,7 @@ import { IComponent, IModule } from "@ax/types";
4
4
 
5
5
  const updateElementCollection = (elementType: string, prevCollection: any[]) => {
6
6
  const newElement = getDefaultSchema(elementType);
7
- return [...prevCollection, newElement];
7
+ return prevCollection ? [...prevCollection, newElement] : [newElement];
8
8
  };
9
9
 
10
10
  const addElement = (componentType: IComponent) => {
@@ -175,8 +175,7 @@ const moveModule = (params: IMoveElementParams) => {
175
175
  const isPage = ["Page", "GlobalPage"].includes(selectedContent.component);
176
176
  let newContent;
177
177
  if (isPage) {
178
- const { modules } = content;
179
- const newModules = moveElement(elementID, modules, newIndex);
178
+ const newModules = moveElement(elementID, content[key], newIndex);
180
179
  const { template } = selectedContent;
181
180
  const selectedSection = Object.keys(template).find(
182
181
  (key: string) => template[key] && template[key].editorID === content.editorID
@@ -192,7 +191,13 @@ const moveModule = (params: IMoveElementParams) => {
192
191
  },
193
192
  },
194
193
  }
195
- : null;
194
+ : {
195
+ ...selectedContent,
196
+ template: {
197
+ ...selectedContent.template,
198
+ [key]: newModules,
199
+ },
200
+ };
196
201
  } else {
197
202
  const contentElements = content[key];
198
203
  const { template } = page;
@@ -240,4 +245,5 @@ export {
240
245
  moveElement,
241
246
  deleteComponent,
242
247
  replaceElements,
248
+ updateElementCollection,
243
249
  };
@@ -8,6 +8,7 @@ const getInnerFields = (
8
8
  selectedContent: IPage,
9
9
  isTemplateActivated: boolean,
10
10
  theme: string,
11
+ moduleCopy: { date: string; element: Record<string, unknown> } | null,
11
12
  parentDisabled?: boolean,
12
13
  site?: ISite,
13
14
  errors?: IErrorItem[],
@@ -28,6 +29,7 @@ const getInnerFields = (
28
29
  selectedContent,
29
30
  isTemplateActivated,
30
31
  theme,
32
+ moduleCopy,
31
33
  parentDisabled,
32
34
  site,
33
35
  errors,
@@ -51,6 +53,7 @@ const getInnerFields = (
51
53
  error={error}
52
54
  deleteError={deleteError}
53
55
  theme={theme}
56
+ moduleCopy={moduleCopy}
54
57
  />
55
58
  );
56
59
  })
@@ -24,6 +24,7 @@ import {
24
24
  moveElement,
25
25
  deleteComponent,
26
26
  replaceElements,
27
+ updateElementCollection,
27
28
  } from "./elements";
28
29
  import { getInnerFields, getStructuredDataInnerFields } from "./fields";
29
30
  import {
@@ -69,4 +70,5 @@ export {
69
70
  checkMaxModules,
70
71
  evaluateComputedFields,
71
72
  findByComponent,
73
+ updateElementCollection,
72
74
  };
@@ -84,7 +84,7 @@ import { getFieldByPath } from "./fields";
84
84
 
85
85
  import { formatBytes, imageToBase64, getImageFromHtml, getImageFromIFrame } from "./images";
86
86
 
87
- import { isReqOk, handleRequest } from "./requests";
87
+ import { isReqOk, handleRequest, delay } from "./requests";
88
88
 
89
89
  import {
90
90
  dateToString,
@@ -232,4 +232,5 @@ export {
232
232
  updateColumns,
233
233
  findObjectValue,
234
234
  removeDuplicatesByProperty,
235
+ delay,
235
236
  };
@@ -33,4 +33,6 @@ function handleRequest(
33
33
  };
34
34
  }
35
35
 
36
- export { isReqOk, handleRequest };
36
+ const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
37
+
38
+ export { isReqOk, handleRequest, delay };
@@ -15,6 +15,7 @@ import {
15
15
  IDataPack,
16
16
  ILanguage,
17
17
  ISchemaField,
18
+ IRootState,
18
19
  } from "@ax/types";
19
20
  import { pageStatus, ISetCurrentPageIDAction } from "@ax/containers/PageEditor/interfaces";
20
21
  import {
@@ -56,6 +57,7 @@ const PageItem = (props: IPageItemProps): JSX.Element => {
56
57
  hoverCheck,
57
58
  createNewTranslation,
58
59
  setLanguage,
60
+ isSaving,
59
61
  } = props;
60
62
  const { isSelected, siteLanguages, page, lang, isDuplicable } = item;
61
63
  const {
@@ -299,7 +301,7 @@ const PageItem = (props: IPageItemProps): JSX.Element => {
299
301
  const mainModalAction = {
300
302
  title: "Duplicate",
301
303
  onClick: handleDuplicatePage,
302
- disabled: !modalState.title.trim() || !modalState.slug.trim(),
304
+ disabled: !modalState.title.trim() || !modalState.slug.trim() || isSaving,
303
305
  };
304
306
  const secondaryModalAction = { title: "Cancel", onClick: handleCloseDuplicate };
305
307
 
@@ -490,7 +492,7 @@ const PageItem = (props: IPageItemProps): JSX.Element => {
490
492
 
491
493
  const CategoryColumns = categoryColumns.map((col) => {
492
494
  if (!activeColumns.includes(col.key)) {
493
- return <></>;
495
+ return <React.Fragment key={col.key} />;
494
496
  }
495
497
 
496
498
  const type: any = structuredDataContent && structuredDataContent[col.key];
@@ -721,11 +723,16 @@ interface IPageItemProps {
721
723
  hoverCheck?: boolean;
722
724
  createNewTranslation(isNewTranslation: boolean): void;
723
725
  setLanguage(lang: { locale: string; id: number | null }): void;
726
+ isSaving: boolean;
724
727
  }
725
728
 
729
+ const mapStateToProps = (state: IRootState) => ({
730
+ isSaving: state.app.isSaving,
731
+ });
732
+
726
733
  const mapDispatchToProps = {
727
734
  createNewTranslation: pageEditorActions.createNewTranslation,
728
735
  setLanguage: appActions.setLanguage,
729
736
  };
730
737
 
731
- export default connect(null, mapDispatchToProps)(PageItem);
738
+ export default connect(mapStateToProps, mapDispatchToProps)(PageItem);
@@ -37,7 +37,17 @@ const Field = (props: IFieldProps): JSX.Element => {
37
37
 
38
38
  if (isGroup || isConditional || isArrayGroup) {
39
39
  const innerActions = { ...actions, updateValue, goTo };
40
- innerFields = getInnerFields(field.fields, innerActions, selectedContent, true, theme, disabled, site, errors);
40
+ innerFields = getInnerFields(
41
+ field.fields,
42
+ innerActions,
43
+ selectedContent,
44
+ true,
45
+ theme,
46
+ moduleCopy,
47
+ disabled,
48
+ site,
49
+ errors
50
+ );
41
51
  }
42
52
 
43
53
  return isGroup ? (
@@ -11,6 +11,7 @@ import {
11
11
  IPage,
12
12
  IColumn,
13
13
  ISchemaField,
14
+ IRootState,
14
15
  } from "@ax/types";
15
16
  import { getHumanLastModifiedDate, getScheduleFormatDate, getStructuredDataTitle, trimText } from "@ax/helpers";
16
17
  import { appActions } from "@ax/containers/App";
@@ -62,6 +63,7 @@ const GlobalPageItem = (props: IGlobalPageItemProps): JSX.Element => {
62
63
  addCategoryColors,
63
64
  skipReview,
64
65
  hoverCheck,
66
+ isSaving,
65
67
  } = props;
66
68
 
67
69
  const { locale } = lang;
@@ -287,7 +289,7 @@ const GlobalPageItem = (props: IGlobalPageItemProps): JSX.Element => {
287
289
  const mainDuplicateModalAction = {
288
290
  title: "Duplicate",
289
291
  onClick: handleDuplicatePage,
290
- disabled: !duplicateModalState.title.trim() || !duplicateModalState.slug.trim(),
292
+ disabled: !duplicateModalState.title.trim() || !duplicateModalState.slug.trim() || isSaving,
291
293
  };
292
294
  const secondaryDuplicateModalAction = { title: "Cancel", onClick: toggleDuplicateModal };
293
295
 
@@ -368,7 +370,7 @@ const GlobalPageItem = (props: IGlobalPageItemProps): JSX.Element => {
368
370
 
369
371
  const CategoryColumns = categoryColumns.map((col) => {
370
372
  if (!activeColumns.includes(col.key)) {
371
- return <></>;
373
+ return <React.Fragment key={col.key} />;
372
374
  }
373
375
 
374
376
  const type: any = structuredDataContent && structuredDataContent[col.key];
@@ -514,8 +516,13 @@ interface IGlobalPageItemProps {
514
516
  addCategoryColors(cats: string[]): void;
515
517
  skipReview?: boolean;
516
518
  hoverCheck?: boolean;
519
+ isSaving: boolean;
517
520
  }
518
521
 
522
+ const mapStateToProps = (state: IRootState) => ({
523
+ isSaving: state.app.isSaving,
524
+ });
525
+
519
526
  const mapDispatchToProps = {
520
527
  setLanguage: appActions.setLanguage,
521
528
  updatePageStatus: pageEditorActions.updatePageStatus,
@@ -529,4 +536,4 @@ const mapDispatchToProps = {
529
536
  deleteBulk: pageEditorActions.deleteBulk,
530
537
  };
531
538
 
532
- export default connect(null, mapDispatchToProps)(GlobalPageItem);
539
+ export default connect(mapStateToProps, mapDispatchToProps)(GlobalPageItem);
@@ -213,7 +213,7 @@ const StructuredDataItem = (props: IStructuredDataItemProps): JSX.Element => {
213
213
 
214
214
  const CategoryColumns = categoryColumns.map((col) => {
215
215
  if (!activeColumns.includes(col.key)) {
216
- return <></>;
216
+ return <React.Fragment key={col.key} />;
217
217
  }
218
218
 
219
219
  const type: any = structuredData && structuredData.content && structuredData.content[col.key];