@griddo/ax 1.65.11 → 1.65.14

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 (28) hide show
  1. package/package.json +3 -2
  2. package/src/api/structuredData.tsx +13 -2
  3. package/src/components/Button/index.tsx +15 -2
  4. package/src/components/Fields/AnalyticsField/PageAnalytics/index.test.tsx +204 -0
  5. package/src/components/Fields/AnalyticsField/StructuredDataAnalytics/atoms.tsx +1 -0
  6. package/src/components/Fields/AnalyticsField/StructuredDataAnalytics/index.test.tsx +146 -0
  7. package/src/components/Fields/ArrayFieldGroup/ArrayFieldInline/index.tsx +2 -1
  8. package/src/components/Fields/ArrayFieldGroup/ArrayFieldItem/index.tsx +1 -1
  9. package/src/components/Fields/ArrayFieldGroup/index.test.tsx +277 -0
  10. package/src/components/Fields/ArrayFieldGroup/index.tsx +0 -1
  11. package/src/components/Fields/AsyncCheckGroup/index.test.tsx +108 -0
  12. package/src/components/Fields/AsyncCheckGroup/index.tsx +2 -3
  13. package/src/components/Fields/AsyncSelect/index.test.tsx +306 -0
  14. package/src/components/Fields/AsyncSelect/index.tsx +18 -17
  15. package/src/components/Fields/HeadingField/index.test.tsx +71 -0
  16. package/src/components/Fields/HeadingField/index.tsx +1 -1
  17. package/src/components/Fields/Select/index.tsx +39 -24
  18. package/src/components/Fields/UrlField/index.tsx +38 -4
  19. package/src/components/Fields/UrlField/utils.tsx +74 -14
  20. package/src/components/FieldsBehavior/index.tsx +1 -1
  21. package/src/containers/StructuredData/actions.tsx +7 -0
  22. package/src/containers/StructuredData/constants.tsx +2 -0
  23. package/src/containers/StructuredData/interfaces.tsx +7 -0
  24. package/src/containers/StructuredData/reducer.tsx +4 -0
  25. package/src/modules/StructuredData/Form/index.tsx +12 -1
  26. package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +4 -2
  27. package/src/modules/StructuredData/StructuredDataList/index.tsx +1 -0
  28. package/src/types/index.tsx +7 -5
@@ -1,6 +1,58 @@
1
+ import { getSchema } from "@ax/helpers";
1
2
  import { IPage, ISelectOption } from "@ax/types";
2
3
 
