@griddo/ax 10.5.4 → 10.6.1

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 (52) hide show
  1. package/package.json +2 -2
  2. package/src/__tests__/components/Fields/ComponentArray/MixableComponentArray/MixableComponentArray.test.tsx +3 -3
  3. package/src/components/Button/style.tsx +1 -1
  4. package/src/components/ConfigPanel/Form/ConnectedField/NavConnectedField/index.tsx +2 -2
  5. package/src/components/ConfigPanel/Form/ConnectedField/PageConnectedField/TemplateManager/index.tsx +2 -2
  6. package/src/components/ConfigPanel/Form/ConnectedField/PageConnectedField/index.tsx +3 -3
  7. package/src/components/Fields/ComponentArray/MixableComponentArray/index.tsx +4 -3
  8. package/src/components/Fields/ImageField/index.tsx +19 -2
  9. package/src/components/Gallery/GalleryPanel/DetailPanel/index.tsx +8 -5
  10. package/src/components/Gallery/GalleryPanel/GalleryDragAndDrop/index.tsx +15 -5
  11. package/src/components/Gallery/GalleryPanel/GalleryDragAndDrop/style.tsx +1 -0
  12. package/src/components/Gallery/GalleryPanel/index.tsx +2 -11
  13. package/src/components/MenuGroup/index.tsx +81 -0
  14. package/src/components/MenuGroup/style.tsx +46 -0
  15. package/src/components/MenuItem/index.tsx +14 -7
  16. package/src/components/MenuItem/style.tsx +48 -26
  17. package/src/components/Nav/index.tsx +2 -2
  18. package/src/components/SideModal/index.tsx +2 -1
  19. package/src/components/Tooltip/index.tsx +1 -1
  20. package/src/components/index.tsx +2 -0
  21. package/src/containers/Gallery/actions.tsx +10 -2
  22. package/src/containers/Sites/actions.tsx +27 -0
  23. package/src/containers/Sites/constants.tsx +1 -0
  24. package/src/containers/Sites/interfaces.tsx +6 -0
  25. package/src/containers/Sites/reducer.tsx +4 -0
  26. package/src/helpers/index.tsx +2 -2
  27. package/src/helpers/themes.tsx +18 -13
  28. package/src/modules/Categories/CategoriesList/CategoryNav/NavItem/index.tsx +2 -2
  29. package/src/modules/Content/BulkHeader/TableHeader/index.tsx +1 -5
  30. package/src/modules/Content/BulkHeader/TableHeader/style.tsx +6 -0
  31. package/src/modules/Content/ContentFilters/index.tsx +66 -41
  32. package/src/modules/Content/ContentFilters/style.tsx +4 -38
  33. package/src/modules/Content/ContentFilters/utils.tsx +47 -10
  34. package/src/modules/Content/OptionTable/index.tsx +13 -14
  35. package/src/modules/Content/index.tsx +26 -7
  36. package/src/modules/Content/utils.tsx +5 -5
  37. package/src/modules/Navigation/Defaults/Nav/index.tsx +4 -6
  38. package/src/modules/Navigation/Menus/List/Nav/index.tsx +2 -2
  39. package/src/modules/Settings/ContentTypes/DataPacks/Nav/index.tsx +6 -10
  40. package/src/modules/StructuredData/StructuredDataList/BulkHeader/TableHeader/index.tsx +1 -6
  41. package/src/modules/StructuredData/StructuredDataList/BulkHeader/TableHeader/style.tsx +6 -0
  42. package/src/modules/StructuredData/StructuredDataList/ContentFilters/index.tsx +33 -41
  43. package/src/modules/StructuredData/StructuredDataList/ContentFilters/style.tsx +4 -38
  44. package/src/modules/StructuredData/StructuredDataList/ContentFilters/utils.tsx +44 -11
  45. package/src/modules/StructuredData/StructuredDataList/OptionTable/index.tsx +5 -5
  46. package/src/modules/StructuredData/StructuredDataList/index.tsx +1 -2
  47. package/src/modules/Users/UserForm/index.tsx +13 -27
  48. package/src/routes/multisite.tsx +1 -1
  49. package/src/routes/site.tsx +1 -1
  50. package/src/types/index.tsx +15 -0
  51. package/src/modules/Content/ContentFilters/constants.tsx +0 -15
  52. package/src/modules/StructuredData/StructuredDataList/ContentFilters/constants.tsx +0 -21
