@griddo/ax 1.63.3 → 1.64.0

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 (132) hide show
  1. package/config/griddo-config/cx-polyfills/builder.ssr.js +6 -0
  2. package/config/griddo-config/cx-polyfills/componentsBundle.js +4 -0
  3. package/config/{griddo-config.js → griddo-config/index.js} +36 -15
  4. package/config/griddo-config/ssrHelpers.js +47 -0
  5. package/config/jest/componentsMock.js +29 -0
  6. package/config/jest/fileMock.js +1 -0
  7. package/config/jest/setup.js +5 -0
  8. package/config/jest/styleMock.js +1 -0
  9. package/config/jest/test-utils.js +17 -0
  10. package/config/paths.js +36 -5
  11. package/config/webpack.config.js +1 -1
  12. package/config/webpackDevServer.config.js +4 -1
  13. package/config/webpackSchemas.config.js +4 -1
  14. package/package.json +35 -64
  15. package/scripts/build.js +9 -2
  16. package/src/__mocks__/reducers/analyticsState.tsx +14 -0
  17. package/src/__mocks__/reducers/pageEditor.tsx +30 -0
  18. package/src/api/sites.tsx +28 -6
  19. package/src/api/structuredData.tsx +1 -1
  20. package/src/api/users.tsx +5 -4
  21. package/src/components/ActionMenu/style.tsx +2 -0
  22. package/src/components/Browser/index.tsx +9 -5
  23. package/src/{modules/Content/PageItem/atoms.tsx → components/CategoryCell/index.tsx} +4 -6
  24. package/src/components/CategoryCell/style.tsx +11 -0
  25. package/src/components/Fields/AnalyticsField/PageAnalytics/index.tsx +19 -19
  26. package/src/components/Fields/AnalyticsField/StructuredDataAnalytics/atoms.tsx +26 -16
  27. package/src/components/Fields/AnalyticsField/StructuredDataAnalytics/index.tsx +8 -13
  28. package/src/components/Fields/AnalyticsField/index.test.tsx +100 -0
  29. package/src/components/Fields/AnalyticsField/index.tsx +9 -2
  30. package/src/components/Fields/AnalyticsField/utils.tsx +2 -2
  31. package/src/components/Fields/ArrayFieldGroup/ArrayFieldItem/style.tsx +2 -1
  32. package/src/components/Fields/CheckField/index.test.tsx +95 -0
  33. package/src/components/Fields/CheckField/index.tsx +9 -3
  34. package/src/components/Fields/CheckField/style.tsx +32 -24
  35. package/src/components/Fields/CheckGroup/index.test.tsx +274 -0
  36. package/src/components/Fields/CheckGroup/index.tsx +2 -1
  37. package/src/components/Fields/FileField/FileDragAndDrop/style.tsx +3 -2
  38. package/src/components/Fields/FileField/style.tsx +2 -1
  39. package/src/components/Fields/MultiCheckSelect/style.tsx +18 -18
  40. package/src/components/Fields/NoteField/style.tsx +9 -9
  41. package/src/components/Fields/ReferenceField/AutoPanel/AutoItem/index.tsx +1 -1
  42. package/src/components/Fields/Select/style.tsx +41 -37
  43. package/src/components/Fields/TagField/index.test.tsx +136 -0
  44. package/src/components/Fields/TagField/index.tsx +8 -12
  45. package/src/components/Fields/TextArea/index.test.tsx +69 -0
  46. package/src/components/Fields/TextArea/index.tsx +4 -13
  47. package/src/components/Fields/TextArea/style.tsx +2 -2
  48. package/src/components/Fields/TextField/index.test.tsx +144 -0
  49. package/src/components/Fields/TextField/index.tsx +23 -19
  50. package/src/components/Fields/TextField/style.tsx +16 -7
  51. package/src/components/Fields/UniqueCheck/index.test.tsx +43 -0
  52. package/src/components/Fields/UrlField/utils.tsx +8 -6
  53. package/src/components/FieldsBehavior/index.tsx +0 -2
  54. package/src/components/FieldsBehavior/style.tsx +21 -21
  55. package/src/components/Gallery/GalleryFilters/Orientation/style.tsx +2 -1
  56. package/src/components/Gallery/GalleryFilters/SortBy/style.tsx +2 -1
  57. package/src/components/Icon/index.tsx +12 -10
  58. package/src/components/IconAction/index.tsx +7 -1
  59. package/src/components/IconAction/style.tsx +10 -10
  60. package/src/components/SearchField/index.tsx +11 -8
  61. package/src/components/SearchField/style.tsx +21 -12
  62. package/src/components/TableFilters/CategoryFilter/index.tsx +1 -1
  63. package/src/components/TableFilters/CategoryFilter/style.tsx +2 -1
  64. package/src/components/TableFilters/DateFilter/style.tsx +2 -1
  65. package/src/components/TableFilters/LiveFilter/index.tsx +2 -2
  66. package/src/components/TableFilters/LiveFilter/style.tsx +2 -1
  67. package/src/components/TableFilters/NameFilter/style.tsx +2 -1
  68. package/src/components/TableFilters/SiteFilter/index.tsx +38 -24
  69. package/src/components/TableFilters/SiteFilter/style.tsx +2 -1
  70. package/src/components/TableFilters/StatusFilter/style.tsx +2 -1
  71. package/src/components/TableFilters/TranslationsFilter/style.tsx +2 -1
  72. package/src/components/TableFilters/TypeFilter/style.tsx +2 -1
  73. package/src/components/Tag/index.tsx +9 -7
  74. package/src/components/Tag/style.tsx +20 -8
  75. package/src/components/index.tsx +4 -2
  76. package/src/containers/App/reducer.tsx +0 -2
  77. package/src/containers/PageEditor/actions.tsx +2 -2
  78. package/src/containers/Sites/actions.tsx +30 -19
  79. package/src/containers/Users/actions.tsx +10 -2
  80. package/src/containers/Users/reducer.tsx +3 -1
  81. package/src/helpers/fields.tsx +2 -4
  82. package/src/helpers/index.tsx +3 -0
  83. package/src/helpers/themes.tsx +9 -0
  84. package/src/index.tsx +3 -0
  85. package/src/modules/Analytics/GroupPanel/utils.tsx +3 -3
  86. package/src/modules/App/Routing/NavMenu/index.tsx +13 -12
  87. package/src/modules/Content/PageItem/index.tsx +31 -9
  88. package/src/modules/Content/PageItem/style.tsx +0 -7
  89. package/src/modules/Content/atoms.tsx +78 -0
  90. package/src/modules/Content/index.tsx +104 -33
  91. package/src/modules/Content/style.tsx +10 -7
  92. package/src/modules/GlobalEditor/PageBrowser/index.tsx +0 -4
  93. package/src/modules/GlobalEditor/index.tsx +3 -3
  94. package/src/modules/Navigation/Defaults/DefaultsEditor/Editor/DefaultsBrowser/index.tsx +0 -4
  95. package/src/modules/PageEditor/PageBrowser/index.tsx +0 -4
  96. package/src/modules/PageEditor/atoms.tsx +74 -0
  97. package/src/modules/PageEditor/index.tsx +30 -9
  98. package/src/modules/PageEditor/style.tsx +4 -0
  99. package/src/modules/PublicPreview/index.tsx +3 -5
  100. package/src/modules/Settings/ContentTypes/DataPacks/Config/Form/TemplateConfig/TemplateEditor/Editor/TemplateBrowser/index.tsx +0 -4
  101. package/src/modules/Settings/ContentTypes/DataPacks/Config/Form/TemplateConfig/TemplateEditor/Editor/index.tsx +2 -3
  102. package/src/modules/Settings/ContentTypes/DataPacks/Config/Form/index.tsx +1 -1
  103. package/src/modules/Settings/Globals/index.tsx +3 -3
  104. package/src/modules/StructuredData/Form/index.tsx +2 -4
  105. package/src/modules/StructuredData/StructuredDataList/BulkHeader/TableHeader/index.tsx +22 -18
  106. package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/atoms.tsx +3 -24
  107. package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/index.tsx +2 -2
  108. package/src/modules/StructuredData/StructuredDataList/GlobalPageItem/style.tsx +0 -7
  109. package/src/modules/StructuredData/StructuredDataList/OptionTable/index.tsx +2 -4
  110. package/src/modules/StructuredData/StructuredDataList/StructuredDataItem/index.tsx +46 -14
  111. package/src/modules/StructuredData/StructuredDataList/hooks.tsx +21 -9
  112. package/src/modules/StructuredData/StructuredDataList/index.tsx +48 -20
  113. package/src/modules/Users/Profile/index.tsx +12 -7
  114. package/src/modules/Users/UserCreate/SiteItem/index.tsx +44 -0
  115. package/src/modules/Users/UserCreate/SiteItem/style.tsx +30 -0
  116. package/src/modules/Users/UserCreate/index.tsx +120 -10
  117. package/src/modules/Users/UserCreate/style.tsx +54 -1
  118. package/src/modules/Users/UserEdit/index.tsx +53 -15
  119. package/src/modules/Users/UserForm/index.tsx +152 -5
  120. package/src/modules/Users/UserForm/style.tsx +40 -2
  121. package/src/modules/Users/UserList/BulkHeader/TableHeader/index.tsx +40 -2
  122. package/src/modules/Users/UserList/BulkHeader/TableHeader/style.tsx +0 -1
  123. package/src/modules/Users/UserList/BulkHeader/index.tsx +10 -1
  124. package/src/modules/Users/UserList/UserItem/index.tsx +70 -15
  125. package/src/modules/Users/UserList/hooks.tsx +58 -1
  126. package/src/modules/Users/UserList/index.tsx +80 -34
  127. package/src/modules/Users/index.tsx +18 -11
  128. package/src/routes/site.tsx +8 -0
  129. package/src/types/index.tsx +7 -0
  130. package/tsconfig.json +2 -0
  131. package/patches/connected-react-router+6.9.2.patch +0 -12
  132. package/scripts/test.js +0 -45
