@griddo/ax 11.9.11 → 11.9.12

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.9.11",
4
+ "version": "11.9.12",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Diego M. Béjar <diego.bejar@secuoyas.com>",
@@ -225,5 +225,5 @@
225
225
  "publishConfig": {
226
226
  "access": "public"
227
227
  },
228
- "gitHead": "e1a759f603928811450030145f5e79efb63fcedd"
228
+ "gitHead": "84fe61a326894742c48b3e82956928042e563a5b"
229
229
  }
@@ -132,11 +132,11 @@ const ComponentContainer = (props: IComponentContainerProps): JSX.Element => {
132
132
  const actionMenuIcon = "more";
133
133
 
134
134
  const handleEmptyContainerClick = () => {
135
- if (addComponentAction) addComponentAction(value);
135
+ if (addComponentAction) addComponentAction(value, objKey);
136
136
  };
137
137
 
138
138
  const handleOptionClick = (option: any) => {
139
- if (addComponentAction) addComponentAction(option);
139
+ if (addComponentAction) addComponentAction(option, objKey);
140
140
  };
141
141
 
142
142
  const compoundKey = parentKey ? `${parentKey}.${objKey}` : objKey;
@@ -735,11 +735,13 @@ function addComponent(
735
735
  localStorage.setItem("selectedID", `${lastElementEditorID}`);
736
736
  }
737
737
  } else {
738
- lastElementEditorID = addElementToCollection(type as string, key, dispatch, getState);
738
+ lastElementEditorID = addElementToCollection(type, key, dispatch, getState);
739
739
  }
740
740
 
741
- dispatch(setLastElementAddedId(lastElementEditorID));
742
- localStorage.setItem("selectedID", `${lastElementEditorID}`);
741
+ if (lastElementEditorID) {
742
+ dispatch(setLastElementAddedId(lastElementEditorID));
743
+ localStorage.setItem("selectedID", `${lastElementEditorID}`);
744
+ }
743
745
  };
744
746
  }
745
747
 
@@ -1,7 +1,7 @@
1
- import { IIntegration, IRootState, ISavePageParams } from "@ax/types";
2
- import { cleanContent, updateElementCollection } from "@ax/forms";
1
+ import { IComponent, IIntegration, IRootState, ISavePageParams } from "@ax/types";
2
+ import { addElement, cleanContent, updateElementCollection } from "@ax/forms";
3
3
  import { Dispatch } from "redux";
4
- import { generatePageContent } from "./actions";
4
+ import { generatePageContent, setSelectedContent } from "./actions";
5
5
 
6
6
  const getPageParams = (getState: any): ISavePageParams => {
7
7
  const {
@@ -125,16 +125,42 @@ const getDefaultPageNavigation = (defaultsContent: any, type: string) => {
125
125
  return navitagion;
126
126
  };
127
127
 
128
- const addElementToCollection = (type: string, key: string, dispatch: Dispatch, getState: () => IRootState) => {
128
+ const addElementToComponent = (component: Record<string, any>, type: IComponent) => {
129
+ const element = addElement(type);
130
+ Object.keys(component).forEach((key: string) => {
131
+ const containedValue = component[key];
132
+ if (containedValue.editorID === type.editorID) {
133
+ component[key] = element;
134
+ }
135
+ });
136
+ return component;
137
+ };
138
+
139
+ const addElementToCollection = (
140
+ type: string | IComponent,
141
+ key: string,
142
+ dispatch: Dispatch,
143
+ getState: () => IRootState
144
+ ) => {
145
+ const isSimpleField = typeof type === "string";
129
146
  const { editorContent } = getStateValues(getState);
130
- const updatedComponent = updateElementCollection(type, editorContent.template[key]);
147
+
148
+ const updatedComponent = isSimpleField
149
+ ? updateElementCollection(type, editorContent.template[key])
150
+ : addElementToComponent(editorContent.template[key], type);
151
+
131
152
  const updatedPageContent = { ...editorContent, template: { ...editorContent.template, [key]: updatedComponent } };
153
+
132
154
  generatePageContent(updatedPageContent)(dispatch, getState);
133
155
 
134
- const { editorContent: generatedEditor } = getStateValues(getState);
135
- const generatedElement = generatedEditor.template[key];
136
- const lastModuleEditorID = generatedElement[generatedElement.length - 1].editorID as number;
137
- return lastModuleEditorID;
156
+ if (isSimpleField) {
157
+ const { editorContent: generatedEditor } = getStateValues(getState);
158
+ const generatedElement = generatedEditor.template[key];
159
+ const lastModuleEditorID = generatedElement[generatedElement.length - 1].editorID as number;
160
+ return lastModuleEditorID;
161
+ } else {
162
+ setSelectedContent(type.editorID)(dispatch, getState);
163
+ }
138
164
  };
139
165
 
140
166
  export {
@@ -12,6 +12,7 @@ const addElement = (componentType: IComponent) => {
12
12
  for (const key in defaultSchema) {
13
13
  componentType[key] = defaultSchema[key];
14
14
  }
15
+ return componentType;
15
16
  };
16
17
 
17
18
  const updateComponent = (component: any, schema: any) => {
@@ -258,4 +259,5 @@ export {
258
259
  deleteComponent,
259
260
  replaceElements,
260
261
  updateElementCollection,
262
+ addElement,
261
263
  };
@@ -25,6 +25,7 @@ import {
25
25
  deleteComponent,
26
26
  replaceElements,
27
27
  updateElementCollection,
28
+ addElement,
28
29
  } from "./elements";
29
30
  import { getInnerFields, getStructuredDataInnerFields } from "./fields";
30
31
  import {
@@ -71,4 +72,5 @@ export {
71
72
  evaluateComputedFields,
72
73
  findByComponent,
73
74
  updateElementCollection,
75
+ addElement,
74
76
  };