@griddo/ax 10.4.7 → 10.4.9

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 (45) hide show
  1. package/package.json +2 -2
  2. package/src/__tests__/components/Browser/Browser.test.tsx +4 -4
  3. package/src/__tests__/components/Fields/ComponentArray/MixableComponentArray/MixableComponentArray.test.tsx +39 -7
  4. package/src/__tests__/components/Fields/ComponentArray/MixableComponentArray/PasteModuleButton/PasteModuleButton.test.tsx +8 -8
  5. package/src/__tests__/components/Fields/ComponentContainer/ComponentContainer.test.tsx +28 -16
  6. package/src/components/Browser/index.tsx +5 -5
  7. package/src/components/BulkSelectionOptions/style.tsx +1 -0
  8. package/src/components/ConfigPanel/Header/index.tsx +8 -4
  9. package/src/components/Fields/AsyncCheckGroup/style.tsx +3 -0
  10. package/src/components/Fields/CheckField/index.tsx +4 -1
  11. package/src/components/Fields/CheckField/style.tsx +19 -3
  12. package/src/components/Fields/CheckGroup/index.tsx +3 -2
  13. package/src/components/Fields/CheckGroup/style.tsx +3 -0
  14. package/src/components/Fields/ComponentArray/MixableComponentArray/BulkHeader/index.tsx +47 -0
  15. package/src/components/Fields/ComponentArray/MixableComponentArray/BulkHeader/style.tsx +44 -0
  16. package/src/components/Fields/ComponentArray/MixableComponentArray/PasteModuleButton/index.tsx +31 -12
  17. package/src/components/Fields/ComponentArray/MixableComponentArray/index.tsx +153 -59
  18. package/src/components/Fields/ComponentArray/SameComponentArray/index.tsx +1 -1
  19. package/src/components/Fields/ComponentArray/helpers.tsx +45 -4
  20. package/src/components/Fields/ComponentContainer/EmptyContainer/index.tsx +2 -2
  21. package/src/components/Fields/ComponentContainer/index.tsx +68 -33
  22. package/src/components/Fields/ComponentContainer/style.tsx +78 -11
  23. package/src/components/Fields/ReferenceField/Context/index.tsx +1 -1
  24. package/src/components/MainWrapper/AppBar/atoms.tsx +5 -8
  25. package/src/components/SideModal/SideModalOption/index.tsx +5 -3
  26. package/src/containers/Navigation/Defaults/actions.tsx +86 -55
  27. package/src/containers/Navigation/Defaults/interfaces.tsx +2 -2
  28. package/src/containers/Navigation/Defaults/reducer.tsx +3 -3
  29. package/src/containers/PageEditor/actions.tsx +142 -109
  30. package/src/containers/PageEditor/interfaces.tsx +1 -1
  31. package/src/containers/PageEditor/reducer.tsx +2 -2
  32. package/src/containers/PageEditor/utils.tsx +1 -1
  33. package/src/containers/Settings/DataPacks/actions.tsx +7 -2
  34. package/src/forms/elements.tsx +20 -14
  35. package/src/hooks/bulk.tsx +57 -2
  36. package/src/hooks/iframe.ts +5 -5
  37. package/src/modules/Content/index.tsx +10 -1
  38. package/src/modules/FramePreview/index.tsx +4 -4
  39. package/src/modules/GlobalEditor/Editor/index.tsx +6 -6
  40. package/src/modules/GlobalEditor/PageBrowser/index.tsx +2 -2
  41. package/src/modules/Navigation/Defaults/DefaultsEditor/Editor/index.tsx +6 -6
  42. package/src/modules/PageEditor/Editor/index.tsx +7 -7
  43. package/src/modules/PageEditor/PageBrowser/index.tsx +2 -2
  44. package/src/modules/Users/UserForm/index.tsx +52 -34
  45. package/src/types/index.tsx +1 -0
@@ -80,6 +80,9 @@ import {
80
80
  IStructuredDataContent,
81
81
  INotification,
82
82
  IPageLanguage,
83
+ IComponent,
84
+ IModule,
85
+ IRootState,
83
86
  } from "@ax/types";
