@griddo/ax 1.65.10 → 1.65.13

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.
@@ -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">
@@ -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 {
@@ -720,11 +721,11 @@ export interface IDimensionsGroup {
720
721
  }
721
722
 
722
723
  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 },
724
+ dataPacks: string[];
725
+ id: string;
726
+ thumbnails: Record<string, string>;
727
+ title: string;
728
+ type: { label: string; value: string; mode: string };
728
729
  }
729
730
 
730
731
  export type Field =