@griddo/ax 11.0.22 → 11.0.23

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.0.22",
4
+ "version": "11.0.23",
5
5
  "authors": [
6
6
  "Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
7
7
  "Carlos Torres <carlos.torres@secuoyas.com>",
@@ -225,5 +225,5 @@
225
225
  "publishConfig": {
226
226
  "access": "public"
227
227
  },
228
- "gitHead": "f47b8da5bc98f03f7f23a65d471a0429785c280d"
228
+ "gitHead": "eec9df5df565f610ec25cfb4b48bf737e9073990"
229
229
  }
@@ -30,7 +30,7 @@ import {
30
30
  parseValidationErrors,
31
31
  findPackagesActivationErrors,
32
32
  checkMaxModules,
33
- evalueComputedFields,
33
+ evaluateComputedFields,
34
34
  } from "@ax/forms";
35
35
  import { appActions } from "@ax/containers/App";
36
36
  import { navigationActions } from "@ax/containers/Navigation";
@@ -430,7 +430,7 @@ function savePage(
430
430
 
431
431
  const rootEditorID = 0;
432
432
  const { values: page, id } = getPageData(getState, false);
433
- const values = evalueComputedFields(page);
433
+ const values = await evaluateComputedFields(page, "save");
434
434
 
435
435
  const isNewPage = !id;
436
436
 
@@ -1064,8 +1064,8 @@ function updateEditorContent(
1064
1064
  clearTimeout(lastTimeout);
1065
1065
  }
1066
1066
 
1067
- const timeoutId = setTimeout(() => {
1068
- updatedEditorContent = evalueComputedFields(updatedEditorContent);
1067
+ const timeoutId = setTimeout(async () => {
1068
+ updatedEditorContent = await evaluateComputedFields(updatedEditorContent, "refresh");
1069
1069
  generatePageContent(updatedEditorContent)(dispatch, getState);
1070
1070
  }, 1500);
1071
1071
 
@@ -42,7 +42,7 @@ import {
42
42
  getTaxonomies,
43
43
  filterStructuredDataByID,
44
44
  getTypes,
45
- evalueDataComputedFields,
45
+ evaluateDataComputedFields,
46
46
  } from "./utils";
47
47
  import {
48
48
  IStructuredData,
@@ -333,7 +333,7 @@ function createStructuredDataContent(
333
333
  const isCategory = currentStructuredData?.taxonomy === true;
334
334
  let dataContent = prepareStructuredDataContent(structuredDataContent);
335
335
  if (Array.isArray(schema.fields) && !isCategory) {
336
- dataContent = evalueDataComputedFields(structuredDataContent, schema.fields);
336
+ dataContent = await evaluateDataComputedFields(structuredDataContent, schema.fields);
337
337
  }
338
338
 
339
339
  dataContent = {
@@ -370,7 +370,7 @@ function updateStructuredDataContent(
370
370
  const isCategory = currentStructuredData?.taxonomy === true;
371
371
  let dataContent = prepareStructuredDataContent(structuredDataContent);
372
372
  if (Array.isArray(schema.fields) && !isCategory) {
373
- dataContent = evalueDataComputedFields(structuredDataContent, schema.fields);
373
+ dataContent = await evaluateDataComputedFields(structuredDataContent, schema.fields);
374
374
  }
375
375
 
376
376
  const responseActions = {
@@ -32,12 +32,17 @@ const getTaxonomies = (data: IStructuredData[]) => data.filter((item: IStructure
32
32
  const getTypes = (data: IStructuredData[]) => data.filter((item: IStructuredData) => !item.taxonomy);
33
33
  const filterStructuredDataByID = (data: any, id: string) => data.find((item: any) => item.id === id);
34
34
 
35
- const evalueDataComputedFields = (structuredData: any, fields: any[]) => {
35
+ const evaluateDataComputedFields = (structuredData: any, fields: any[]) => {
36
36
  const updatedData = deepClone(structuredData);
37
- fields.forEach((field: ISchemaField) => {
37
+ const data = {
38
+ operation: "save",
39
+ apiUrl: process.env.REACT_APP_API_ENDPOINT,
40
+ publicApiUrl: process.env.REACT_APP_PUBLIC_API_ENDPOINT,
41
+ };
42
+ fields.forEach(async (field: ISchemaField) => {
38
43
  if (Object.prototype.hasOwnProperty.call(field, "computed")) {
39
44
  const computedFunction = eval(`(${field.computed})`);
40
- updatedData.content[field.key] = computedFunction(structuredData.content);
45
+ updatedData.content[field.key] = await computedFunction(structuredData.content, data);
41
46
  }
42
47
  });
43
48
  return updatedData;
@@ -50,5 +55,5 @@ export {
50
55
  getTaxonomies,
51
56
  getTypes,
52
57
  filterStructuredDataByID,
53
- evalueDataComputedFields,
58
+ evaluateDataComputedFields,
54
59
  };
@@ -199,12 +199,18 @@ const checkMaxModules = (content: any, type: string): { isMaxModules: boolean; e
199
199
  };
200
200
  };
201
201
 
202
- const evalueComputedFields = (page: any) => {
202
+ const evaluateComputedFields = (page: any, operation: "save" | "refresh") => {
203
203
  const updatedPage = deepClone(page);
204
204
  const pageSchemaContent = getTemplate(page.template.templateType).content;
205
- pageSchemaContent.forEach((field: any) => {
205
+ const data = {
206
+ operation,
207
+ apiUrl: process.env.REACT_APP_API_ENDPOINT,
208
+ publicApiUrl: process.env.REACT_APP_PUBLIC_API_ENDPOINT,
209
+ };
210
+ pageSchemaContent.forEach(async (field: any) => {
206
211
  if (Object.prototype.hasOwnProperty.call(field, "computed")) {
207
- updatedPage.template[field.key] = field.computed(page);
212
+ const computedFunction = eval(`(${field.computed})`);
213
+ updatedPage.template[field.key] = await computedFunction(page, data);
208
214
  }
209
215
  });
210
216
 
@@ -225,5 +231,5 @@ export {
225
231
  getLastComponentEditorID,
226
232
  getParentKey,
227
233
  checkMaxModules,
228
- evalueComputedFields,
234
+ evaluateComputedFields,
229
235
  };
@@ -11,7 +11,7 @@ import {
11
11
  getLastComponentEditorID,
12
12
  getParentKey,
13
13
  checkMaxModules,
14
- evalueComputedFields,
14
+ evaluateComputedFields,
15
15
  } from "./editor";
16
16
  import {
17
17
  getUpdatedComponents,
@@ -66,5 +66,5 @@ export {
66
66
  checkH1content,
67
67
  parseValidationErrors,
68
68
  checkMaxModules,
69
- evalueComputedFields,
69
+ evaluateComputedFields,
70
70
  };
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import { connect } from "react-redux";
3
3
 
4
4
  import { IErrorItem, IRootState } from "@ax/types";
@@ -15,14 +15,35 @@ const ConnectedField = (props: IProps) => {
15
15
  const isArrayGroup = field.type === "ArrayFieldGroup";
16
16
  const isComputedField = Object.prototype.hasOwnProperty.call(field, "computed");
17
17
  const isFieldDisabled = disabled || isComputedField;
18
-
19
- let value = form?.content && form.content[fieldKey];
20
18
  const error = errors.find((err: any) => err.key === field.key);
21
19
 
22
- if(isComputedField && form?.content) {
23
- const computedFunction = eval(`(${field.computed})`);
24
- value = computedFunction(form.content);
25
- }
20
+ const [value, setValue] = useState(form?.content && form.content[fieldKey]);
21
+ const [timeOut, setTimeOut] = useState(form?.content && form.content[fieldKey]);
22
+
23
+ useEffect(() => {
24
+ const evaluateDataComputedFields = async () => {
25
+ const data = {
26
+ operation: "refresh",
27
+ apiUrl: process.env.REACT_APP_API_ENDPOINT,
28
+ publicApiUrl: process.env.REACT_APP_PUBLIC_API_ENDPOINT,
29
+ };
30
+ const computedFunction = eval(`(${field.computed})`);
31
+ const value = await computedFunction(form.content, data);
32
+ setValue(value);
33
+ };
34
+
35
+ if (isComputedField && form?.content) {
36
+ if (timeOut) {
37
+ clearTimeout(timeOut);
38
+ }
39
+ const timeoutId = setTimeout(async () => {
40
+ evaluateDataComputedFields();
41
+ }, 1500);
42
+
43
+ setTimeOut(timeoutId);
44
+ }
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ }, [form?.content]);
26
47
 
27
48
  const handleChange = (newValue: any) => updateFormValue({ [fieldKey]: newValue });
28
49