4
+ const findSchemaComponentArrays = (component: string) => {
5
+ const keys: string[] = [];
6
+ const schemaTabs = getSchema(component).configTabs;
7
+ schemaTabs.forEach((tab: any) => {
8
+ tab.fields.forEach((field: any) => {
9
+ if (field.type === "ComponentArray") {
10
+ keys.push(field.key);
11
+ }
12
+ });
13
+ });
14
+ return keys;
15
+ };
16
+
17
+ const findAnchorsFromModule = (module: any) => {
18
+ if (!module) return [];
19
+ let options: ISelectOption[] = [];
20
+
21
+ if (module.anchorID && module.anchorID.trim() !== "") {
22
+ const option = { value: module.anchorID, label: module.anchorID };
23
+ options.push(option);
24
+ }
25
+
26
+ const arrayKeys = findSchemaComponentArrays(module.component);
27
+ if (arrayKeys.length) {
28
+ arrayKeys.forEach((key: string) => {
29
+ module[key].forEach((element: any) => {
30
+ const subOptions = findAnchorsFromModule(element);
31
+ options = [...options, ...subOptions];
32
+ });
33
+ });
34
+ }
35
+
36
+ return options;
37
+ };
38
+
3
39
  const findAnchorsFromPage = (page: IPage): ISelectOption[] => {
40
+ let options: ISelectOption[] = [];
41
+ const { template } = page;
42
+ const sections = Object.keys(template)
43
+ .map((key: string) => template[key])
44
+ .filter((value: any) => typeof value === "object" && value !== null && value.component === "Section");
45
+
46
+ sections.forEach((section: any) => {
47
+ section.modules.forEach((module: any) => {
48
+ const sectionOptions = findAnchorsFromModule(module);
49
+ options = [...options, ...sectionOptions];
50
+ });
51
+ });
52
+ return options;
53
+ };
54
+
55
+ const findTabsFromPage = (page: IPage): ISelectOption[] => {
4
56
  const options: ISelectOption[] = [];
5
57
  const { template } = page;
6
58
  const sections = Object.keys(template)
@@ -9,20 +61,10 @@ const findAnchorsFromPage = (page: IPage): ISelectOption[] => {
9
61
 
10
62
  sections.forEach((section: any) => {
11
63
  section.modules.forEach((module: any) => {
12
- if (module.anchorID && module.anchorID.trim() !== "") {
13
- const option = { value: module.anchorID, label: module.anchorID };
14
- options.push(option);
15
- }
16
- if (module.elements) {
64
+ if (module.hasGriddoMultiPage && module.elements) {
17
65
  module.elements.forEach((element: any) => {
18
- element.componentModules &&
19
- Array.isArray(element.componentModules) &&
20
- element.componentModules.forEach((component: any) => {
21
- if (component.anchorID && component.anchorID.trim() !== "") {
22
- const option = { value: component.anchorID, label: component.anchorID };
23
- options.push(option);
24
- }
25
- });
66
+ const option = { value: element.sectionSlug, label: element.title };
67
+ options.push(option);
26
68
  });
27
69
  }
28
70
  });
@@ -30,4 +72,22 @@ const findAnchorsFromPage = (page: IPage): ISelectOption[] => {
30
72
  return options;
31
73
  };
32
74
 
33
- export { findAnchorsFromPage };
75
+ const findAnchorsFromTab = (page: IPage, tabSlug: string): ISelectOption[] => {
76
+ let options: ISelectOption[] = [];
77
+ const { template } = page;
78
+ const sections = Object.keys(template)
79
+ .map((key: string) => template[key])
80
+ .filter((value: any) => typeof value === "object" && value !== null && value.component === "Section");
81
+
82
+ sections.forEach((section: any) => {
83
+ section.modules.forEach((module: any) => {
84
+ if (module.hasGriddoMultiPage) {
85
+ const tab = module.elements.find((elem: any) => elem.sectionSlug === tabSlug);
86
+ options = findAnchorsFromModule(tab);
87
+ }
88
+ });
89
+ });
90
+ return options;
91
+ };
92
+
93
+ export { findAnchorsFromPage, findTabsFromPage, findAnchorsFromTab };
@@ -73,7 +73,7 @@ const FieldsBehavior = (props: any): JSX.Element => {
73
73
  };
74
74
  return (
75
75
  <S.Wrapper error={errorField} className={wrapperClass} showTitle={showTitle} id={objKey}>
76
- <S.Content error={errorField}>
76
+ <S.Content data-testid="contentWrapper" error={errorField}>
77
77
  <Field {...props} showAdvanced={showAdvanced} handleValidation={handleValidation} error={errorField} />
78
78
  </S.Content>
79
79
  <S.Header className="fieldHeader">
@@ -3,6 +3,7 @@ import {
3
3
  SET_CATEGORIES,
4
4
  SET_STRUCTURED_DATA,
5
5
  SET_CURRENT_STRUCTURED_DATA,
6
+ SET_CURRENT_STRUCTURED_DATA_ID,
6
7
  SET_CURRENT_STRUCTURED_DATA_CONTENTS,
7
8
  SET_CATEGORY,
8
9
  SET_SCHEMA,
@@ -21,6 +22,7 @@ import {
21
22
  ISetCategories,
22
23
  ISetStructuredData,
23
24
  ISetCurrentData,
25
+ ISetCurrentDataID,
24
26
  ISetCurrentDataContent,
25
27
  ISetIsActive,
26
28
  ISetCategory,
@@ -56,6 +58,10 @@ function setCurrentData(currentStructuredData: any): ISetCurrentData {
56
58
  return { type: SET_CURRENT_STRUCTURED_DATA, payload: { currentStructuredData } };
57
59
  }
58
60
 
61
+ function setCurrentDataID(currentStructuredDataId: any): ISetCurrentDataID {
62
+ return { type: SET_CURRENT_STRUCTURED_DATA_ID, payload: { currentStructuredDataId } };
63
+ }
64
+
59
65
  function setCurrentDataContent(currentDataContent: any): ISetCurrentDataContent {
60
66
  return { type: SET_CURRENT_STRUCTURED_DATA_CONTENTS, payload: { currentDataContent } };
61
67
  }
@@ -530,6 +536,7 @@ export {
530
536
  setCategories,
531
537
  setStructuredData,
532
538
  setCurrentData,
539
+ setCurrentDataID,
533
540
  setCategory,
534
541
  setSchema,
535
542
  setForm,
@@ -4,6 +4,7 @@ const SET_IS_ACTIVE = `${NAME}/SET_IS_ACTIVE`;
4
4
  const SET_CATEGORIES = `${NAME}/SET_CATEGORIES`;
5
5
  const SET_STRUCTURED_DATA = `${NAME}/SET_STRUCTURED_DATA`;
6
6
  const SET_CURRENT_STRUCTURED_DATA = `${NAME}/SET_CURRENT_STRUCTURED_DATA`;
7
+ const SET_CURRENT_STRUCTURED_DATA_ID = `${NAME}/SET_CURRENT_STRUCTURED_DATA_ID`;
7
8
  const SET_CURRENT_STRUCTURED_DATA_CONTENTS = `${NAME}/SET_CURRENT_STRUCTURED_DATA_CONTENTS`;
8
9
  const SET_CATEGORY = `${NAME}/SET_CATEGORY`;
9
10
  const SET_SCHEMA = `${NAME}/SET_SCHEMA`;
@@ -30,6 +31,7 @@ export {
30
31
  SET_CATEGORIES,
31
32
  SET_STRUCTURED_DATA,
32
33
  SET_CURRENT_STRUCTURED_DATA,
34
+ SET_CURRENT_STRUCTURED_DATA_ID,
33
35
  SET_CURRENT_STRUCTURED_DATA_CONTENTS,
34
36
  SET_CATEGORY,
35
37
  SET_SCHEMA,
@@ -2,6 +2,7 @@ import {
2
2
  SET_CATEGORIES,
3
3
  SET_STRUCTURED_DATA,
4
4
  SET_CURRENT_STRUCTURED_DATA,
5
+ SET_CURRENT_STRUCTURED_DATA_ID,
5
6
  SET_CURRENT_STRUCTURED_DATA_CONTENTS,
6
7
  SET_SCHEMA,
7
8
  UPDATE_FORM,
@@ -30,6 +31,11 @@ export interface ISetCurrentData {
30
31
  payload: { currentStructuredData: any };
31
32
  }
32
33
 
34
+ export interface ISetCurrentDataID {
35
+ type: typeof SET_CURRENT_STRUCTURED_DATA_ID;
36
+ payload: { currentStructuredDataId: number };
37
+ }
38
+
33
39
  export interface ISetCategory {
34
40
  type: typeof SET_CATEGORY;
35
41
  payload: { category: ICategory };
@@ -79,4 +85,5 @@ export type CategoryActionsCreators = ISetCategories & ISetCurrentData;
79
85
  export type StructuredDataActionsCreators = CategoryActionsCreators &
80
86
  ISetStructuredData &
81
87
  ISetCurrentData &
88
+ ISetCurrentDataID &
82
89
  ISetCurrentDataContent;
@@ -3,6 +3,7 @@ import {
3
3
  SET_CATEGORIES,
4
4
  SET_STRUCTURED_DATA,
5
5
  SET_CURRENT_STRUCTURED_DATA,
6
+ SET_CURRENT_STRUCTURED_DATA_ID,
6
7
  SET_CURRENT_STRUCTURED_DATA_CONTENTS,
7
8
  SET_CATEGORY,
8
9
  SET_SCHEMA,
@@ -23,6 +24,7 @@ export interface IStructuredDataState {
23
24
  categories: { global: IStructuredData[]; site: IStructuredData[] };
24
25
  structuredData: { global: IStructuredData[]; site: IStructuredData[] };
25
26
  currentStructuredData: IStructuredData | null;
27
+ currentStructuredDataId: number | null;
26
28
  currentDataContent: IStructuredDataContent[];
27
29
  category: ICategory;
28
30
  schema: any;
@@ -39,6 +41,7 @@ export const initialState = {
39
41
  categories: { global: [], site: [] },
40
42
  structuredData: { global: [], site: [] },
41
43
  currentStructuredData: null,
44
+ currentStructuredDataId: null,
42
45
  currentDataContent: [],
43
46
  category: { name: "", code: "", lang: null, isTranslation: false, isNew: true },
44
47
  schema: {},
@@ -55,6 +58,7 @@ export function reducer(state = initialState, action: StructuredDataActionsCreat
55
58
  case SET_CATEGORIES:
56
59
  case SET_STRUCTURED_DATA:
57
60
  case SET_CURRENT_STRUCTURED_DATA:
61
+ case SET_CURRENT_STRUCTURED_DATA_ID:
58
62
  case SET_CURRENT_STRUCTURED_DATA_CONTENTS:
59
63
  case SET_CATEGORY:
60
64
  case SET_SCHEMA:
@@ -1,4 +1,4 @@
1
- import React, { useState } from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import { connect } from "react-redux";
3
3
 
4
4
  import { IDataPack, IErrorItem, IRootState, ISite } from "@ax/types";
@@ -39,6 +39,8 @@ const Form = (props: IProps) => {
39
39
  errors,
40
40
  validated,
41
41
  validateForm,
42
+ currentStructuredDataId,
43
+ resetForm,
42
44
  } = props;
43
45
 
44
46
  const [isNewStructuredData, setIsNewStructuredData] = useState(!form.id);
@@ -56,6 +58,11 @@ const Form = (props: IProps) => {
56
58
 
57
59
  const theme = getDefaultTheme();
58
60
 
61
+ useEffect(() => {
62
+ resetForm();
63
+ currentStructuredDataId && getDataContent(currentStructuredDataId);
64
+ }, [currentStructuredDataId]);
65
+
59
66
  const Fields =
60
67
  fields &&
61
68
  fields.map((field: any, i: number) => {
@@ -315,6 +322,8 @@ interface IProps {
315
322
  setDataStatus(id: number, status: string): Promise<boolean>;
316
323
  deleteStructuredDataContent(id: number): Promise<boolean>;
317
324
  validateForm(publish?: boolean): Promise<boolean>;
325
+ currentStructuredDataId: number | null;
326
+ resetForm(): void;
318
327
  }
319
328
 
320
329
  const mapStateToProps = (state: IRootState) => ({
@@ -322,6 +331,7 @@ const mapStateToProps = (state: IRootState) => ({
322
331
  form: state.structuredData.form,
323
332
  site: state.sites.currentSiteInfo,
324
333
  currentStructuredData: state.structuredData.currentStructuredData,
334
+ currentStructuredDataId: state.structuredData.currentStructuredDataId,
325
335
  isSaving: state.app.isSaving,
326
336
  isLoading: state.app.isLoading,
327
337
  lang: state.app.lang,
@@ -343,6 +353,7 @@ const mapDispatchToProps = {
343
353
  setDataStatus: structuredDataActions.setStatusStructuredDataContent,
344
354
  deleteStructuredDataContent: structuredDataActions.deleteStructuredDataContent,
345
355
  validateForm: structuredDataActions.validateForm,
356
+ resetForm: structuredDataActions.resetForm,
346
357
  };
347
358
 
348
359
  export default connect(mapStateToProps, mapDispatchToProps)(Form);
@@ -21,6 +21,7 @@ const StructuredDataItem = (props: IStructuredDataItemProps): JSX.Element => {
21
21
  setLanguage,
22
22
  setEntity,
23
23
  currentStructuredData,
24
+ setCurrentDataID,
24
25
  resetForm,
25
26
  isSelected,
26
27
  onChange,
@@ -52,8 +53,7 @@ const StructuredDataItem = (props: IStructuredDataItemProps): JSX.Element => {
52
53
  };
53
54
 
54
55
  const _handleClick = () => {
55
- resetForm();
56
- updateForm(structuredData);
56
+ setCurrentDataID(structuredData.id);
57
57
  handleClick();
58
58
  };
59
59
 
@@ -244,6 +244,7 @@ interface IStructuredDataItemProps {
244
244
  columns: Record<string, IColumn>;
245
245
  categoryColors: any;
246
246
  addCategoryColors(cats: string[]): void;
247
+ setCurrentDataID(id: number | null): void;
247
248
  }
248
249
 
249
250
  const mapStateToProps = (state: IRootState) => ({
@@ -258,6 +259,7 @@ const mapDispatchToProps = {
258
259
  resetForm: structuredDataActions.resetForm,
259
260
  setLanguage: appActions.setLanguage,
260
261
  setDataStatus: structuredDataActions.setStatusStructuredDataContent,
262
+ setCurrentDataID: structuredDataActions.setCurrentDataID,
261
263
  };
262
264
 
263
265
  const memoizedComponent = memo(StructuredDataItem);
@@ -171,6 +171,7 @@ const StructuredDataList = (props: IProps): JSX.Element => {
171
171
  include_draft: true,
172
172
  query: searchQuery,
173
173
  format: "list",
174
+ relatedFields: true,
174
175
  };
175
176
 
176
177
  return params;
@@ -164,6 +164,7 @@ export interface IUrlField {
164
164
  noFollow?: boolean;
165
165
  anchor?: string;
166
166
  title?: string;
167
+ subSlug?: string;
167
168
  }
168
169
 
169
170
  export interface IHeadingField {
@@ -298,6 +299,7 @@ export interface IGetStructuredDataParams {
298
299
  include_draft: boolean;
299
300
  query?: string;
300
301
  filterQuery?: string;
302
+ relatedFields?: boolean;
301
303
  }
302
304
 
303
305
  export interface IMenu {
@@ -720,11 +722,11 @@ export interface IDimensionsGroup {
720
722
  }
721
723
 
722
724
  export interface ITemplate {
723
- dataPacks: string[],
724
- id: string,
725
- thumbnails: Record<string, string>,
726
- title: string,
727
- type: { label: string, value: string, mode: string },
725
+ dataPacks: string[];
726
+ id: string;
727
+ thumbnails: Record<string, string>;
728
+ title: string;
729
+ type: { label: string; value: string; mode: string };
728
730
  }
729
731
 
730
732
  export type Field =