@griddo/ax 1.51.1 → 1.51.2

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": "1.51.1",
4
+ "version": "1.51.2",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -232,5 +232,5 @@
232
232
  "publishConfig": {
233
233
  "access": "public"
234
234
  },
235
- "gitHead": "db3b9481ca1ef33aad641cf6b693356055e9dedc"
235
+ "gitHead": "137fb5810ec6523db7745a43f77e47484611441b"
236
236
  }
@@ -4,7 +4,7 @@ import { IModule } from "@ax/types";
4
4
  import { ComponentContainer } from "@ax/components";
5
5
 
6
6
  import AddItemButton from "./AddItemButton";
7
- import { getComponentProps, containerToComponentArray } from "../helpers";
7
+ import { getComponentProps, containerToComponentArray, getTypefromKey } from "../helpers";
8
8
 
9
9
  import * as S from "./style";
10
10
 
@@ -21,8 +21,13 @@ const MixableComponentArray = (props: IMixableComponentArrayProps): JSX.Element
21
21
  maxItems,
22
22
  disabled,
23
23
  activatedModules,
24
+ objKey,
25
+ field,
24
26
  } = props;
25
27
 
28
+ const type = getTypefromKey(objKey);
29
+ const { contentType = type } = field;
30
+
26
31
  let addModuleAction: any;
27
32
  let addComponentAction: any;
28
33
 
@@ -38,14 +43,12 @@ const MixableComponentArray = (props: IMixableComponentArrayProps): JSX.Element
38
43
  return fixedValue.length > 1 ? `#${index + 1} ${name}` : name;
39
44
  };
40
45
 
41
- const { elements, componentModules } = selectedContent;
42
-
43
- const isComponentModule = !!componentModules;
44
- const isModuleArr = !elements && !isComponentModule;
46
+ const isComponentModule = contentType === "components";
47
+ const isModuleArr = contentType === "modules";
45
48
 
46
49
  const handleAddModule = (moduleType: string) => addModuleAction(moduleType, editorID, isComponentModule);
47
50
 
48
- const handleAddComponent = (componentType: string) => addComponentAction && addComponentAction(componentType);
51
+ const handleAddComponent = (componentType: string) => addComponentAction && addComponentAction(componentType, objKey);
49
52
 
50
53
  const handleAdd = isModuleArr ? handleAddModule : handleAddComponent;
51
54
 
@@ -90,6 +93,7 @@ const MixableComponentArray = (props: IMixableComponentArrayProps): JSX.Element
90
93
  selectedContent={selectedContent}
91
94
  disabled={disabled}
92
95
  canDuplicate={showAddItemButton && !isModuleDeactivated}
96
+ parentKey={objKey}
93
97
  />
94
98
  );
95
99
  })}
@@ -109,6 +113,8 @@ export interface IMixableComponentArrayProps {
109
113
  categories?: any;
110
114
  disabled?: boolean;
111
115
  activatedModules: string[];
116
+ objKey: string;
117
+ field: any;
112
118
  }
113
119
 
114
120
  export default MixableComponentArray;
@@ -4,7 +4,7 @@ import { IModule } from "@ax/types";
4
4
  import { ComponentContainer } from "@ax/components";
5
5
 
6
6
  import AddItemButton from "./AddItemButton";
7
- import { getComponentProps } from "../helpers";
7
+ import { getComponentProps, getTypefromKey } from "../helpers";
8
8
 
9
9
  import * as S from "./style";
10
10
 
@@ -21,8 +21,13 @@ const SameComponentArray = (props: ISameComponentArrayProps): JSX.Element => {
21
21
  maxItems,
22
22
  disabled,
23
23
  activatedModules,
24
+ objKey,
25
+ field,
24
26
  } = props;
25
27
 
28
+ const type = getTypefromKey(objKey);
29
+ const { contentType = type } = field;
30
+
26
31
  let addModuleAction: any;
27
32
  let addComponentAction: any;
28
33
 
@@ -35,14 +40,14 @@ const SameComponentArray = (props: ISameComponentArrayProps): JSX.Element => {
35
40
  return value.length > 1 ? `#${index + 1} ${name}` : name;
36
41
  };
37
42
 
38
- const { elements, componentModules, kind } = selectedContent;
43
+ const { kind } = selectedContent;
39
44
 
40
- const isModuleArr = !elements;
41
- const isComponentModule = !!componentModules;
45
+ const isModuleArr = contentType === "modules";
46
+ const isComponentModule = contentType === "components";
42
47
 
43
48
  const handleAddModule = (moduleType: string) => addModuleAction(moduleType, editorID, isComponentModule);
44
49
 
45
- const handleAddComponent = () => addComponentAction && addComponentAction(kind);
50
+ const handleAddComponent = () => addComponentAction && addComponentAction(kind, objKey);
46
51
 
47
52
  const handleAdd = isModuleArr ? handleAddModule : handleAddComponent;
48
53
 