@@ -82,7 +82,8 @@ function getSiteImages(props: IGetSiteImages): (dispatch: Dispatch, getState: ()
82
82
  function uploadImage(
83
83
  imageFiles: File | File[],
84
84
  site: number | string,
85
- setProgress?: (progress: number) => void
85
+ setProgress?: (progress: number) => void,
86
+ visible = true
86
87
  ): (dispatch: Dispatch) => Promise<IImage> {
87
88
  return async (dispatch) => {
88
89
  try {
@@ -95,6 +96,7 @@ function uploadImage(
95
96
  const form = new FormData();
96
97
  form.append("file", image);
97
98
  site && form.append("site", JSON.stringify(site));
99
+ visible === false && form.append("active", "false");
98
100
  const createdImage = await images.createImage(form, setProgress);
99
101
  return { ...createdImage, image };
100
102
  });
@@ -165,4 +167,10 @@ function deleteImage(imageID: number): (dispatch: Dispatch, getState: () => IRoo
165
167
  };
166
168
  }
167
169
 
168
- export { setIsLoading, getSiteImages, uploadImage, updateImage, deleteImage, uploadError };
170
+ function resetGalleryState(): (dispatch: Dispatch) => Promise<void> {
171
+ return async (dispatch) => {
172
+ dispatch(setUploadSuccess(false));
173
+ };
174
+ }
175
+
176
+ export { setIsLoading, getSiteImages, uploadImage, updateImage, deleteImage, uploadError, resetGalleryState };
@@ -5,6 +5,7 @@ import {
5
5
  SET_SITES_BY_LANG,
6
6
  SET_CURRENT_SITE_INFO,
7
7
  SET_CURRENT_SITE_PAGES,
8
+ SET_ALL_SITE_PAGES,
8
9
  SET_FILTER,
9
10
  SET_TOTAL_ITEMS,
10
11
  SET_SITES_TOTAL_ITEMS,
@@ -24,6 +25,7 @@ import {
24
25
  ISetSitesByLangAction,
25
26
  ISetCurrentSiteInfoAction,
26
27
  ISetCurrentSitePagesAction,
28
+ ISetAllSitePagesAction,
27
29
  ISetFilter,
28
30
  ISetTotalItems,
29
31
  ISetCurrentSiteLanguagesAction,
@@ -90,6 +92,10 @@ function setCurrentSitePages(currentSitePages: IPage[]): ISetCurrentSitePagesAct
90
92
  return { type: SET_CURRENT_SITE_PAGES, payload: { currentSitePages } };
91
93
  }
92
94
 
95
+ function setAllSitePages(allSitePages: IPage[]): ISetAllSitePagesAction {
96
+ return { type: SET_ALL_SITE_PAGES, payload: { allSitePages } };
97
+ }
98
+
93
99
  function setFilter(currentFilter: string | null): ISetFilter {
94
100
  return { type: SET_FILTER, payload: { currentFilter } };
95
101
  }
@@ -387,6 +393,26 @@ function getSitePages(
387
393
  };
388
394
  }
389
395
 
396
+ function getAllSitePages(params: IGetSitePagesParams): (dispatch: any) => Promise<void> {
397
+ return async (dispatch) => {
398
+ try {
399
+ const responseActions = {
400
+ handleSuccess: (response: any) => {
401
+ const { items } = response;
402
+ dispatch(setAllSitePages(items));
403
+ },
404
+ handleError: (response: any) => appActions.handleError(response)(dispatch),
405
+ };
406
+
407
+ const callback = async () => sites.getSitePages(params);
408
+
409
+ await handleRequest(callback, responseActions, [])(dispatch);
410
+ } catch (e) {
411
+ console.log(e); // FIXME: capturar errores mejor
412
+ }
413
+ };
414
+ }
415
+
390
416
  function getSiteLanguages(siteID: number): (dispatch: any) => Promise<void> {
391
417
  return async (dispatch) => {
392
418
  try {
@@ -738,6 +764,7 @@ export {
738
764
  setSiteInfo,
739
765
  getFilteredContent,
740
766
  getSitePages,
767
+ getAllSitePages,
741
768
  getSiteLanguages,
742
769
  deleteSite,
743
770
  publishSite,
@@ -6,6 +6,7 @@ export const SET_SITES_TOTAL_ITEMS = `${NAME}/SET_SITES_TOTAL_ITEMS`;
6
6
  export const SET_SITES_BY_LANG = `${NAME}/SET_SITES_BY_LANG`;
7
7
  export const SET_CURRENT_SITE_INFO = `${NAME}/SET_CURRENT_SITE_INFO`;
8
8
  export const SET_CURRENT_SITE_PAGES = `${NAME}/SET_CURRENT_SITE_PAGES`;
9
+ export const SET_ALL_SITE_PAGES = `${NAME}/SET_ALL_SITE_PAGES`;
9
10
  export const SET_FILTER: string | null = `${NAME}/SET_FILTER`;
10
11
  export const SET_TOTAL_ITEMS: string | null = `${NAME}/SET_TOTAL_ITEMS`;
11
12
  export const SET_CURRENT_SITE_LANGUAGES: string | null = `${NAME}/SET_CURRENT_SITE_LANGUAGES`;
@@ -4,6 +4,7 @@ import {
4
4
  SET_SITES_BY_LANG,
5
5
  SET_CURRENT_SITE_INFO,
6
6
  SET_CURRENT_SITE_PAGES,
7
+ SET_ALL_SITE_PAGES,
7
8
  SET_FILTER,
8
9
  SET_TOTAL_ITEMS,
9
10
  SET_CURRENT_SITE_LANGUAGES,
@@ -53,6 +54,11 @@ export interface ISetCurrentSitePagesAction {
53
54
  payload: { currentSitePages: any }; // FIXME: establecer type
54
55
  }
55
56
 
57
+ export interface ISetAllSitePagesAction {
58
+ type: typeof SET_ALL_SITE_PAGES;
59
+ payload: { allSitePages: any }; // FIXME: establecer type
60
+ }
61
+
56
62
  export interface ISetTotalItems {
57
63
  type: typeof SET_TOTAL_ITEMS;
58
64
  payload: { totalItems: number };
@@ -5,6 +5,7 @@ import {
5
5
  SET_SITES_BY_LANG,
6
6
  SET_CURRENT_SITE_INFO,
7
7
  SET_CURRENT_SITE_PAGES,
8
+ SET_ALL_SITE_PAGES,
8
9
  SET_FILTER,
9
10
  SET_TOTAL_ITEMS,
10
11
  SET_CURRENT_SITE_LANGUAGES,
@@ -24,6 +25,7 @@ import { SitesActionsCreators } from "./interfaces";
24
25
  export interface ISitesState {
25
26
  currentSiteName: string | null;
26
27
  currentSitePages: IPage[];
28
+ allSitePages: IPage[];
27
29
  sites: ISite[];
28
30
  recentSites: ISite[];
29
31
  sitesTotalItems: number;
@@ -56,6 +58,7 @@ const config = {
56
58
  export const initialState = {
57
59
  currentSiteName: null,
58
60
  currentSitePages: [],
61
+ allSitePages: [],
59
62
  sites: [],
60
63
  recentSites: [],
61
64
  sitesByLang: [],
@@ -81,6 +84,7 @@ export function reducer(state = initialState, action: any): ISitesState {
81
84
  case SET_SITES_BY_LANG:
82
85
  case SET_CURRENT_SITE_INFO:
83
86
  case SET_CURRENT_SITE_PAGES:
87
+ case SET_ALL_SITE_PAGES:
84
88
  case SET_TOTAL_ITEMS:
85
89
  case SET_CURRENT_SITE_LANGUAGES:
86
90
  case SET_INITIAL_VALUES:
@@ -103,7 +103,7 @@ import { isDevelopment } from "./environment";
103
103
  import {
104
104
  getDefaultTheme,
105
105
  getThemeElements,
106
- filterThemeElements,
106
+ filterThemeModules,
107
107
  filterThemeTemplates,
108
108
  filterThemeDatapacks,
109
109
  isTemplateExcludedFromTheme,
@@ -191,7 +191,7 @@ export {
191
191
  splitAndTrim,
192
192
  getDefaultTheme,
193
193
  getThemeElements,
194
- filterThemeElements,
194
+ filterThemeModules,
195
195
  filterThemeTemplates,
196
196
  filterThemeDatapacks,
197
197
  isTemplateExcludedFromTheme,
@@ -1,5 +1,6 @@
1
- import { IDataPack, IGriddoTheme, ITemplateOption, IThemeElements } from "@ax/types";
1
+ import { IDataPack, IGriddoTheme, ISchema, ITemplateOption, IThemeElements } from "@ax/types";
2
2
  import { themes } from "components";
3
+ import { getSchema } from "@ax/helpers";
3
4
 
4
5
  const getDefaultTheme = (): string => {
5
6
  const defaultTheme = (themes as IGriddoTheme[]).find((theme) => theme.default);
@@ -11,20 +12,19 @@ const getThemeElements = (theme: string): IThemeElements | undefined => {
11
12
  return (themes as IGriddoTheme[]).find((griddoTheme) => griddoTheme.value === theme)?.elements;
12
13
  };
13
14
 
14
- const filterThemeElements = (
15
- themeElements: IThemeElements | null,
16
- elements: string[],
17
- type: "modules" | "templates" | "datapacks"
18
- ): string[] => {
15
+ const filterThemeModules = (themeElements: IThemeElements | null, elements: string[]): string[] => {
19
16
  if (themeElements === null) return elements;
20
17
 
21
18
  const { exclude, include } = themeElements;
22
19
 
23
20
  let filteredElements: string[] = elements;
24
- if (exclude && Array.isArray(exclude[type])) {
25
- filteredElements = elements.filter((element: string) => !exclude[type]?.includes(element));
26
- } else if (include && Array.isArray(include[type])) {
27
- filteredElements = elements.filter((element: string) => include[type]?.includes(element));
21
+ if (exclude && Array.isArray(exclude.modules)) {
22
+ filteredElements = elements.filter((element: string) => !exclude.modules?.includes(element));
23
+ } else if (include && Array.isArray(include.modules)) {
24
+ filteredElements = elements.filter((element: string) => {
25
+ const schema: ISchema = getSchema(element);
26
+ return schema?.schemaType === "component" ? true : include.modules?.includes(element);
27
+ });
28
28
  }
29
29
 
30
30
  return filteredElements;
@@ -42,7 +42,9 @@ const filterThemeTemplates = (
42
42
  if (exclude && Array.isArray(exclude.templates)) {
43
43
  filteredElements = templates.filter((template) => !exclude.templates?.includes(template.value));
44
44
  } else if (include && Array.isArray(include.templates)) {
45
- filteredElements = templates.filter((template) => include.templates?.includes(template.value));
45
+ filteredElements = templates.filter(
46
+ (template) => include.templates?.includes(template.value) || template.value === "BasicTemplate"
47
+ );
46
48
  }
47
49
 
48
50
  return filteredElements;
@@ -70,7 +72,10 @@ const isTemplateExcludedFromTheme = (themeElements: IThemeElements | null, templ
70
72
 
71
73
  if (
72
74
  (exclude && Array.isArray(exclude.templates) && exclude.templates.includes(template)) ||
73
- (include && Array.isArray(include.templates) && !include.templates.includes(template))
75
+ (include &&
76
+ Array.isArray(include.templates) &&
77
+ !include.templates.includes(template) &&
78
+ template !== "BasicTemplate")
74
79
  ) {
75
80
  return true;
76
81
  }
@@ -81,7 +86,7 @@ const isTemplateExcludedFromTheme = (themeElements: IThemeElements | null, templ
81
86
  export {
82
87
  getDefaultTheme,
83
88
  getThemeElements,
84
- filterThemeElements,
89
+ filterThemeModules,
85
90
  filterThemeTemplates,
86
91
  filterThemeDatapacks,
87
92
  isTemplateExcludedFromTheme,
@@ -34,8 +34,8 @@ const NavItem = (props: IProps): JSX.Element => {
34
34
  const selectedClass = isSelected ? "selected" : "";
35
35
  const handleClick = () => onClick(category.id);
36
36
  return (
37
- <MenuItem key={category.id} onClick={handleClick}>
38
- <NavLink to="#" className={selectedClass}>
37
+ <MenuItem key={category.id} onClick={handleClick} className={selectedClass}>
38
+ <NavLink to="#">
39
39
  <S.Link active={isSelected}>{category.title}</S.Link>
40
40
  </NavLink>
41
41
  </MenuItem>
@@ -110,11 +110,7 @@ const TableHeader = (props: IProps): JSX.Element => {
110
110
  <NameFilter sortItems={sortItems} sortedState={sortedListStatus} />
111
111
  </S.NameWrapper>
112
112
  {CategoryColumns}
113
- {activeColumns.includes("type") && (
114
- <S.HeaderWrapper>
115
- <TypeFilter filterItems={filterItems} filters={typeFilters} value={filterValues.type} pointer="type" />
116
- </S.HeaderWrapper>
117
- )}
113
+ {activeColumns.includes("type") && <S.TypeHeader>Type</S.TypeHeader>}
118
114
  {activeColumns.includes("live") && (
119
115
  <S.HeaderWrapper>
120
116
  <LiveFilter filterItems={filterItems} value={filterValues.liveStatus} />
@@ -46,6 +46,11 @@ const SeoHeader = styled(Header)`
46
46
  width: 124px;
47
47
  `;
48
48
 
49
+ const TypeHeader = styled(Header)`
50
+ width: 170px;
51
+ justify-content: center;
52
+ `;
53
+
49
54
  const GlobalMark = styled(Header)`
50
55
  width: 24px;
51
56
  flex: 0 0 24px;
@@ -79,4 +84,5 @@ export {
79
84
  NameWrapper,
80
85
  HeaderWrapper,
81
86
  GlobalMark,
87
+ TypeHeader,
82
88
  };
@@ -2,14 +2,12 @@ import React from "react";
2
2
  import { connect } from "react-redux";
3
3
  import { NavLink } from "react-router-dom";
4
4
 
5
- import { deepClone } from "@ax/helpers";
6
- import { MenuItem, SubNav } from "@ax/components";
5
+ import { MenuGroup, MenuItem, SubNav } from "@ax/components";
7
6
  import { sitesActions } from "@ax/containers/Sites";
8
7
  import { pageEditorActions } from "@ax/containers/PageEditor";
9
8
  import { INITIAL_TEMPLATE } from "@ax/containers/PageEditor/constants";
10
9
  import { structuredDataActions } from "@ax/containers/StructuredData";
11
-
12
- import { filterStructure } from "./constants";
10
+ import { IQueryValue, IStructuredData } from "@ax/types";
13
11
  import { getFilters } from "./utils";
14
12
 
15
13
  import * as S from "./style";
@@ -19,64 +17,91 @@ const ContentFilters = (props: IProps): JSX.Element => {
19
17
  setContentFilter,
20
18
  current,
21
19
  dynamicValues,
20
+ isAllowedToCreate,
21
+ typeFilters,
22
22
  addTemplate,
23
23
  setSelectedStructuredData,
24
24
  resetFilter,
25
25
  setStructuredDataFilter,
26
+ setFilter,
27
+ addNew,
26
28
  } = props;
27
- const clonedStructure = deepClone(filterStructure);
28
- const filters = getFilters(clonedStructure, dynamicValues);
29
29
 
30
- return (
31
- <SubNav>
32
- {filters.map((category: any, key: number) => {
33
- return (
34
- <S.Item key={key}>
35
- <S.Heading>{category.title}</S.Heading>
36
- {category.filters &&
37
- category.filters.map((filter: any, filterKey: number) => {
38
- const { name, value, fromPage, firstTemplate } = filter;
30
+ const type = typeFilters[0].value;
31
+ const filters = getFilters(dynamicValues);
32
+
33
+ const handleClick = (value: string, fromPage = false, firstTemplate: string | null = null) => {
34
+ const hasTemplate = fromPage && firstTemplate;
39
35
 
40
- const hasTemplate = fromPage && firstTemplate;
36
+ resetFilter();
37
+ setContentFilter(value);
38
+ setSelectedStructuredData(value, "site");
39
+ current && setStructuredDataFilter(value);
40
+ if (hasTemplate) {
41
+ addTemplate(firstTemplate);
42
+ } else {
43
+ addTemplate(INITIAL_TEMPLATE);
44
+ }
45
+ };
41
46
 
42
- const handleClick = () => {
43
- resetFilter();
44
- setContentFilter(value);
45
- setSelectedStructuredData(value, "site");
46
- current && setStructuredDataFilter(value);
47
- if (hasTemplate) {
48
- addTemplate(firstTemplate);
49
- } else {
50
- addTemplate(INITIAL_TEMPLATE);
51
- }
52
- };
47
+ const handleClickBase = (value: string) => {
48
+ resetFilter();
53
49
 
54
- const isSelected = value === current;
55
- const selectedClass = isSelected ? "selected" : "";
50
+ let filter = value;
51
+ if (value === "unique") {
52
+ filter = "unique-pages";
53
+ setFilter("type", [{ value, label: value }]);
54
+ }
55
+
56
+ setContentFilter(filter);
57
+ setSelectedStructuredData(filter, "site");
58
+ current && setStructuredDataFilter(filter);
59
+ };
60
+
61
+ return (
62
+ <SubNav>
63
+ <S.Wrapper>
64
+ {filters.map((filter) => {
65
+ const isSelected = type === "all" ? filter.value === current : filter.value === type;
66
+ const selectedClass = isSelected ? "selected" : "";
56
67
 
57
- return (
58
- <MenuItem key={filterKey} onClick={handleClick}>
59
- <NavLink to="#" className={selectedClass}>
60
- <S.Link active={isSelected}>{name}</S.Link>
61
- </NavLink>
62
- </MenuItem>
63
- );
64
- })}
65
- </S.Item>
66
- );
67
- })}
68
+ return (
69
+ <React.Fragment key={filter.value}>
70
+ {!filter.items ? (
71
+ <MenuItem onClick={() => handleClickBase(filter.value)} className={selectedClass}>
72
+ <NavLink to="#">
73
+ <S.Link active={isSelected}>{filter.label}</S.Link>
74
+ </NavLink>
75
+ </MenuItem>
76
+ ) : (
77
+ <MenuGroup
78
+ filter={filter}
79
+ current={current}
80
+ onClick={handleClick}
81
+ addNew={addNew}
82
+ isAllowedToCreate={isAllowedToCreate}
83
+ />
84
+ )}
85
+ </React.Fragment>
86
+ );
87
+ })}
88
+ </S.Wrapper>
68
89
  </SubNav>
69
90
  );
70
91
  };
71
92
 
72
93
  interface IProps {
73
94
  current: string | undefined;
95
+ dynamicValues: IStructuredData[];
96
+ isAllowedToCreate: boolean;
97
+ typeFilters: IQueryValue[];
74
98
  setContentFilter(filter: string | null): void;
75
99
  addTemplate(template: string): void;
76
- dynamicValues: any;
77
100
  setSelectedStructuredData(id: string, scope: string): void;
78
101
  resetFilter(): void;
79
102
  setStructuredDataFilter: (filter: string) => void;
103
+ setFilter: (pointer: string, filter: IQueryValue[]) => void;
104
+ addNew: () => void;
80
105
  }
81
106
 
82
107
  const mapDispatchToProps = {
@@ -1,43 +1,9 @@
1
1
  import styled from "styled-components";
2
2
 
3
- export const Heading = styled.div`
4
- ${p => p.theme.textStyle.headingXXS};
5
- color: ${p => p.theme.color.textLowEmphasis};
6
- margin-bottom: ${p => p.theme.spacing.xs};
7
- cursor: default;
3
+ const Wrapper = styled.ul``;
8
4
 
9
- &:empty {
10
- display: none;
11
- }
5
+ const Link = styled.div<{ active: boolean }>`
6
+ color: ${(p) => (p.active ? p.theme.color.textHighEmphasis : p.theme.color.textMediumEmphasis)};
12
7
  `;
13
8
 
14
- export const SubItem = styled.div`
15
- display: block;
16
- ${p => p.theme.textStyle.uiM};
17
- color: ${p => p.theme.color.textHighEmphasis};
18
- clear: both;
19
- width: 100%;
20
-
21
- &:hover {
22
- cursor: pointer;
23
- }
24
-
25
- > a {
26
- display: flex;
27
- padding: ${p => p.theme.spacing.xs};
28
- border-radius: ${p => p.theme.radii.s};
29
- color: inherit;
30
-
31
- &:hover {
32
- background: ${p => p.theme.color.overlayHoverPrimary};
33
- }
34
- }
35
- `;
36
-
37
- export const Item = styled.div`
38
- margin-bottom: ${p => p.theme.spacing.m};
39
- `;
40
-
41
- export const Link = styled.div<{ active: boolean }>`
42
- color: ${p => p.active ? p.theme.color.textHighEmphasis : p.theme.color.textMediumEmphasis};
43
- `;
9
+ export { Wrapper, Link };
@@ -1,20 +1,57 @@
1
- const getDynamicFilters = (values: any) =>
1
+ import React from "react";
2
+ import { IContentFilter, IDynamicFilter, IStructuredData } from "@ax/types";
3
+
4
+ const getDynamicFilters = (values: IStructuredData[]): IDynamicFilter[] =>
2
5
  values &&
3
- values.map((value: any) => ({
4
- name: `${value.title}${value.local ? "" : " (Global)"}`,
6
+ values.map((value) => ({
7
+ label: `${value.title}${value.local ? "" : " (Global)"}`,
5
8
  value: value.id,
6
9
  fromPage: value.fromPage,
10
+ editable: value.editable ? value.editable : false,
7
11
  firstTemplate: value.schema.templates ? value.schema.templates[0] : null,
8
12
  }));
9
13
 
10
- const getFilters = (staticFilters: any, dynamicValues: any) => {
11
- staticFilters &&
12
- staticFilters.forEach((item: any) => {
13
- if (!item.filters.length) {
14
- item.filters = getDynamicFilters(dynamicValues);
15
- }
14
+ const getFilters = (dynamicValues: IStructuredData[]): IContentFilter[] => {
15
+ const filters: IContentFilter[] = [
16
+ { label: "All Content", value: "unique-pages" },
17
+ { label: "Base Pages", value: "unique" },
18
+ ];
19
+
20
+ const pageTypes = dynamicValues.filter((value) => value.fromPage);
21
+ const simpleTypes = dynamicValues.filter((value) => !value.fromPage);
22
+
23
+ if (pageTypes.length) {
24
+ filters.push({
25
+ label: "Page Content Types",
26
+ value: "pages",
27
+ items: getDynamicFilters(pageTypes),
28
+ description: (
29
+ <>
30
+ Content shown in a page. Data is filled
31
+ <br />
32
+ on a page and has a URL.
33
+ </>
34
+ ),
16
35
  });
17
- return staticFilters;
36
+ }
37
+
38
+ if (simpleTypes.length) {
39
+ filters.push({
40
+ label: "Simple Content Types",
41
+ value: "simple",
42
+ items: getDynamicFilters(simpleTypes),
43
+ description: (
44
+ <>
45
+ Pageless content. Data is entered on a<br />
46
+ form and consumed in lists and
47
+ <br />
48
+ distributors.
49
+ </>
50
+ ),
51
+ });
52
+ }
53
+
54
+ return filters;
18
55
  };
19
56
 
20
57
  export { getDynamicFilters, getFilters };
@@ -1,4 +1,4 @@
1
- import React, { useReducer, useEffect, useLayoutEffect } from "react";
1
+ import React, { useReducer, useEffect } from "react";
2
2
  import { connect } from "react-redux";
3
3
 
4
4
  import { IRootState, IStructuredData, ITemplateOption, IThemeElements } from "@ax/types";
@@ -24,6 +24,7 @@ const OptionTable = (props: IOptionTableProps): JSX.Element => {
24
24
  secondaryAction,
25
25
  structuredData,
26
26
  themeElements,
27
+ currentStructuredData,
27
28
  } = props;
28
29
 
29
30
  const filteredValues = filterThemeTemplates(themeElements, values);
@@ -39,8 +40,7 @@ const OptionTable = (props: IOptionTableProps): JSX.Element => {
39
40
  });
40
41
  };
41
42
 
42
- const currentOption = filterOptions(selectedValue, "value");
43
- const currentType = currentOption[0] ? currentOption[0].type : "static";
43
+ const currentType = currentStructuredData ? currentStructuredData.dataPacks[0] : "basics";
44
44
 
45
45
  const initialState: IOptionTableStore = {
46
46
  columnValues: filterOptions(currentType, "type"),
@@ -65,17 +65,11 @@ const OptionTable = (props: IOptionTableProps): JSX.Element => {
65
65
 
66
66
  let filteredOptionsByDataPack = filterOptionsByDataPack(state.selectedType);
67
67
 
68
- useLayoutEffect(() => {
68
+ useEffect(() => {
69
69
  displayOptions({ value: state.selectedType, label: state.selectedType });
70
70
  // eslint-disable-next-line react-hooks/exhaustive-deps
71
71
  }, []);
72
72
 
73
- useEffect(() => {
74
- const firstOption = filteredOptionsByDataPack[0] && filteredOptionsByDataPack[0].value;
75
- selectOption(firstOption, filteredOptionsByDataPack);
76
- // eslint-disable-next-line
77
- }, []);
78
-
79
73
  const setValue = (value: string, isStructuredData: boolean) => {
80
74
  setIsStructuredData(isStructuredData);
81
75
  isStructuredData ? selectData(value) : selectPage(value);
@@ -131,8 +125,11 @@ const OptionTable = (props: IOptionTableProps): JSX.Element => {
131
125
  });
132
126
 
133
127
  setValues(filteredOptionsByDataPack);
134
- const firstOption = filteredOptionsByDataPack[0] && filteredOptionsByDataPack[0].value;
135
- selectOption(firstOption, filteredOptionsByDataPack);
128
+ const selectedTemplate =
129
+ currentStructuredData && currentStructuredData.schema.templates
130
+ ? currentStructuredData.schema.templates[0]
131
+ : selectedValue;
132
+ selectOption(selectedTemplate, filteredOptionsByDataPack);
136
133
  };
137
134
 
138
135
  const handleChange = (value: string | boolean) => typeof value === "string" && selectOption(value);
@@ -147,8 +144,8 @@ const OptionTable = (props: IOptionTableProps): JSX.Element => {
147
144
  const isSelected = item.value === state.selectedType;
148
145
  const selectedClass = isSelected ? "selected" : "";
149
146
  return (
150
- <MenuItem key={`${item.value}${i}`}>
151
- <S.NavLink onClick={displayFilteredOptions} className={selectedClass}>
147
+ <MenuItem key={`${item.value}${i}`} className={selectedClass} onClick={displayFilteredOptions}>
148
+ <S.NavLink>
152
149
  <S.Link active={isSelected}>{item.label}</S.Link>
153
150
  </S.NavLink>
154
151
  </MenuItem>
@@ -198,11 +195,13 @@ interface IOptionTableProps {
198
195
  secondaryAction: IAction;
199
196
  structuredData: { global: IStructuredData[]; site: IStructuredData[] };
200
197
  themeElements: IThemeElements | null;
198
+ currentStructuredData: IStructuredData | null;
201
199
  }
202
200
 
203
201
  const mapStateToProps = (state: IRootState) => ({
204
202
  structuredData: state.structuredData.structuredData,
205
203
  themeElements: state.sites.themeElements,
204
+ currentStructuredData: state.structuredData.currentStructuredData,
206
205
  });
207
206
 
208
207
  const mapDispatchToProps = {