@@ -108,7 +108,7 @@ const getDataContents = (params: IGetStructuredDataParams, siteID?: number | nul
108
108
 
109
109
  const url = siteID ? `${host}/site/${siteID}${endpoint}` : `${host}${endpoint}`;
110
110
 
111
- SERVICES.GET_DATA_CONTENTS.dynamicUrl = `${url}${dataID}?page=${page}&itemsPerPage=${itemsPerPage}&pagination=${pagination}&deleted=${deleted}&includeDraft=${include_draft}`;
111
+ SERVICES.GET_DATA_CONTENTS.dynamicUrl = `${url}${dataID}?page=${page}&itemsPerPage=${itemsPerPage}&pagination=${pagination}&deleted=${deleted}&includeDraft=${include_draft}&relatedFields=true`;
112
112
  if (query && query.trim() !== "") SERVICES.GET_DATA_CONTENTS.dynamicUrl += `&query=${query}`;
113
113
  if (filterQuery) SERVICES.GET_DATA_CONTENTS.dynamicUrl += filterQuery;
114
114
 
package/src/api/users.tsx CHANGED
@@ -47,11 +47,12 @@ const SERVICES: { [key: string]: IServiceConfig } = {
47
47
  const getUsers = async (params: any) => {
48
48
  const { host, endpoint } = SERVICES.GET_USERS;
49
49
 
50
- const { query, order } = params;
50
+ const { query, filterQuery } = params;
51
+
52
+ SERVICES.GET_USERS.dynamicUrl = `${host}${endpoint}${filterQuery}`;
51
53
 
52
- SERVICES.GET_USERS.dynamicUrl = `${host}${endpoint}?order=${order}`;
53
54
  if (query && query.trim() !== "") {
54
- SERVICES.GET_USERS.dynamicUrl = SERVICES.GET_USERS.dynamicUrl + `&query=${query}`;
55
+ SERVICES.GET_USERS.dynamicUrl = `${SERVICES.GET_USERS.dynamicUrl}${query}`;
55
56
  }
56
57
 
57
58
  return sendRequest(SERVICES.GET_USERS);
@@ -119,4 +120,4 @@ export default {
119
120
  deleteUser,
120
121
  deleteUserBulk,
121
122
  resendInvitation,
122
- };
123
+ };
@@ -44,6 +44,8 @@ export const ActionItem = styled.li<{ disabled?: boolean; color?: boolean }>`
44
44
  padding: ${(p) => p.theme.spacing.xs} ${(p) => p.theme.spacing.s};
45
45
  pointer-events: ${(p) => (p.disabled ? "none" : "auto")};
46
46
  text-align: left;
47
+ white-space: nowrap;
48
+
47
49
  &:focus {
48
50
  background: ${(p) => (p.disabled ? "transparent" : p.theme.color.overlayFocusPrimary)};
49
51
  }
@@ -1,9 +1,9 @@
1
- import React, { useEffect, useState } from "react";
1
+ import React, { useEffect, useState, useCallback } from "react";
2
2
  import { FrameContextConsumer } from "react-frame-component";
3
3
  import { StyleSheetManager } from "styled-components";
4
4
 
5
5
  import * as components from "components";
6
- import { providers, translations, cloudinaryDefaults, griddoDamDefaults } from "components";
6
+ import { providers, translations, cloudinaryDefaults, griddoDamDefaults, builderSSR, ssrHelpers } from "components";
7
7
  import { Preview } from "@griddo/core";
8
8
  import { findByEditorID } from "@ax/forms";
9
9
  import { copyTextToClipboard } from "@ax/helpers";
@@ -28,7 +28,6 @@ const Browser = (props: IBrowserProps): JSX.Element => {
28
28
  disabled,
29
29
  siteID,
30
30
  isPreview,
31
- damDomain,
32
31
  setSelectedContent,
33
32
  } = props;
34
33
 
@@ -44,6 +43,13 @@ const Browser = (props: IBrowserProps): JSX.Element => {
44
43
  (window as any).browserRef = null;
45
44
  }, []);
46
45
 
46
+ const useInstanceExternalAssets = useCallback(() => {
47
+ if (builderSSR && builderSSR.onRenderBody) {
48
+ builderSSR.onRenderBody(ssrHelpers);
49
+ }
50
+ }, []);
51
+ useEffect(useInstanceExternalAssets, [useInstanceExternalAssets]);
52
+
47
53
  const selectEditorID = (
48
54
  selectedComponent: { editorID: number; component: any; type: string; parentEditorID: number },
49
55
  parentComponent: string | undefined | null,
@@ -96,7 +102,6 @@ const Browser = (props: IBrowserProps): JSX.Element => {
96
102
  const Providers = (
97
103
  <SiteProvider
98
104
  cloudinaryCloudName={cloudinaryName}
99
- damDomain={damDomain}
100
105
  theme={theme}
101
106
  socials={socials}
102
107
  siteLangs={siteLangs}
@@ -192,7 +197,6 @@ interface IBrowserProps {
192
197
  theme: string;
193
198
  socials: any;
194
199
  cloudinaryName: string | null;
195
- damDomain: string | null;
196
200
  siteLangs: any[];
197
201
  disabled?: boolean;
198
202
  siteID?: number;
@@ -1,10 +1,8 @@
1
1
  import React, { useEffect } from "react";
2
-
3
2
  import { ElementsTooltip } from "@ax/components";
3
+ import * as S from "./style"
4
4
 
5
- import * as S from "./style";
6
-
7
- const CategoryCell = (props: ICategoryCellProps): JSX.Element => {
5
+ const CategoryCell = (props: IProps): JSX.Element => {
8
6
  const { categories, categoryColors, addCategoryColors } = props;
9
7
 
10
8
  useEffect(() => {
@@ -19,10 +17,10 @@ const CategoryCell = (props: ICategoryCellProps): JSX.Element => {
19
17
  );
20
18
  };
21
19
 
22
- interface ICategoryCellProps {
20
+ interface IProps {
23
21
  categories: any;
24
22
  categoryColors: any;
25
23
  addCategoryColors(cats: string[]): void;
26
24
  }
27
25
 
28
- export { CategoryCell };
26
+ export default CategoryCell;
@@ -0,0 +1,11 @@
1
+ import styled from "styled-components";
2
+
3
+ import { Cell } from "@ax/components/TableList/TableItem/style";
4
+
5
+ const CategoryCell = styled(Cell)`
6
+ flex: 0 0 150px;
7
+ align-items: center;
8
+ position: relative;
9
+ `;
10
+
11
+ export { CategoryCell }
@@ -7,18 +7,14 @@ import { DimensionsGroup, DimensionsSelection } from "./atoms";
7
7
  import * as S from "../style";
8
8
 
9
9
  const PageAnalytics = (props: IAnalyticsFieldProps): JSX.Element => {
10
- const {
11
- value,
12
- onChange,
13
- analytics,
14
- } = props;
10
+ const { value, onChange, analytics } = props;
15
11
 
16
12
  const initialState = {
17
13
  contentSelect: "",
18
14
  groupSelect: "",
19
15
  dimensionsSelect: [],
20
- values: {}
21
- }
16
+ values: {},
17
+ };
22
18
 
23
19
  const [state, setState] = useState<IState>(value || initialState);
24
20
 
@@ -29,11 +25,11 @@ const PageAnalytics = (props: IAnalyticsFieldProps): JSX.Element => {
29
25
 
30
26
  const handleContentSelect = (contentSelect: string) => {
31
27
  setState({ ...initialState, contentSelect });
32
- }
28
+ };
33
29
 
34
30
  const handleGroupSelect = (groupSelect: string) => {
35
31
  setState((state: IState) => ({ ...state, groupSelect, values: {} }));
36
- }
32
+ };
37
33
 
38
34
  const handleDimensionsSelect = (selection: string[]) => {
39
35
  const values: Record<string, string> = {};
@@ -43,33 +39,37 @@ const PageAnalytics = (props: IAnalyticsFieldProps): JSX.Element => {
43
39
  dimensionsSelect = analytics.dimensions.map((dimension) => dimension.name);
44
40
  }
45
41
 
46
- dimensionsSelect.forEach((dimension) => values[dimension] = state.values[dimension]);
42
+ dimensionsSelect.forEach((dimension) => (values[dimension] = state.values[dimension]));
47
43
  setState((state: IState) => ({ ...state, dimensionsSelect, values }));
48
- }
44
+ };
49
45
 
50
46
  const setDimension = (value: Record<string, string>) => {
51
47
  setState((state: IState) => ({ ...state, values: { ...state.values, ...value } }));
52
- }
48
+ };
53
49
 
54
50
  const contentOptions = [
55
51
  {
56
52
  label: "Dimensions Group",
57
- value: "group"
53
+ value: "group",
58
54
  },
59
55
  {
60
56
  label: "Individual Dimensions",
61
- value: "individual"
57
+ value: "individual",
62
58
  },
63
- ]
59
+ ];
64
60
 
65
- const groupOptions: { label: string, value: string }[] = [];
61
+ const groupOptions: { label: string; value: string }[] = [];
66
62
  analytics.groups?.forEach((group) => {
67
- groupOptions.push({ label: group.name, value: group.name })
63
+ groupOptions.push({ label: group.name, value: group.name });
68
64
  });
69
65
 
70
66
  const noteText = (
71
67
  <>
72
- Select <strong>Dimension Group</strong> if you want to select one of the groups you created in the global settings (based on the page content).<br /><br />Select <strong>Individual Dimensions</strong> if you want to select the dimensions to track manually.
68
+ Select <strong>Dimension Group</strong> if you want to select one of the groups you created in the global settings
69
+ (based on the page content).
70
+ <br />
71
+ <br />
72
+ Select <strong>Individual Dimensions</strong> if you want to select the dimensions to track manually.
73
73
  </>
74
74
  );
75
75
 
@@ -88,7 +88,7 @@ const PageAnalytics = (props: IAnalyticsFieldProps): JSX.Element => {
88
88
  name: dimension.name,
89
89
  value: dimension.name,
90
90
  title: dimension.name,
91
- }
91
+ };
92
92
  dimensionOptions.push(option);
93
93
  });
94
94
 
@@ -12,38 +12,48 @@ const TemplateDimensions = (props: ITemplateDimensions): JSX.Element => {
12
12
  const groupDimensions = dimensionNames.map((dimensionName) => {
13
13
  const dimension = analytics.dimensions.find((dimension) => dimension.name === dimensionName);
14
14
  return dimension;
15
- })
15
+ });
16
16
 
17
17
  return (
18
18
  <>
19
- {groupDimensions && groupDimensions.map((dimension, idx) => (
20
- dimension && <DimensionValue key={idx} {...{ dimension, setDimension, values }} />
21
- ))}
19
+ {groupDimensions &&
20
+ groupDimensions.map(
21
+ (dimension, idx) => dimension && <DimensionValue key={idx} {...{ dimension, setDimension, values }} />
22
+ )}
22
23
  </>
23
- )
24
- }
24
+ );
25
+ };
25
26
 
26
- const DimensionsSelection = (props: { analytics: IAnalytics, state: IState, setDimension: (value: Record<string, string>) => void }): JSX.Element => {
27
+ const DimensionsSelection = (props: {
28
+ analytics: IAnalytics;
29
+ state: IState;
30
+ setDimension: (value: Record<string, string>) => void;
31
+ }): JSX.Element => {
27
32
  const { analytics, state, setDimension } = props;
28
33
  const { dimensionsSelect, values } = state;
29
34
  const selectedDimensions = analytics.dimensions.filter((d) => dimensionsSelect.includes(d.name));
30
35
 
31
36
  return (
32
37
  <>
33
- {selectedDimensions && selectedDimensions.map((dimension, idx) => (
34
- <DimensionValue key={idx} {...{ dimension, setDimension, values }} />
35
- ))}
38
+ {selectedDimensions &&
39
+ selectedDimensions.map((dimension, idx) => (
40
+ <DimensionValue key={idx} {...{ dimension, setDimension, values }} />
41
+ ))}
36
42
  </>
37
- )
38
- }
43
+ );
44
+ };
39
45
 
40
- const DimensionValue = (props: { dimension: IDimension, setDimension: (value: Record<string, string>) => void, values: Record<string, string> }) => {
46
+ const DimensionValue = (props: {
47
+ dimension: IDimension;
48
+ setDimension: (value: Record<string, string>) => void;
49
+ values: Record<string, string>;
50
+ }) => {
41
51
  const { dimension, setDimension, values } = props;
42
52
  const dimensionValues = splitAndTrim(dimension?.values, ";");
43
53
  const options = dimensionValues.map((option) => ({ label: option, value: option }));
44
54
  const handleOnChange = (value: string) => {
45
55
  dimension && setDimension({ [dimension.name]: value });
46
- }
56
+ };
47
57
 
48
58
  const isNullValue = dimensionValues.includes("null");
49
59
  const fieldValue = values && dimension ? values[dimension.name] : "";
@@ -65,8 +75,8 @@ const DimensionValue = (props: { dimension: IDimension, setDimension: (value: Re
65
75
  onChange={handleOnChange}
66
76
  placeholder="Select variable"
67
77
  />
68
- )
69
- }
78
+ );
79
+ };
70
80
 
71
81
  interface ITemplateDimensions {
72
82
  analytics: IAnalytics;
@@ -8,17 +8,12 @@ import { TemplateDimensions, DimensionsSelection } from "./atoms";
8
8
  import * as S from "../style";
9
9
 
10
10
  const StructuredDataAnalytics = (props: IAnalyticsFieldProps): JSX.Element => {
11
- const {
12
- value,
13
- onChange,
14
- analytics,
15
- template,
16
- } = props;
11
+ const { value, onChange, analytics, template } = props;
17
12
 
18
13
  const initialState = {
19
14
  dimensionsSelect: [],
20
- values: {}
21
- }
15
+ values: {},
16
+ };
22
17
 
23
18
  const [state, setState] = useState<IState>({ ...initialState, ...value });
24
19
 
@@ -31,20 +26,20 @@ const StructuredDataAnalytics = (props: IAnalyticsFieldProps): JSX.Element => {
31
26
 
32
27
  const handleDimensionsSelect = (selection: string[]) => {
33
28
  const values: Record<string, string> = {};
34
- templateDimensions.forEach((dimension) => values[dimension] = state.values[dimension]);
29
+ templateDimensions.forEach((dimension) => (values[dimension] = state.values[dimension]));
35
30
  let dimensionsSelect = selection;
36
31
 
37
32
  if (selection.includes("all")) {
38
33
  dimensionsSelect = dimensionOptions.map((dimension) => dimension.name);
39
34
  }
40
35
 
41
- dimensionsSelect.forEach((dimension) => values[dimension] = state.values[dimension]);
36
+ dimensionsSelect.forEach((dimension) => (values[dimension] = state.values[dimension]));
42
37
  setState((state: IState) => ({ ...state, dimensionsSelect, values }));
43
- }
38
+ };
44
39
 
45
40
  const setDimension = (value: Record<string, string>) => {
46
41
  setState((state: IState) => ({ ...state, values: { ...state.values, ...value } }));
47
- }
42
+ };
48
43
 
49
44
  const dimensionOptions = [
50
45
  {
@@ -59,7 +54,7 @@ const StructuredDataAnalytics = (props: IAnalyticsFieldProps): JSX.Element => {
59
54
  name: dimension.name,
60
55
  value: dimension.name,
61
56
  title: dimension.name,
62
- }
57
+ };
63
58
  dimensionOptions.push(option);
64
59
  }
65
60
  });
@@ -0,0 +1,100 @@
1
+ import React from "react";
2
+ import "@testing-library/jest-dom";
3
+ import AnalyticsField from "./index";
4
+ import { IAnalytics } from "@ax/types";
5
+ import { createStore, combineReducers } from "redux";
6
+ import analyticsReducer from "../../../__mocks__/reducers/analyticsState";
7
+ import pageEditorReducer from "../../../__mocks__/reducers/pageEditor";
8
+ import { ThemeProvider } from "styled-components";
9
+ import { parseTheme } from "@griddo/core";
10
+ import globalTheme from "../../../themes/theme.json";
11
+ import { render, cleanup } from "../../../../config/jest/test-utils";
12
+
13
+ const valuesMock = {
14
+ contentSelect: "",
15
+ groupSelect: "",
16
+ dimensionsSelect: ["dimensions"],
17
+ values: { key: "", value: "" },
18
+ };
19
+
20
+ const analyticsMock = {
21
+ scriptCode: "",
22
+ siteScriptCodeExists: false,
23
+ dimensions: [],
24
+ groups: [],
25
+ };
26
+
27
+ afterEach(cleanup);
28
+
29
+ describe("AnalyticsField component rendering", () => {
30
+ test("should render the component PageAnalytics", () => {
31
+ const initialState = {
32
+ value: valuesMock,
33
+ template: "BasicTemplate",
34
+ onChange: jest.fn(),
35
+ analytics: analyticsMock,
36
+ };
37
+ const initialStore = {
38
+ analytics: analyticsMock,
39
+ };
40
+ const store = createStore(
41
+ combineReducers({ pageEditor: pageEditorReducer, analytics: analyticsReducer }),
42
+ initialStore
43
+ );
44
+ const { getByText } = render(
45
+ <ThemeProvider theme={parseTheme(globalTheme)}>
46
+ <AnalyticsField {...initialState} />
47
+ </ThemeProvider>,
48
+ { store }
49
+ );
50
+ expect(getByText(/Select Dimensions Options/i)).toBeInTheDocument();
51
+ });
52
+ test("should render the component StructuredDataAnalytics", () => {
53
+ const valuesMock = {
54
+ contentSelect: "content",
55
+ groupSelect: "group",
56
+ dimensionsSelect: ["dimensions"],
57
+ values: { key: "a", value: "b" },
58
+ };
59
+ const analyticsMock = {
60
+ scriptCode: "",
61
+ siteScriptCodeExists: false,
62
+ dimensions: [{ name: "dimension", values: "dimensions" }],
63
+ groups: [{ templates: "BasicTemplate", name: "Basic Template", dimensions: "dimension 1" }],
64
+ };
65
+ const initialState = {
66
+ value: valuesMock,
67
+ template: "BasicTemplate",
68
+ onChange: jest.fn(),
69
+ analytics: analyticsMock,
70
+ };
71
+ const initialStore = {
72
+ analytics: analyticsMock,
73
+ };
74
+ const store = createStore(
75
+ combineReducers({ pageEditor: pageEditorReducer, analytics: analyticsReducer }),
76
+ initialStore
77
+ );
78
+ const { getByText } = render(
79
+ <ThemeProvider theme={parseTheme(globalTheme)}>
80
+ <AnalyticsField {...initialState} />
81
+ </ThemeProvider>,
82
+ { store }
83
+ );
84
+ expect(getByText(/Add More Dimensions/i)).toBeInTheDocument();
85
+ });
86
+ });
87
+
88
+ export interface IAnalyticsFieldProps {
89
+ value: IState;
90
+ template: string;
91
+ onChange: (value: IState) => void;
92
+ analytics: IAnalytics;
93
+ }
94
+
95
+ export interface IState {
96
+ contentSelect: string;
97
+ groupSelect: string;
98
+ dimensionsSelect: string[];
99
+ values: Record<string, string>;
100
+ }
@@ -10,10 +10,17 @@ import { getTemplateDimensions } from "./utils";
10
10
 
11
11
  const AnalyticsField = (props: IAnalyticsFieldProps): JSX.Element => {
12
12
  const { analytics, template } = props;
13
-
14
13
  const templateDimensions = getTemplateDimensions(analytics.groups, template);
15
14
 
16
- return isEmptyArray(templateDimensions) ? <PageAnalytics {...props} /> : <StructuredDataAnalytics {...props} />;
15
+ return isEmptyArray(templateDimensions) ? (
16
+ <>
17
+ <PageAnalytics {...props} />
18
+ </>
19
+ ) : (
20
+ <>
21
+ <StructuredDataAnalytics {...props} />
22
+ </>
23
+ );
17
24
  };
18
25
 
19
26
  const mapStateToProps = (state: IRootState) => ({
@@ -8,6 +8,6 @@ const getTemplateDimensions = (groups: IDimensionsGroup[], template: string): st
8
8
  }, []);
9
9
  const uniqueTemplateDimensions = [...new Set(templateDimensions)];
10
10
  return uniqueTemplateDimensions;
11
- }
11
+ };
12
12
 
13
- export { getTemplateDimensions }
13
+ export { getTemplateDimensions };
@@ -1,3 +1,4 @@
1
+ import React from "react";
1
2
  import styled from "styled-components";
2
3
  import ActionMenu from "@ax/components/ActionMenu";
3
4
 
@@ -8,7 +9,7 @@ const Wrapper = styled.div<{ isOpen: boolean }>`
8
9
  border-radius: ${(p) => p.theme.radii.s};
9
10
  `;
10
11
 
11
- const StyledActionMenu = styled(ActionMenu)`
12
+ const StyledActionMenu = styled((props) => <ActionMenu {...props} />)`
12
13
  width: ${(p) => p.theme.spacing.m};
13
14
  height: ${(p) => p.theme.spacing.m};
14
15
  display: flex;
@@ -0,0 +1,95 @@
1
+ import React from "react";
2
+ import CheckField from "./index";
3
+ import { ThemeProvider } from "styled-components";
4
+ import { parseTheme } from "@griddo/core";
5
+ import globalTheme from "../../../themes/theme.json";
6
+ import { render, screen, cleanup, fireEvent } from "@testing-library/react";
7
+
8
+ afterEach(cleanup);
9
+
10
+ const defaultProps = {
11
+ name: "",
12
+ title: "",
13
+ value: "",
14
+ checked: false,
15
+ error: false,
16
+ disabled: false,
17
+ indeterminate: false,
18
+ onChange: jest.fn(),
19
+ icon: "",
20
+ };
21
+
22
+ describe("CheckField component rendering", () => {
23
+ it("should render the component", () => {
24
+ render(
25
+ <ThemeProvider theme={parseTheme(globalTheme)}>
26
+ <CheckField {...defaultProps} />
27
+ </ThemeProvider>
28
+ );
29
+
30
+ const checkFieldLabel = screen.getByTestId("checkFieldLabel");
31
+ const checkFieldInput = screen.getByTestId("checkFieldInput");
32
+ const checkFieldCheckMark = screen.getByTestId("checkFieldCheckMark");
33
+
34
+ expect(checkFieldLabel).toBeTruthy();
35
+ expect(checkFieldInput).toBeTruthy();
36
+ expect(checkFieldCheckMark).toBeTruthy();
37
+ });
38
+
39
+ it("should render the component with icon", () => {
40
+ const props = {
41
+ name: "",
42
+ title: "",
43
+ value: "",
44
+ checked: false,
45
+ error: false,
46
+ disabled: false,
47
+ indeterminate: false,
48
+ onChange: jest.fn(),
49
+ icon: "icon",
50
+ };
51
+
52
+ render(
53
+ <ThemeProvider theme={parseTheme(globalTheme)}>
54
+ <CheckField {...props} />
55
+ </ThemeProvider>
56
+ );
57
+
58
+ const checkFieldInput = screen.getByTestId("checkFieldInput");
59
+
60
+ expect(checkFieldInput).toBeTruthy();
61
+ });
62
+ });
63
+
64
+ describe("CheckField events", () => {
65
+ it("should call the onchange", () => {
66
+ const onChangeMock = jest.fn();
67
+
68
+ const props = {
69
+ name: "name",
70
+ title: "title",
71
+ value: "empty",
72
+ checked: false,
73
+ error: false,
74
+ disabled: false,
75
+ indeterminate: false,
76
+ onChange: onChangeMock,
77
+ icon: "icon",
78
+ };
79
+
80
+ render(
81
+ <ThemeProvider theme={parseTheme(globalTheme)}>
82
+ <CheckField {...props} />
83
+ </ThemeProvider>
84
+ );
85
+
86
+ const checkFieldLabel = screen.getByTestId("checkFieldLabel");
87
+ const checkFieldInput = screen.getByTestId<HTMLInputElement>("checkFieldInput");
88
+
89
+ expect(checkFieldLabel).toBeTruthy();
90
+ expect(checkFieldInput).toBeTruthy();
91
+ fireEvent.change(checkFieldInput, { target: { checked: true, value: "lalala" } });
92
+ expect(checkFieldInput.value).toBe("lalala");
93
+ expect(checkFieldInput.checked).toBe(true);
94
+ });
95
+ });
@@ -24,9 +24,9 @@ const CheckField = ({
24
24
 
25
25
  return (
26
26
  <S.Wrapper>
27
- <S.Label disabled={disabled}>
27
+ <S.Label data-testid={"checkFieldLabel"} disabled={disabled}>
28
28
  {icon ? (
29
- <S.IconLabelWrapper>
29
+ <S.IconLabelWrapper data-testid={"checkFieldIconLabel"}>
30
30
  <S.IconWrapper>
31
31
  <Icon name={icon} />
32
32
  </S.IconWrapper>
@@ -36,6 +36,7 @@ const CheckField = ({
36
36
  title
37
37
  )}
38
38
  <S.Input
39
+ data-testid={"checkFieldInput"}
39
40
  type="checkbox"
40
41
  name={`${name}`}
41
42
  value={value || ""}
@@ -43,7 +44,12 @@ const CheckField = ({
43
44
  disabled={disabled}
44
45
  onChange={handleChange}
45
46
  />
46
- <S.CheckMark checked={checked} error={error} indeterminate={indeterminate} />
47
+ <S.CheckMark
48
+ data-testid={"checkFieldCheckMark"}
49
+ checked={checked}
50
+ error={error}
51
+ indeterminate={indeterminate}
52
+ />
47
53
  </S.Label>
48
54
  </S.Wrapper>
49
55
  );