@@ -82,6 +87,7 @@ const SameComponentArray = (props: ISameComponentArrayProps): JSX.Element => {
82
87
  selectedContent={selectedContent}
83
88
  disabled={disabled}
84
89
  canDuplicate={showAddItemButton && !isModuleDeactivated}
90
+ parentKey={objKey}
85
91
  />
86
92
  );
87
93
  })}
@@ -102,6 +108,8 @@ export interface ISameComponentArrayProps {
102
108
  categories?: any;
103
109
  disabled?: boolean;
104
110
  activatedModules: string[];
111
+ objKey: string;
112
+ field: any;
105
113
  }
106
114
 
107
115
  export default SameComponentArray;
@@ -29,4 +29,16 @@ const getComponentProps = (element: any, activatedModules: string[], isModuleArr
29
29
  const containerToComponentArray = (value: Record<string, IComponent>): IComponent[] =>
30
30
  Object.values(value).filter((item: IComponent) => !isComponentEmpty(item));
31
31
 
32
- export { getComponentTitle, getComponentProps, containerToComponentArray };
32
+ const getTypefromKey = (key: string) => {
33
+ switch (key) {
34
+ case "elements":
35
+ case "componentModules":
36
+ return "components";
37
+ case "modules":
38
+ return key;
39
+ default:
40
+ return null;
41
+ }
42
+ };
43
+
44
+ export { getComponentTitle, getComponentProps, containerToComponentArray, getTypefromKey };
@@ -26,6 +26,7 @@ const ComponentContainer = (props: IComponentContainerProps): JSX.Element => {
26
26
  arrayLength,
27
27
  disabled,
28
28
  canDuplicate,
29
+ parentKey,
29
30
  } = props;
30
31
 
31
32
  let deleteModuleAction: any;
@@ -65,8 +66,8 @@ const ComponentContainer = (props: IComponentContainerProps): JSX.Element => {
65
66
  }
66
67
  };
67
68
 
68
- const removeItem = () => deleteModuleAction(editorID);
69
- const duplicateItem = () => duplicateModuleAction(editorID);
69
+ const removeItem = () => deleteModuleAction(editorID, parentKey);
70
+ const duplicateItem = () => parentKey && duplicateModuleAction(editorID, parentKey);
70
71
 