84
87
  import {
85
88
  ISetBreadcrumb,
@@ -199,7 +202,7 @@ function setLastElementAddedId(lastElementAddedId: null | number): ISetLastEleme
199
202
  return { type: SET_LAST_ELEMENT_ADDED_ID, payload: { lastElementAddedId } };
200
203
  }
201
204
 
202
- function setCopyModule(moduleCopy: Record<string, unknown> | null): ISetCopyModule {
205
+ function setCopyModule(moduleCopy: { date: Date; elements: Record<string, unknown>[] } | null): ISetCopyModule {
203
206
  return { type: SET_COPY_MODULE, payload: { moduleCopy } };
204
207
  }
205
208
 
@@ -288,7 +291,7 @@ function generateNewPage(dispatch: Dispatch, getState: any, baseSchema: string)
288
291
 
289
292
  // SET PAGE AS ROOT WHEN NEW PAGE
290
293
  setRootEditorID(dispatch);
291
- generatePageContent(page, dispatch, getState);
294
+ generatePageContent(page)(dispatch, getState);
292
295
  }
293
296
 
294
297
  // API RELATED ACTIONS
@@ -350,7 +353,7 @@ function getPage(pageID?: number, global?: boolean): (dispatch: Dispatch, getSta
350
353
  if (isReqOk(response.status)) {
351
354
  addTemplate(page.templateId)(dispatch);
352
355
  setRootEditorID(dispatch);
353
- generatePageContent(page, dispatch, getState);
356
+ generatePageContent(page)(dispatch, getState);
354
357
  dispatch(setCurrentPageName(page.title));
355
358
  dispatch(setCurrentPageID(page.id));
356
359
  dispatch(setTemplateConfig(page.templateConfig));
@@ -674,7 +677,7 @@ function addTemplate(template: string): (dispatch: Dispatch) => Promise<void> {
674
677
  };
675
678
  }
676
679
 
677
- function addComponent(type: any, key: string): (dispatch: Dispatch, getState: any) => void {
680
+ function addComponent(type: IComponent | string, key: string): (dispatch: Dispatch, getState: any) => void {
678
681
  return (dispatch, getState) => {
679
682
  const { editorContent, sections, editorID } = getStateValues(getState);
680
683
  const component = {
@@ -693,9 +696,9 @@ function addComponent(type: any, key: string): (dispatch: Dispatch, getState: an
693
696
  },
694
697
  };
695
698
 
696
- generatePageContent(updatedPageContent, dispatch, getState);
699
+ generatePageContent(updatedPageContent)(dispatch, getState);
697
700
 
698
- if (type.editorID) {
701
+ if (typeof type === "object" && Object.prototype.hasOwnProperty.call(type, "editorID")) {
699
702
  setSelectedContent(type.editorID)(dispatch, getState);
700
703
  } else {
701
704
  const { sections: generatedSections } = getStateValues(getState);
@@ -747,7 +750,7 @@ function addModule(
747
750
  },
748
751
  };
749
752
 
750
- generatePageContent(updatedPageContent, dispatch, getState);
753
+ generatePageContent(updatedPageContent)(dispatch, getState);
751
754
 
752
755
  const { sections: generatedSections } = getStateValues(getState);
753
756
  const lastModuleEditorID = getLastModuleEditorID(generatedSections, updatedSectionIndex);
@@ -778,11 +781,14 @@ function replaceModule(module: any, parent: any, objKey: string): (dispatch: Dis
778
781
  });
779
782
 
780
783
  const updatedContent = updateByEditorID(editorContent, parent.editorID, objKey, updatedVal);
781
- generatePageContent(updatedContent, dispatch, getState);
784
+ generatePageContent(updatedContent)(dispatch, getState);
782
785
  };
783
786
  }
784
787
 
785
- function replaceElementsInCollection(newValue: string, reference: string): (dispatch: Dispatch, getState: any) => void {
788
+ function replaceElementsInCollection(
789
+ newValue: string,
790
+ reference?: string
791
+ ): (dispatch: Dispatch, getState: any) => void {
786
792
  return async (dispatch, getState) => {
787
793
  const { selectedContent } = getStateValues(getState);
788
794
 
@@ -792,23 +798,25 @@ function replaceElementsInCollection(newValue: string, reference: string): (disp
792
798
  updateEditorContent(selectedContent.editorID, key, updatedContent)(dispatch, getState);
793
799
 
794
800
  const { editorContent } = getStateValues(getState);
795
- generatePageContent(editorContent, dispatch, getState);
801
+ generatePageContent(editorContent)(dispatch, getState);
796
802
  };
797
803
  }
798
804
 
799
- function deleteModule(editorID: number, key?: string): (dispatch: Dispatch, getState: any) => void {
805
+ function deleteModule(editorID: number[], key?: string): (dispatch: Dispatch, getState: any) => void {
800
806
  return (dispatch, getState) => {
801
807
  const { sections, editorContent, errors } = getStateValues(getState);
802
808
 
803
809
  const updatedSections: any = [...sections];
804
- const { parent, grandParent } = findByEditorID(updatedSections, editorID);
810
+ const { parent, grandParent } = findByEditorID(updatedSections, editorID[0]);
805
811
  const parentModule = Array.isArray(parent) ? grandParent : parent;
806
812
 
807
- const parentKey = key ? key : getParentKey(parentModule, editorID);
813
+ const parentKey = key ? key : getParentKey(parentModule, editorID[0]);
808
814
  const itemsArr = parentModule[parentKey];
809
815
 
810
- const index = itemsArr.findIndex((module: any) => module.editorID === editorID);
811
- itemsArr.splice(index, 1);
816
+ editorID.forEach((moduleID) => {
817
+ const index = itemsArr.findIndex((module: IModule) => module.editorID === moduleID);
818
+ itemsArr.splice(index, 1);
819
+ });
812
820
 
813
821
  const updatedPageContent = {
814
822
  ...editorContent,
@@ -818,45 +826,51 @@ function deleteModule(editorID: number, key?: string): (dispatch: Dispatch, getS
818
826
  validatePage()(dispatch, getState);
819
827
  }
820
828
 
821
- generatePageContent(updatedPageContent, dispatch, getState);
829
+ generatePageContent(updatedPageContent)(dispatch, getState);
822
830
 
823
831
  dispatch(setLastElementAddedId(null));
824
832
  };
825
833
  }
826
834
 
827
- function duplicateModule(editorID: number, key?: string): (dispatch: Dispatch, getState: any) => Promise<number> {
835
+ function duplicateModule(editorID: number[], key?: string): (dispatch: Dispatch, getState: any) => number {
828
836
  return (dispatch, getState) => {
829
837
  const { sections, editorContent } = getStateValues(getState);
830
838
 
831
839
  const updatedSections: any = [...sections];
832
- const { element: originalItem, parent, grandParent } = findByEditorID(updatedSections, editorID);
833
-
834
- const { isMaxModules, errorMessage } = checkMaxModules(editorContent, originalItem.component);
835
-
836
- if (isMaxModules) {
837
- handleError(errorMessage)(dispatch);
838
- return editorID;
839
- }
840
840
 
841
+ const { parent, grandParent } = findByEditorID(updatedSections, editorID[0]);
841
842
  const parentModule = Array.isArray(parent) ? grandParent : parent;
842
-
843
- const parentKey = key ? key : getParentKey(parentModule, editorID);
843
+ const parentKey = key ? key : getParentKey(parentModule, editorID[0]);
844
844
  const itemsArr = parentModule[parentKey];
845
+ let duplicatedItemIndex = 0;
845
846
 
846
- const originalItemIndex = itemsArr.findIndex((module: any) => module.editorID === editorID);
847
- const duplicatedItemIndex = originalItemIndex + 1;
848
- itemsArr.splice(duplicatedItemIndex, 0, originalItem);
847
+ editorID.forEach((id) => {
848
+ const { element: originalItem } = findByEditorID(updatedSections, id);
849
+ const { isMaxModules, errorMessage } = checkMaxModules(editorContent, originalItem.component);
850
+
851
+ if (isMaxModules) {
852
+ handleError(errorMessage)(dispatch);
853
+ return;
854
+ } else {
855
+ const originalItemIndex = itemsArr.findIndex((module: any) => module.editorID === id);
856
+ duplicatedItemIndex = originalItemIndex + 1;
857
+ itemsArr.splice(duplicatedItemIndex, 0, originalItem);
858
+ }
859
+ });
849
860
 
850
861
  const updatedPageContent = {
851
862
  ...editorContent,
852
863
  };
853
864
 
854
- generatePageContent(updatedPageContent, dispatch, getState);
865
+ generatePageContent(updatedPageContent)(dispatch, getState);
855
866
 
856
867
  const { sections: generatedSections } = getStateValues(getState);
857
- const { parent: generatedParent, grandParent: generatedGrandParent } = findByEditorID(generatedSections, editorID);
868
+ const { parent: generatedParent, grandParent: generatedGrandParent } = findByEditorID(
869
+ generatedSections,
870
+ editorID[0]
871
+ );
858
872
  const section = Array.isArray(generatedParent) ? generatedGrandParent : generatedParent;
859
- const duplicatedEditorID = section[parentKey][duplicatedItemIndex].editorID;
873
+ const duplicatedEditorID: number = section[parentKey][duplicatedItemIndex].editorID;
860
874
 
861
875
  localStorage.setItem("selectedID", `${duplicatedEditorID}`);
862
876
 
@@ -864,17 +878,27 @@ function duplicateModule(editorID: number, key?: string): (dispatch: Dispatch, g
864
878
  };
865
879
  }
866
880
 
867
- function copyModule(editorID: number): (dispatch: Dispatch, getState: any) => boolean {
881
+ function copyModule(editorID: number[]): (dispatch: Dispatch, getState: any) => boolean {
868
882
  return (dispatch, getState) => {
869
883
  const { sections } = getStateValues(getState);
870
- const { element: originalElement } = findByEditorID(sections, editorID);
871
- if (originalElement) {
872
- const { editorID, parentEditorID, ...element } = originalElement;
884
+ const modulesToCopy: Record<string, unknown>[] = [];
885
+
886
+ editorID.forEach((id) => {
887
+ const { element: originalElement } = findByEditorID(sections, id);
888
+ if (originalElement) {
889
+ const { editorID, parentEditorID, ...element } = originalElement;
890
+ modulesToCopy.push(element);
891
+ }
892
+ });
893
+
894
+ if (modulesToCopy.length) {
873
895
  const payload = {
874
896
  date: new Date(),
875
- element,
897
+ elements: modulesToCopy,
876
898
  };
899
+
877
900
  dispatch(setCopyModule(payload));
901
+
878
902
  return true;
879
903
  } else {
880
904
  return false;
@@ -884,59 +908,63 @@ function copyModule(editorID: number): (dispatch: Dispatch, getState: any) => bo
884
908
 
885
909
  function pasteModule(
886
910
  editorID: number,
887
- key: string
911
+ key: string,
912
+ modulesToPaste: IModule[]
888
913
  ): (dispatch: Dispatch, getState: any) => Promise<{ error?: INotification }> {
889
914
  return async (dispatch, getState) => {
890
915
  const {
891
- pageEditor: { moduleCopy },
892
916
  sites: { currentSiteInfo },
893
- } = getState();
917
+ }: IRootState = getState();
894
918
 
895
919
  const { sections, editorContent } = getStateValues(getState);
896
920
 
897
- const { isMaxModules, errorMessage } = checkMaxModules(editorContent, moduleCopy.element.component);
898
- if (isMaxModules && errorMessage) {
899
- const error: INotification = {
900
- type: "error",
901
- text: errorMessage,
902
- };
903
- return { error };
904
- }
905
-
906
921
  const updatedSections: any = [...sections];
907
922
  const { element: originalElement } = findByEditorID(updatedSections, editorID);
923
+ const itemsArr = originalElement[key];
908
924
 
909
- const validatedModuleCopy: any = deepClone(moduleCopy.element);
910
925
  let error: INotification | undefined;
911
926
 
912
- if (moduleCopy.element.hasDistributorData) {
913
- const { mode, fixed } = moduleCopy.element.data;
914
- const isManualMode = mode === "manual" && !!fixed?.length;
915
- if (isManualMode) {
916
- const response = await structuredData.getDataContentBulk(fixed, currentSiteInfo.id);
917
- if (isReqOk(response.status)) {
918
- const validDataIds: number[] = [];
919
- response.data.items.forEach((data: IStructuredDataContent) => data.relatedSite && validDataIds.push(data.id));
920
- const hasInvalidData = validDataIds.length < fixed.length;
921
- validatedModuleCopy.data.fixed = validDataIds;
922
- if (hasInvalidData) {
923
- error = {
924
- type: "warning",
925
- text: "Some distributor data were not copied because they are not imported into this site",
926
- };
927
+ modulesToPaste.forEach(async (element) => {
928
+ const { isMaxModules, errorMessage } = checkMaxModules(editorContent, element.component);
929
+ if (isMaxModules && errorMessage) {
930
+ error = {
931
+ type: "error",
932
+ text: errorMessage,
933
+ };
934
+ }
935
+
936
+ const validatedModuleCopy: any = deepClone(element);
937
+
938
+ if (element.hasDistributorData) {
939
+ const { mode, fixed } = element.data;
940
+ const isManualMode = mode === "manual" && !!fixed?.length;
941
+ if (isManualMode) {
942
+ const response = await structuredData.getDataContentBulk(fixed, currentSiteInfo?.id);
943
+ if (isReqOk(response.status)) {
944
+ const validDataIds: number[] = [];
945
+ response.data.items.forEach(
946
+ (data: IStructuredDataContent) => data.relatedSite && validDataIds.push(data.id)
947
+ );
948
+ const hasInvalidData = validDataIds.length < fixed.length;
949
+ validatedModuleCopy.data.fixed = validDataIds;
950
+ if (hasInvalidData) {
951
+ error = {
952
+ type: "warning",
953
+ text: "Some distributor data were not copied because they are not imported into this site",
954
+ };
955
+ }
927
956
  }
928
957
  }
929
958
  }
930
- }
931
959
 
932
- const itemsArr = originalElement[key];
933
- itemsArr.push(validatedModuleCopy);
960
+ itemsArr.push(validatedModuleCopy);
961
+ });
934
962
 
935
963
  const updatedPageContent = {
936
964
  ...editorContent,
937
965
  };
938
966
 
939
- generatePageContent(updatedPageContent, dispatch, getState);
967
+ generatePageContent(updatedPageContent)(dispatch, getState);
940
968
 
941
969
  const { sections: generatedSections } = getStateValues(getState);
942
970
  const { element: generatedElement } = findByEditorID(generatedSections, editorID);
@@ -963,40 +991,42 @@ function overwriteHeaderConfig(params: IFieldProps): (dispatch: Dispatch, getSta
963
991
  };
964
992
  }
965
993
 
966
- function generatePageContent(editorContent: IPage, dispatch: Dispatch, getState: any): void {
967
- const {
968
- pageEditor: { selectedEditorID, isNewTranslation, template },
969
- navigation: { currentDefaultsContent },
970
- dataPacks: { configFormData },
971
- } = getState();
994
+ function generatePageContent(editorContent: IPage): (dispatch: Dispatch, getState: any) => void {
995
+ return (dispatch, getState) => {
996
+ const {
997
+ pageEditor: { selectedEditorID, isNewTranslation, template },
998
+ navigation: { currentDefaultsContent },
999
+ dataPacks: { configFormData },
1000
+ } = getState();
972
1001
 
973
- const { header, footer, isGlobal } = editorContent;
974
- const { defaultHeader, defaultFooter } = (configFormData?.templates && configFormData?.templates[template]) || {};
1002
+ const { header, footer, isGlobal } = editorContent;
1003
+ const { defaultHeader, defaultFooter } = (configFormData?.templates && configFormData?.templates[template]) || {};
975
1004
 
976
- const headerID =
977
- header === null || header === undefined ? defaultHeader : typeof header === "object" ? header.id : header;
978
- const footerID =
979
- footer === null || footer === undefined ? defaultFooter : typeof footer === "object" ? footer.id : footer;
1005
+ const headerID =
1006
+ header === null || header === undefined ? defaultHeader : typeof header === "object" ? header.id : header;
1007
+ const footerID =
1008
+ footer === null || footer === undefined ? defaultFooter : typeof footer === "object" ? footer.id : footer;
980
1009
 
981
- const { header: pageHeader, footer: pageFooter } = getPageNavigation(
982
- headerID,
983
- footerID,
984
- currentDefaultsContent,
985
- isGlobal
986
- );
1010
+ const { header: pageHeader, footer: pageFooter } = getPageNavigation(
1011
+ headerID,
1012
+ footerID,
1013
+ currentDefaultsContent,
1014
+ isGlobal
1015
+ );
1016
+
1017
+ const { pageContent } = generateEditorIDs({ ...editorContent, header: pageHeader, footer: pageFooter });
1018
+ const { element: selectedContent, parent: selectedParent } = findByEditorID({ pageContent }, selectedEditorID);
1019
+ const { component } = selectedContent;
1020
+ const schema = getSchema(component);
987
1021
 
988
- const { pageContent } = generateEditorIDs({ ...editorContent, header: pageHeader, footer: pageFooter });
989
- const { element: selectedContent, parent: selectedParent } = findByEditorID({ pageContent }, selectedEditorID);
990
- const { component } = selectedContent;
991
- const schema = getSchema(component);
992
-
993
- dispatch(setSchema(schema));
994
- dispatch(setEditorContent(pageContent));
995
- dispatch(updateBreadcrumb(selectedEditorID));
996
- dispatch(setSelectedPageContent(selectedContent));
997
- dispatch(setSelectedParent(selectedParent));
998
- dispatch(setIsLoading(false));
999
- if (isNewTranslation) setTranslatedParent()(dispatch, getState);
1022
+ dispatch(setSchema(schema));
1023
+ dispatch(setEditorContent(pageContent));
1024
+ dispatch(updateBreadcrumb(selectedEditorID));
1025
+ dispatch(setSelectedPageContent(selectedContent));
1026
+ dispatch(setSelectedParent(selectedParent));
1027
+ dispatch(setIsLoading(false));
1028
+ if (isNewTranslation) setTranslatedParent()(dispatch, getState);
1029
+ };
1000
1030
  }
1001
1031
 
1002
1032
  function updateEditorContent(
@@ -1023,14 +1053,14 @@ function updateEditorContent(
1023
1053
 
1024
1054
  const timeoutId = setTimeout(() => {
1025
1055
  updatedEditorContent = evalueComputedFields(updatedEditorContent);
1026
- generatePageContent(updatedEditorContent, dispatch, getState);
1056
+ generatePageContent(updatedEditorContent)(dispatch, getState);
1027
1057
  }, 1500);
1028
1058
 
1029
1059
  dispatch(setLastTimeout(timeoutId));
1030
1060
 
1031
1061
  const isNavigation = ["header", "footer"].includes(key);
1032
1062
  if (isNavigation || (value && typeof value === "object")) {
1033
- generatePageContent(updatedEditorContent, dispatch, getState);
1063
+ generatePageContent(updatedEditorContent)(dispatch, getState);
1034
1064
  }
1035
1065
  };
1036
1066
  }
@@ -1144,14 +1174,15 @@ function resetPageEditor(): (dispatch: Dispatch) => Promise<void> {
1144
1174
  }
1145
1175
 
1146
1176
  function moveElement(
1147
- elementID: number,
1177
+ elementID: number[],
1148
1178
  content: any,
1149
1179
  newIndex: number,
1150
1180
  key: string
1151
1181
  ): (dispatch: Dispatch, getState: any) => void {
1152
1182
  return async (dispatch, getState) => {
1153
1183
  try {
1154
- const { selectedContent, editorContent } = getState().pageEditor;
1184
+ const { editorContent, editorID, selectedContent } = getStateValues(getState);
1185
+
1155
1186
  const newContent = moveModule({
1156
1187
  elementID,
1157
1188
  content,
@@ -1161,9 +1192,11 @@ function moveElement(
1161
1192
  key,
1162
1193
  });
1163
1194
 
1164
- generatePageContent(newContent, dispatch, getState);
1165
- } catch {
1166
- console.log("error in moveModule");
1195
+ dispatch(setEditorContent(newContent));
1196
+ const { element: selectedPageContent } = findByEditorID(newContent, editorID);
1197
+ dispatch(setSelectedPageContent(selectedPageContent));
1198
+ } catch (e) {
1199
+ console.log(e);
1167
1200
  }
1168
1201
  };
1169
1202
  }
@@ -1384,7 +1417,7 @@ function getPageSummary(): (dispatch: Dispatch, getState: any) => Promise<boolea
1384
1417
  const content = deepClone(editorContent);
1385
1418
  content["metaDescription"] = data.summary;
1386
1419
  content["metaKeywords"] = data.keywords;
1387
- generatePageContent(content, dispatch, getState);
1420
+ generatePageContent(content)(dispatch, getState);
1388
1421
  },
1389
1422
  handleError: () => console.log("Error en GetPageSummary"),
1390
1423
  };
@@ -1409,7 +1442,7 @@ function getPageTranslation(langID: number): (dispatch: Dispatch, getState: any)
1409
1442
  const responseActions = {
1410
1443
  handleSuccess: (data: IPage) => {
1411
1444
  data["canBeTranslated"] = false;
1412
- generatePageContent(data, dispatch, getState);
1445
+ generatePageContent(data)(dispatch, getState);
1413
1446
  dispatch(setCurrentPageName(data.title));
1414
1447
  dispatch(setIsIATranslated(true));
1415
1448
  },
@@ -121,7 +121,7 @@ export interface ISetLastElementAddedId {
121
121
 
122
122
  export interface ISetCopyModule {
123
123
  type: typeof SET_COPY_MODULE;
124
- payload: { moduleCopy: Record<string, unknown> | null };
124
+ payload: { moduleCopy: { date: Date; elements: Record<string, unknown>[] } | null };
125
125
  }
126
126
 
127
127
  export interface ISetIsIATranslated {
@@ -1,4 +1,4 @@
1
- import { IPage, IBreadcrumbItem, ISchema, IErrorItem, IUserEditing } from "@ax/types";
1
+ import { IPage, IBreadcrumbItem, ISchema, IErrorItem, IUserEditing, IModule } from "@ax/types";
2
2
 
3
3
  import {
4
4
  SET_EDITOR_CONTENT,
@@ -48,7 +48,7 @@ export interface IPageEditorState {
48
48
  sitePageID: number | null;
49
49
  userEditing: IUserEditing | null;
50
50
  lastElementAddedId: null | number;
51
- moduleCopy: { date: string; element: Record<string, unknown> } | null;
51
+ moduleCopy: { date: Date; elements: IModule[] } | null;
52
52
  isIATranslated: boolean;
53
53
  lastTimeout: NodeJS.Timeout | null;
54
54
  }
@@ -42,7 +42,7 @@ const getStateValues = (getState: any) => {
42
42
  } = getState();
43
43
  const { header, footer } = editorContent;
44
44
 
45
- const editorID = selectedEditorID;
45
+ const editorID: number = selectedEditorID;
46
46
  const sections = getTemplateValues(editorContent.template);
47
47
 
48
48
  return {
@@ -256,7 +256,10 @@ function resetForm(): (dispatch: Dispatch) => void {
256
256
  };
257
257
  }
258
258
 
259
- function getAvailableSiteDataPacks(queryParams: string | null): (dispatch: Dispatch, getState: any) => Promise<void> {
259
+ function getAvailableSiteDataPacks(
260
+ queryParams: string | null,
261
+ loading = true,
262
+ ): (dispatch: Dispatch, getState: any) => Promise<void> {
260
263
  return async (dispatch, getState) => {
261
264
  try {
262
265
  const {
@@ -277,7 +280,9 @@ function getAvailableSiteDataPacks(queryParams: string | null): (dispatch: Dispa
277
280
 
278
281
  const callback = async () => dataPack.getSiteDataPack(currentSiteID, query);
279
282
 
280
- await handleRequest(callback, responseActions, [appActions.setIsLoading])(dispatch);
283
+ const setLoading = loading ? [appActions.setIsLoading] : [];
284
+
285
+ await handleRequest(callback, responseActions, setLoading)(dispatch);
281
286
  } catch (e) {
282
287
  console.log(e); // TODO: capturar error bien
283
288
  }
@@ -1,12 +1,13 @@
1
1
  import { getDefaultSchema, camelize, isSelectedEditorID, deepClone } from "@ax/helpers";
2
2
  import { findByEditorID } from "./editor";
3
+ import { IComponent, IModule } from "@ax/types";
3
4
 
4
5
  const updateElementCollection = (elementType: string, prevCollection: any[]) => {
5
6
  const newElement = getDefaultSchema(elementType);
6
7
  return [...prevCollection, newElement];
7
8
  };
8
9
 
9
- const addElement = (componentType: any) => {
10
+ const addElement = (componentType: IComponent) => {
10
11
  const defaultSchema = getDefaultSchema(componentType.component);
11
12
  for (const key in defaultSchema) {
12
13
  componentType[key] = defaultSchema[key];
@@ -22,20 +23,24 @@ const updateComponent = (component: any, schema: any) => {
22
23
  }
23
24
  };
24
25
 
25
- const updateCollection = (type: string, item: any, key: string) =>
26
+ const updateCollection = (type: string, item: IModule, key: string) =>
26
27
  (item[key] = updateElementCollection(type, item[key]));
27
28
 
28
- const getUpdatedComponents = (sections: any, component: any, key: string) => {
29
+ const getUpdatedComponents = (
30
+ sections: any[],
31
+ component: { editorID: number; type: IComponent | string },
32
+ key: string
33
+ ) => {
29
34
  const { editorID, type } = component;
30
35
 
31
36
  const isCollectionItem = typeof type === "string";
32
37
  let selectedIndex = 0;
33
38
 
34
- const addItem = (item: any) => (isCollectionItem ? updateCollection(type, item, key) : addElement(type));
39
+ const addItem = (item: IModule) => (isCollectionItem ? updateCollection(type, item, key) : addElement(type));
35
40
 
36
41
  const sectionEntries = sections.map((section: any, index: number) => {
37
- const updatedModules = section.modules.map((module: any) => {
38
- const mapValues = (item: any) => {
42
+ const updatedModules = section.modules.map((module: IModule) => {
43
+ const mapValues = (item: IModule) => {
39
44
  if (item.editorID && item.editorID === editorID) {
40
45
  addItem(item);
41
46
  selectedIndex = index;
@@ -150,14 +155,15 @@ const updateByEditorID = (content: any, editorID: number, contentKey: string, va
150
155
  return content;
151
156
  };
152
157
 
153
- const moveElement = (elementID: number, arr: any[], newIndex: number, idKey = "editorID") => {
154
- const arrCopy = [...arr];
158
+ const moveElement = (elementID: number[], arr: any[], newIndex: number, idKey = "editorID"): any[] => {
159
+ const arrCopy = deepClone(arr);
155
160
  if (arrCopy.length <= 1) return arrCopy;
156
- const elementIndex = arrCopy.findIndex((el: any) => el[idKey] === elementID);
157
- const element = { ...arrCopy[elementIndex] };
158
- arrCopy.splice(elementIndex, 1);
159
- arrCopy.splice(newIndex, 0, element);
160
-
161
+ elementID.forEach((id) => {
162
+ const elementIndex = arrCopy.findIndex((el: any) => el[idKey] === id);
163
+ const element = { ...arrCopy[elementIndex] };
164
+ arrCopy.splice(elementIndex, 1);
165
+ arrCopy.splice(newIndex, 0, element);
166
+ });
161
167
  return arrCopy;
162
168
  };
163
169
 
@@ -213,7 +219,7 @@ function replaceElements(elements: any, elemType: string): any {
213
219
  }
214
220
 
215
221
  interface IMoveElementParams {
216
- elementID: number;
222
+ elementID: number[];
217
223
  content: any;
218
224
  newIndex: number;
219
225
  selectedContent: any;