71
72
  const duplicateOpt = {
72
73
  label: "duplicate",
@@ -99,7 +100,7 @@ const ComponentContainer = (props: IComponentContainerProps): JSX.Element => {
99
100
  const moveModule = (e: any, isPush: boolean) => {
100
101
  e.preventDefault();
101
102
  e.stopPropagation();
102
- moveModuleAction(editorID, selectedContent, isPush);
103
+ moveModuleAction(editorID, selectedContent, isPush, parentKey);
103
104
  };
104
105
 
105
106
  const handleOptionClick = (option: any) => actions.addComponentAction(option);
@@ -177,6 +178,7 @@ interface IComponentContainerProps {
177
178
  arrayLength: number;
178
179
  disabled?: boolean;
179
180
  canDuplicate?: boolean;
181
+ parentKey?: string;
180
182
  }
181
183
 
182
184
  export default ComponentContainer;
@@ -4,16 +4,8 @@ import { IconAction, VisualOption } from "@ax/components";
4
4
 
5
5
  import * as S from "./style";
6
6
 
7
- const ScrollableSelection = ({
8
- value,
9
- onChange,
10
- actions,
11
- options,
12
- objKey,
13
- columns,
14
- disabled,
15
- ...props
16
- }: IScrollableSelectionProps): JSX.Element => {
7
+ const ScrollableSelection = (props: IScrollableSelectionProps): JSX.Element => {
8
+ const { value, onChange, actions, options, objKey, columns, disabled, reference } = props;
17
9
  const [carouselIndex, setCarouselIndex] = useState(0);
18
10
  const [carouselItemWidth, setCarouselItemWidth] = useState<number>();
19
11
  const carouselRef = useRef<HTMLDivElement>(null);
@@ -22,7 +14,7 @@ const ScrollableSelection = ({
22
14
 
23
15
  const handleSelection = (newValue: string) => {
24
16
  onChange(newValue);
25
- actions.replaceElementsInCollectionAction(newValue);
17
+ actions.replaceElementsInCollectionAction(newValue, reference);
26
18
  };
27
19
 
28
20
  const handlePreviousPage = () => {
@@ -90,6 +82,7 @@ interface IScrollableSelectionProps {
90
82
  disabled?: boolean;
91
83
  actions: any;
92
84
  selectedContent: any;
85
+ reference?: string;
93
86
  }
94
87
 
95
88
  interface IScrollableUniqueSelectionFieldOptionsProps {
@@ -31,6 +31,7 @@ const AppBar = (props: IProps): JSX.Element => {
31
31
  currentPageUrl,
32
32
  errors,
33
33
  errorActions,
34
+ isFromEditor,
34
35
  } = props;
35
36
 
36
37
  const publishedTooltip: any = {
@@ -43,7 +44,7 @@ const AppBar = (props: IProps): JSX.Element => {
43
44
  const fixedClass = fixedAppBar ? "fixed" : "";
44
45
 
45
46
  const goToPages = () => {
46
- typeof backLink === "string" ? props.history.push(backLink) : props.history.goBack();
47
+ typeof backLink === "string" ? props.history.push(backLink, { isFromEditor }) : props.history.goBack();
47
48
  };
48
49
 
49
50
  const getCurrentLanguage = (lang: string) =>
@@ -251,6 +252,7 @@ interface IAppBarProps {
251
252
  errorActions?: {
252
253
  goToError(editorID: number, tab: string, template: boolean): void;
253
254
  };
255
+ isFromEditor?: boolean;
254
256
  }
255
257
 
256
258
  type IProps = IAppBarProps & RouteComponentProps;
@@ -35,6 +35,7 @@ interface IWrapperProps {
35
35
  currentPageID?: number;
36
36
  currentPageUrl?: string;
37
37
  fullWidth?: boolean;
38
+ isFromEditor?: boolean;
38
39
  languageActions?: {
39
40
  setLanguage?(lang: { locale: string; id: number | null }): void;
40
41
  setIsNewTranslation?(isNewTranslation: boolean): void;
@@ -4,11 +4,11 @@ import { navigation } from "@ax/api";
4
4
  import { IBreadcrumbItem, ISchema } from "@ax/types";
5
5
  import { getDefaultSchema, getSchema, handleRequest, removeEditorIds, deepClone, getNullValue } from "@ax/helpers";
6
6
  import {
7
- deleteComponent,
8
7
  findByEditorID,
9
8
  generateEditorIDs,
10
9
  getLastComponentEditorID,
11
10
  getNewBreadcrumb,
11
+ getParentKey,
12
12
  moveElement,
13
13
  replaceElements,
14
14
  setIsSavedData,
@@ -441,7 +441,7 @@ const updateCollection = (elementType: string, prevCollection: any[]) => {
441
441
  return [...prevCollection, newModule];
442
442
  };
443
443
 
444
- const getUpdatedComponents = (editorContent: any, element: any) => {
444
+ const getUpdatedComponents = (editorContent: any, element: any, key: string) => {
445
445
  const { editorID, type } = element;
446
446
  const isCollectionItem = typeof type === "string";
447
447
  const updatedDefault = isCollectionItem ? deepClone(editorContent) : editorContent;
@@ -449,7 +449,7 @@ const getUpdatedComponents = (editorContent: any, element: any) => {
449
449
  const mapValues = (item: any) => {
450
450
  if (item.editorID !== undefined && item.editorID === editorID) {
451
451
  if (isCollectionItem) {
452
- item.elements = updateCollection(type, item.elements);
452
+ item[key] = updateCollection(type, item[key]);
453
453
  } else {
454
454
  addElement(type);
455
455
  }
@@ -468,41 +468,39 @@ const getUpdatedComponents = (editorContent: any, element: any) => {
468
468
  return updatedDefault;
469
469
  };
470
470
 
471
- function addComponent(type: any): (dispatch: Dispatch, getState: any) => void {
471
+ function addComponent(type: any, key: string): (dispatch: Dispatch, getState: any) => void {
472
472
  return (dispatch, getState) => {
473
473
  const { editorContent, selectedEditorID } = getStateValues(getState);
474
474
  const component = {
475
475
  editorID: selectedEditorID,
476
476
  type,
477
477
  };
478
- const updatedContent = getUpdatedComponents(editorContent, component);
478
+ const updatedContent = getUpdatedComponents(editorContent, component, key);
479
479
  generateContent(updatedContent, dispatch, getState);
480
480
 
481
481
  if (type.editorID) {
482
482
  setSelectedContent(type.editorID)(dispatch, getState);
483
483
  } else {
484
484
  const { editorContent } = getStateValues(getState);
485
- const lastElementEditorID = getLastComponentEditorID(editorContent, component.editorID);
485
+ const lastElementEditorID = getLastComponentEditorID(editorContent, component.editorID, key);
486
486
  setSelectedContent(lastElementEditorID)(dispatch, getState);
487
487
  }
488
488
  };
489
489
  }
490
490
 
491
- function deleteModule(editorID: number): (dispatch: Dispatch, getState: any) => void {
491
+ function deleteModule(editorID: number, key: string): (dispatch: Dispatch, getState: any) => void {
492
492
  return (dispatch, getState) => {
493
493
  const { editorContent } = getStateValues(getState);
494
494
  const updatedContent: any = deepClone(editorContent);
495
495
 
496
- updatedContent.elements = updatedContent.elements.filter((module: any) => {
497
- if (module.elements) {
498
- module.elements = deleteComponent(module.elements, editorID);
499
- }
500
- return module.editorID !== editorID;
501
- });
502
-
503
- const { parent, grandParent } = findByEditorID(editorContent, editorID);
496
+ const { parent, grandParent } = findByEditorID(updatedContent, editorID);
504
497
  const parentModule = Array.isArray(parent) ? grandParent : parent;
505
- setSelectedContent(parentModule.editorID)(dispatch, getState);
498
+
499
+ const parentKey = key ? key : getParentKey(parentModule, editorID);
500
+ const itemsArr = parentModule[parentKey];
501
+
502
+ const index = itemsArr.findIndex((module: any) => module.editorID === editorID);
503
+ itemsArr.splice(index, 1);
506
504
 
507
505
  generateContent(updatedContent, dispatch, getState);
508
506
  };
@@ -530,7 +528,7 @@ function replaceModule(module: any, parent: any, objKey: string): (dispatch: Dis
530
528
  };
531
529
  }
532
530
 
533
- function duplicateModule(editorID: number): (dispatch: Dispatch, getState: any) => void {
531
+ function duplicateModule(editorID: number, key?: string): (dispatch: Dispatch, getState: any) => void {
534
532
  return (dispatch, getState) => {
535
533
  const { editorContent } = getStateValues(getState);
536
534
 
@@ -538,33 +536,39 @@ function duplicateModule(editorID: number): (dispatch: Dispatch, getState: any)
538
536
  const { element: originalItem, parent, grandParent } = findByEditorID(updatedContent, editorID);
539
537
  const parentModule = Array.isArray(parent) ? grandParent : parent;
540
538
 
541
- const { elements } = parentModule;
539
+ const parentKey = key ? key : getParentKey(parentModule, editorID);
540
+ const itemsArr = parentModule[parentKey];
542
541
 
543
- const originalItemIndex = elements.findIndex((module: any) => module.editorID === editorID);
542
+ const originalItemIndex = itemsArr.findIndex((module: any) => module.editorID === editorID);
544
543
  const duplicatedItemIndex = originalItemIndex + 1;
545
- elements.splice(duplicatedItemIndex, 0, originalItem);
544
+ itemsArr.splice(duplicatedItemIndex, 0, originalItem);
546
545
 
547
546
  generateContent(updatedContent, dispatch, getState);
548
547
 
549
548
  const { editorContent: generatedContent } = getStateValues(getState);
550
549
  const { parent: generatedParent, grandParent: generatedGrandParent } = findByEditorID(generatedContent, editorID);
551
550
  const module = Array.isArray(generatedParent) ? generatedGrandParent : generatedParent;
552
- const duplicatedEditorID = module.elements[duplicatedItemIndex].editorID;
551
+ const duplicatedEditorID = module[parentKey][duplicatedItemIndex].editorID;
553
552
 
554
553
  setSelectedContent(duplicatedEditorID)(dispatch, getState);
555
554
  };
556
555
  }
557
556
 
558
- function moveModule(elementID: number, content: any, isPush: boolean): (dispatch: Dispatch, getState: any) => void {
557
+ function moveModule(
558
+ elementID: number,
559
+ content: any,
560
+ isPush: boolean,
561
+ key: string
562
+ ): (dispatch: Dispatch, getState: any) => void {
559
563
  return async (dispatch, getState) => {
560
564
  try {
561
565
  const {
562
566
  navigation: { selectedContent, editorContent },
563
567
  } = getState();
564
568
 
565
- const contentElements = [...selectedContent.elements];
569
+ const contentElements = [...selectedContent[key]];
566
570
  const { element: selectedModule } = findByEditorID(editorContent, selectedContent.editorID);
567
- selectedModule.elements = moveElement(elementID, contentElements, isPush);
571
+ selectedModule[key] = moveElement(elementID, contentElements, isPush);
568
572
 
569
573
  generateContent(editorContent, dispatch, getState);
570
574
  } catch {
@@ -573,13 +577,14 @@ function moveModule(elementID: number, content: any, isPush: boolean): (dispatch
573
577
  };
574
578
  }
575
579
 
576
- function replaceElementsInCollection(newValue: string): (dispatch: Dispatch, getState: any) => void {
580
+ function replaceElementsInCollection(newValue: string, reference: string): (dispatch: Dispatch, getState: any) => void {
577
581
  return async (dispatch, getState) => {
578
582
  const { selectedContent } = getStateValues(getState);
583
+ const key = reference ? reference : "elements";
579
584
 
580
- const updatedContent = replaceElements(selectedContent.elements, newValue);
585
+ const updatedContent = replaceElements(selectedContent[key], newValue);
581
586
 
582
- updateEditorContent(selectedContent.editorID, "elements", updatedContent)(dispatch, getState);
587
+ updateEditorContent(selectedContent.editorID, key, updatedContent)(dispatch, getState);
583
588
  };
584
589
  }
585
590
 
@@ -15,7 +15,6 @@ import {
15
15
  getUpdatedComponents,
16
16
  getUpdatedSections,
17
17
  updateComponent,
18
- deleteModules,
19
18
  updateByEditorID,
20
19
  findByEditorID,
21
20
  generateEditorIDs,
@@ -26,6 +25,7 @@ import {
26
25
  getLastComponentEditorID,
27
26
  replaceElements,
28
27
  findMandatoryFieldsErrors,
28
+ getParentKey,
29
29
  } from "@ax/forms";
30
30
  import { appActions } from "@ax/containers/App";
31
31
  import { navigationActions } from "@ax/containers/Navigation";
@@ -462,7 +462,7 @@ function addTemplate(template: string): (dispatch: Dispatch) => Promise<void> {
462
462
  };
463
463
  }
464
464
 
465
- function addComponent(type: any): (dispatch: Dispatch, getState: any) => void {
465
+ function addComponent(type: any, key: string): (dispatch: Dispatch, getState: any) => void {
466
466
  return (dispatch, getState) => {
467
467
  const { editorContent, sections, editorID } = getStateValues(getState);
468
468
  const component = {
@@ -470,7 +470,7 @@ function addComponent(type: any): (dispatch: Dispatch, getState: any) => void {
470
470
  type,
471
471
  };
472
472
 
473
- const updatedObj = getUpdatedComponents(sections, component);
473
+ const updatedObj = getUpdatedComponents(sections, component, key);
474
474
  const updatedSections = updatedObj.updatedSections;
475
475
 
476
476
  const updatedPageContent = {
@@ -487,7 +487,7 @@ function addComponent(type: any): (dispatch: Dispatch, getState: any) => void {
487
487
  setSelectedContent(type.editorID)(dispatch, getState);
488
488
  } else {
489
489
  const { sections: generatedSections } = getStateValues(getState);
490
- const lastElementEditorID = getLastComponentEditorID(generatedSections, component.editorID);
490
+ const lastElementEditorID = getLastComponentEditorID(generatedSections, component.editorID, key);
491
491
  setSelectedContent(lastElementEditorID)(dispatch, getState);
492
492
  }
493
493
  };
@@ -496,6 +496,7 @@ function addComponent(type: any): (dispatch: Dispatch, getState: any) => void {
496
496
  function addModule(
497
497
  type: string,
498
498
  selectedID: number,
499
+ key: string,
499
500
  isComponentModule?: boolean
500
501
  ): (dispatch: Dispatch, getState: any) => void {
501
502
  return (dispatch, getState) => {
@@ -509,7 +510,7 @@ function addModule(
509
510
  updatedSectionIndex = 0;
510
511
 
511
512
  if (isComponentModule) {
512
- const updatedObj = getUpdatedComponents(sections, componentModule);
513
+ const updatedObj = getUpdatedComponents(sections, componentModule, key);
513
514
  updatedSections = updatedObj.updatedSections;
514
515
  updatedSectionIndex = updatedObj.selectedIndex;
515
516
  } else {
@@ -557,33 +558,44 @@ function replaceModule(module: any, parent: any, objKey: string): (dispatch: Dis
557
558
  };
558
559
  }
559
560
 
560
- function replaceElementsInCollection(newValue: string): (dispatch: Dispatch, getState: any) => void {
561
+ function replaceElementsInCollection(newValue: string, reference: string): (dispatch: Dispatch, getState: any) => void {
561
562
  return async (dispatch, getState) => {
562
563
  const { selectedContent } = getStateValues(getState);
563
564
 
564
- const updatedContent = replaceElements(selectedContent.elements, newValue);
565
+ const key = reference ? reference : "elements";
566
+ const updatedContent = replaceElements(selectedContent[key], newValue);
565
567
 
566
- updateEditorContent(selectedContent.editorID, "elements", updatedContent)(dispatch, getState);
568
+ updateEditorContent(selectedContent.editorID, key, updatedContent)(dispatch, getState);
567
569
 
568
570
  const { editorContent } = getStateValues(getState);
569
571
  generatePageContent(editorContent, dispatch, getState);
570
572
  };
571
573
  }
572
574
 
573
- function deleteModule(editorID: number): (dispatch: Dispatch, getState: any) => void {
575
+ function deleteModule(editorID: number, key?: string): (dispatch: Dispatch, getState: any) => void {
574
576
  return (dispatch, getState) => {
575
- const { editorContent, sections } = getStateValues(getState);
576
- deleteModules(sections, editorID);
577
+ const { sections, editorContent } = getStateValues(getState);
578
+
579
+ const updatedSections: any = [...sections];
580
+ const { parent, grandParent } = findByEditorID(updatedSections, editorID);
581
+ const parentModule = Array.isArray(parent) ? grandParent : parent;
582
+
583
+ const parentKey = key ? key : getParentKey(parentModule, editorID);
584
+ const itemsArr = parentModule[parentKey];
585
+
586
+ const index = itemsArr.findIndex((module: any) => module.editorID === editorID);
587
+ itemsArr.splice(index, 1);
577
588
 
578
589
  const updatedPageContent = {
579
590
  ...editorContent,
591
+ sections: [...updatedSections],
580
592
  };
581
593
 
582
594
  generatePageContent(updatedPageContent, dispatch, getState);
583
595
  };
584
596
  }
585
597
 
586
- function duplicateModule(editorID: number): (dispatch: Dispatch, getState: any) => void {
598
+ function duplicateModule(editorID: number, key?: string): (dispatch: Dispatch, getState: any) => void {
587
599
  return (dispatch, getState) => {
588
600
  const { sections, editorContent } = getStateValues(getState);
589
601
 
@@ -591,9 +603,8 @@ function duplicateModule(editorID: number): (dispatch: Dispatch, getState: any)
591
603
  const { element: originalItem, parent, grandParent } = findByEditorID(updatedSections, editorID);
592
604
  const parentModule = Array.isArray(parent) ? grandParent : parent;
593
605
 
594
- const { modules, elements, componentModules } = parentModule;
595
-
596
- const itemsArr = modules ? modules : elements ? elements : componentModules;
606
+ const parentKey = key ? key : getParentKey(parentModule, editorID);
607
+ const itemsArr = parentModule[parentKey];
597
608
 
598
609
  const originalItemIndex = itemsArr.findIndex((module: any) => module.editorID === editorID);
599
610
  const duplicatedItemIndex = originalItemIndex + 1;
@@ -609,11 +620,7 @@ function duplicateModule(editorID: number): (dispatch: Dispatch, getState: any)
609
620
  const { sections: generatedSections } = getStateValues(getState);
610
621
  const { parent: generatedParent, grandParent: generatedGrandParent } = findByEditorID(generatedSections, editorID);
611
622
  const section = Array.isArray(generatedParent) ? generatedGrandParent : generatedParent;
612
- const duplicatedEditorID = modules
613
- ? section.modules[duplicatedItemIndex].editorID
614
- : elements
615
- ? section.elements[duplicatedItemIndex].editorID
616
- : section.componentModules[duplicatedItemIndex].editorID;
623
+ const duplicatedEditorID = section[parentKey][duplicatedItemIndex].editorID;
617
624
 
618
625
  setSelectedContent(duplicatedEditorID)(dispatch, getState);
619
626
  };
@@ -773,7 +780,12 @@ function resetPageEditor(): (dispatch: Dispatch) => Promise<void> {
773
780
  };
774
781
  }
775
782
 
776
- function moveElement(elementID: number, content: any, isPush: boolean): (dispatch: Dispatch, getState: any) => void {
783
+ function moveElement(
784
+ elementID: number,
785
+ content: any,
786
+ isPush: boolean,
787
+ key: string
788
+ ): (dispatch: Dispatch, getState: any) => void {
777
789
  return async (dispatch, getState) => {
778
790
  try {
779
791
  const { selectedContent, editorContent } = getState().pageEditor;
@@ -783,6 +795,7 @@ function moveElement(elementID: number, content: any, isPush: boolean): (dispatc
783
795
  selectedContent,
784
796
  isPush,
785
797
  page: editorContent.editorContent,
798
+ key,
786
799
  });
787
800
 
788
801
  generatePageContent(newContent, dispatch, getState);
@@ -137,16 +137,23 @@ const getLastModuleEditorID = (sections: any, sectionIndex: number) => {
137
137
  return updatedModules[lastModuleIndex].editorID;
138
138
  };
139
139
 
140
- const getLastComponentEditorID = (sections: any, parentEditorID: number) => {
140
+ const getLastComponentEditorID = (sections: any, parentEditorID: number, key: string) => {
141
141
  const { element: module } = findByEditorID(sections, parentEditorID);
142
- if (module.elements) {
143
- const lastElementIndex = module.elements.length - 1;
144
- return module.elements[lastElementIndex].editorID;
145
- }
146
- if (module.componentModules) {
147
- const lastElementIndex = module.componentModules.length - 1;
148
- return module.componentModules[lastElementIndex].editorID;
149
- }
142
+ const lastElementIndex = module[key].length - 1;
143
+ return module[key][lastElementIndex].editorID;
144
+ };
145
+
146
+ const getParentKey = (parentModule: any, editorID: number) => {
147
+ let keyFound = "";
148
+ Object.keys(parentModule).forEach((objKey: any) => {
149
+ if (Array.isArray(parentModule[objKey])) {
150
+ const moduleFound = parentModule[objKey].find((module: any) => module.editorID === editorID);
151
+ if (moduleFound) {
152
+ keyFound = objKey;
153
+ }
154
+ }
155
+ });
156
+ return keyFound;
150
157
  };
151
158
 
152
159
  export {
@@ -161,4 +168,5 @@ export {
161
168
  cleanPageValues,
162
169
  getLastModuleEditorID,
163
170
  getLastComponentEditorID,
171
+ getParentKey,
164
172
  };
@@ -22,18 +22,16 @@ const updateComponent = (component: any, schema: any) => {
22
22
  }
23
23
  };
24
24
 
25
- const updateCollection = (type: string, item: any) =>
26
- item.elements
27
- ? (item.elements = updateElementCollection(type, item.elements))
28
- : (item.componentModules = updateElementCollection(type, item.componentModules));
25
+ const updateCollection = (type: string, item: any, key: string) =>
26
+ (item[key] = updateElementCollection(type, item[key]));
29
27
 
30
- const getUpdatedComponents = (sections: any, component: any) => {
28
+ const getUpdatedComponents = (sections: any, component: any, key: string) => {
31
29
  const { editorID, type } = component;
32
30
 
33
31
  const isCollectionItem = typeof type === "string";
34
32
  let selectedIndex = 0;
35
33
 
36
- const addItem = (item: any) => (isCollectionItem ? updateCollection(type, item) : addElement(type));
34
+ const addItem = (item: any) => (isCollectionItem ? updateCollection(type, item, key) : addElement(type));
37
35
 
38
36
  const sectionEntries = sections.map((section: any, index: number) => {
39
37
  const updatedModules = section.modules.map((module: any) => {
@@ -168,7 +166,7 @@ const moveElement = (elementID: number, arr: any[], isPush: boolean, idKey = "ed
168
166
  };
169
167
 
170
168
  const moveModule = (params: IMoveElementParams) => {
171
- const { elementID, content, selectedContent, isPush, page } = params;
169
+ const { elementID, content, selectedContent, isPush, page, key } = params;
172
170
  const isPage = ["Page", "GlobalPage"].includes(selectedContent.component);
173
171
  let newContent;
174
172
  if (isPage) {
@@ -191,15 +189,10 @@ const moveModule = (params: IMoveElementParams) => {
191
189
  }
192
190
  : null;
193
191
  } else {
194
- const { elements, componentModules } = content;
195
- const contentElements = componentModules ? componentModules : elements;
192
+ const contentElements = content[key];
196
193
  const { template } = page;
197
194
  const { element: selectedModule } = findByEditorID(page, selectedContent.editorID);
198
- if (componentModules) {
199
- selectedModule.componentModules = moveElement(elementID, contentElements, isPush);
200
- } else {
201
- selectedModule.elements = moveElement(elementID, contentElements, isPush);
202
- }
195
+ selectedModule[key] = moveElement(elementID, contentElements, isPush);
203
196
 
204
197
  newContent = {
205
198
  ...page,
@@ -229,6 +222,7 @@ interface IMoveElementParams {
229
222
  isPush: boolean;
230
223
  selectedContent: any;
231
224
  page: any;
225
+ key: string;
232
226
  }
233
227
 
234
228
  export {
@@ -9,6 +9,7 @@ import {
9
9
  cleanPageValues,
10
10
  getLastModuleEditorID,
11
11
  getLastComponentEditorID,
12
+ getParentKey,
12
13
  } from "./editor";
13
14
  import {
14
15
  getUpdatedComponents,
@@ -45,6 +46,7 @@ export {
45
46
  getInnerFields,
46
47
  getLastModuleEditorID,
47
48
  getLastComponentEditorID,
49
+ getParentKey,
48
50
  getValidity,
49
51
  findMandatoryFieldsErrors,
50
52
  };
@@ -1,5 +1,6 @@
1
1
  import React, { useEffect, useCallback, useState, useRef } from "react";
2
2
  import { connect } from "react-redux";
3
+ import { useLocation } from "react-router-dom";
3
4
 
4
5
  import { useModal, useBulkSelection, useToast } from "@ax/hooks";
5
6
  import {
@@ -86,6 +87,7 @@ const Content = (props: IProps): JSX.Element => {
86
87
  const { isOpen: isImporterOpen, toggleModal: toggleImporterModal } = useModal();
87
88
  const { sortedListStatus, setSortedListStatus } = useSortedListStatus();
88
89
  const { setFiltersSelection, setFilterQuery } = useFilterQuery();
90
+ const { state: locationState } = useLocation<{ isFromEditor: boolean }>();
89
91
 
90
92
  const currentFilter = getCurrentFilter(structuredData, filter);
91
93
  const checkFromPage = currentFilter ? currentFilter.fromPage : undefined;
@@ -189,7 +191,9 @@ const Content = (props: IProps): JSX.Element => {
189
191
  useEffect(() => setPage(firstPage), [filter]);
190
192
 
191
193
  useEffect(() => {
192
- setFilter("unique-pages");
194
+ if (!locationState || locationState.isFromEditor !== true) {
195
+ setFilter("unique-pages");
196
+ }
193
197
  resetPageEditor();
194
198
  // eslint-disable-next-line react-hooks/exhaustive-deps
195
199
  }, []);
@@ -73,13 +73,13 @@ interface IEditorStateProps {
73
73
  interface IPageBrowserDispatchProps {
74
74
  setSelectedContent(editorID: number): void;
75
75
  setSelectedTab(tab: string): void;
76
- deleteModule(editorID: number): void;
77
- duplicateModule(editorID: number): void;
78
- addComponent: (componentType: any) => void;
79
- addModule: (moduleType: string, selectedID: number) => void;
80
- moveElement(moduleID: number, selectedContent: any, isPush: boolean): void;
76
+ deleteModule(editorID: number, key: string): void;
77
+ duplicateModule(editorID: number, key: string): void;
78
+ addComponent: (componentType: any, key: string) => void;
79
+ addModule: (moduleType: string, selectedID: number, key: string) => void;
80
+ moveElement(moduleID: number, selectedContent: any, isPush: boolean, key: string): void;
81
81
  replaceModule(module: any, parent: any, objKey: string): void;
82
- replaceElementsInCollection(module: any, parent: any, objKey: string): void;
82
+ replaceElementsInCollection(newValue: string, reference: string): void;
83
83
  isGlobal: boolean;
84
84
  isEditable: boolean;
85
85
  }
@@ -221,6 +221,7 @@ const GlobalEditor = (props: IProps) => {
221
221
  errors={errors}
222
222
  errorActions={{ goToError }}
223
223
  inversed={true}
224
+ isFromEditor={true}
224
225
  >
225
226
  {errors.length > 0 && (
226
227
  <S.NotificationWrapper>
@@ -68,12 +68,12 @@ interface IEditorStateProps {
68
68
  interface IPageBrowserDispatchProps {
69
69
  setSelectedContent(editorID: number): void;
70
70
  setSelectedTab(tab: string): void;
71
- deleteModule(editorID: number): void;
72
- duplicateModule(editorID: number): void;
73
- addComponent: (componentType: any) => void;
71
+ deleteModule(editorID: number, key: string): void;
72
+ duplicateModule(editorID: number, key: string): void;
73
+ addComponent: (componentType: any, key: string) => void;
74
74
  replaceModule(module: any, parent: any, objKey: string): void;
75
- replaceElementsInCollection(module: any, parent: any, objKey: string): void;
76
- moveModule(moduleID: number, selectedContent: any, isPush: boolean): void;
75
+ replaceElementsInCollection(newValue: string, reference: string): void;
76
+ moveModule(moduleID: number, selectedContent: any, isPush: boolean, key: string): void;
77
77
  }
78
78
 
79
79
  type IProps = IEditorStateProps & IPageBrowserDispatchProps;
@@ -84,13 +84,13 @@ interface IEditorStateProps {
84
84
  interface IPageBrowserDispatchProps {
85
85
  setSelectedContent(editorID: number): void;
86
86
  setSelectedTab(tab: string): void;
87
- deleteModule(editorID: number): void;
88
- duplicateModule(editorID: number): void;
89
- addComponent: (componentType: any) => void;
90
- addModule: (moduleType: string, selectedID: number) => void;
91
- moveElement(moduleID: number, selectedContent: any, isPush: boolean): void;
87
+ deleteModule(editorID: number, key: string): void;
88
+ duplicateModule(editorID: number, key: string): void;
89
+ addComponent: (componentType: any, key: string) => void;
90
+ addModule: (moduleType: string, selectedID: number, key: string) => void;
91
+ moveElement(moduleID: number, selectedContent: any, isPush: boolean, key: string): void;
92
92
  replaceModule(module: any, parent: any, objKey: string): void;
93
- replaceElementsInCollection(module: any, parent: any, objKey: string): void;
93
+ replaceElementsInCollection(newValue: string, reference: string): void;
94
94
  setHistoryPush(path: string, isEditor: boolean): void;
95
95
  getGlobalFromLocalPage(): void;
96
96
  saveCurrentSiteInfo(): void;
@@ -255,6 +255,7 @@ const PageEditor = (props: IProps) => {
255
255
  currentPageUrl={editorContent.editorContent.fullUrl}
256
256
  errors={errors}
257
257
  errorActions={{ goToError }}
258
+ isFromEditor={true}
258
259
  >
259
260
  {(!isTemplateActivated || hasDeactivatedModules) && !isGlobal && (
260
261
  <S.NotificationWrapper>
@@ -217,6 +217,7 @@ const Form = (props: IProps) => {
217
217
  pageLanguages={currentLanguages}
218
218
  pageStatus={status}
219
219
  downArrowMenu={downArrowMenu}
220
+ isFromEditor={true}
220
221
  >
221
222
  {isDisabled && (
222
223
  <S.NotificationWrapper>
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
2
2
  import { connect } from "react-redux";
3
- import { useHistory } from "react-router-dom";
3
+ import { useHistory, useLocation } from "react-router-dom";
4
4
 
5
5
  import {
6
6
  IRootState,
@@ -105,6 +105,7 @@ const StructuredDataList = (props: IProps): JSX.Element => {
105
105
  const [isFirstRender, setIsFirstRender] = useState(true);
106
106
  const [deleteAllVersions, setDeleteAllVersions] = useState(false);
107
107
  const [arePagesTranslated, setArePagesTranslated] = useState(false);
108
+ const { state: locationState } = useLocation<{ isFromEditor: boolean }>();
108
109
 
109
110
  const scope = currentSiteID ? "site" : "global";
110
111
  const isDataEditable = !currentStructuredData || currentStructuredData.editable;
@@ -159,8 +160,14 @@ const StructuredDataList = (props: IProps): JSX.Element => {
159
160
  isStructuredDataFromPage ? handleGetGlobalPages() : getStructuredData(filter);
160
161
  };
161
162
 
163
+ const resetFilter = () => {
164
+ if (!locationState || locationState.isFromEditor !== true) {
165
+ setFilter("all-pages");
166
+ }
167
+ };
168
+
162
169
  useLayoutEffect(() => {
163
- history.action !== "POP" ? setFilter("all-pages") : handleGetData();
170
+ history.action !== "POP" ? resetFilter() : handleGetData();
164
171
  setIsFirstRender(false);
165
172
  resetPageEditor();
166
173
  // eslint-disable-next-line react-hooks/exhaustive-deps