@griddo/ax 11.9.9-rc.0 → 11.9.9-rc.2
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 +2 -2
- package/src/api/navigation.tsx +14 -0
- package/src/modules/Forms/FormUseModal/FormUseItem/index.tsx +42 -0
- package/src/modules/Forms/FormUseModal/FormUseItem/style.tsx +56 -0
- package/src/modules/Forms/FormUseModal/index.tsx +148 -77
- package/src/modules/Forms/FormUseModal/style.tsx +1 -27
- package/src/modules/Forms/FormUseModal/utils.tsx +103 -16
- package/src/types/forms.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "11.9.9-rc.
|
|
4
|
+
"version": "11.9.9-rc.2",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Diego M. Béjar <diego.bejar@secuoyas.com>",
|
|
@@ -225,5 +225,5 @@
|
|
|
225
225
|
"publishConfig": {
|
|
226
226
|
"access": "public"
|
|
227
227
|
},
|
|
228
|
-
"gitHead": "
|
|
228
|
+
"gitHead": "40e12cbab48091331921da9166d2acd62906854a"
|
|
229
229
|
}
|
package/src/api/navigation.tsx
CHANGED
|
@@ -72,6 +72,11 @@ const SERVICES: { [key: string]: IServiceConfig } = {
|
|
|
72
72
|
endpoint: "/navigations/page/bulk",
|
|
73
73
|
method: "PUT",
|
|
74
74
|
},
|
|
75
|
+
GET_NAVIGATIONS: {
|
|
76
|
+
...template,
|
|
77
|
+
endpoint: "/navigations",
|
|
78
|
+
method: "GET",
|
|
79
|
+
},
|
|
75
80
|
};
|
|
76
81
|
|
|
77
82
|
const getNavigation = (id: number) => {
|
|
@@ -200,6 +205,14 @@ const getPagesByFooter = async (footerID: number | number[], siteID: number) =>
|
|
|
200
205
|
|
|
201
206
|
const updatePageNavigation = (data: any) => sendRequest(SERVICES.UPDATE_PAGE_NAVIGATION, data);
|
|
202
207
|
|
|
208
|
+
const getNavigations = (ids: number[]) => {
|
|
209
|
+
const { host, endpoint } = SERVICES.GET_NAVIGATIONS;
|
|
210
|
+
|
|
211
|
+
SERVICES.GET_NAVIGATIONS.dynamicUrl = `${host}${endpoint}?ids=${ids}&skipDelete=true`;
|
|
212
|
+
|
|
213
|
+
return sendRequest(SERVICES.GET_NAVIGATIONS);
|
|
214
|
+
};
|
|
215
|
+
|
|
203
216
|
export default {
|
|
204
217
|
getNavigation,
|
|
205
218
|
getHeaders,
|
|
@@ -215,4 +228,5 @@ export default {
|
|
|
215
228
|
getPagesByHeader,
|
|
216
229
|
getPagesByFooter,
|
|
217
230
|
updatePageNavigation,
|
|
231
|
+
getNavigations,
|
|
218
232
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ElementsTooltip, IconAction } from "@ax/components";
|
|
3
|
+
|
|
4
|
+
import * as S from "./style";
|
|
5
|
+
|
|
6
|
+
const FormUseItem = (props: IFormUseItem): JSX.Element => {
|
|
7
|
+
const { isSiteView, title, subtitle, structuredDataTitle, categoryColors, availableSiteNames, goToItem } = props;
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<S.Item>
|
|
11
|
+
<S.PageInfo>
|
|
12
|
+
<S.Title>{title}</S.Title>
|
|
13
|
+
<S.SubTitle>{subtitle}</S.SubTitle>
|
|
14
|
+
</S.PageInfo>
|
|
15
|
+
<S.Type>
|
|
16
|
+
{structuredDataTitle && (
|
|
17
|
+
<ElementsTooltip elements={[structuredDataTitle]} colors={categoryColors} maxChar={30} rounded={true} />
|
|
18
|
+
)}
|
|
19
|
+
</S.Type>
|
|
20
|
+
{!isSiteView && (
|
|
21
|
+
<S.SiteInfo>
|
|
22
|
+
<ElementsTooltip elements={availableSiteNames} defaultColor="#E8E8EC" elementsPerRow={1} maxChar={30} />
|
|
23
|
+
</S.SiteInfo>
|
|
24
|
+
)}
|
|
25
|
+
<S.Action>
|
|
26
|
+
<IconAction icon="openOutside" onClick={() => goToItem()} />
|
|
27
|
+
</S.Action>
|
|
28
|
+
</S.Item>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
interface IFormUseItem {
|
|
33
|
+
title: string;
|
|
34
|
+
subtitle: string;
|
|
35
|
+
isSiteView: boolean;
|
|
36
|
+
structuredDataTitle?: string;
|
|
37
|
+
categoryColors?: Record<string, string>;
|
|
38
|
+
availableSiteNames: string[];
|
|
39
|
+
goToItem(): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default FormUseItem;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
|
|
3
|
+
const Action = styled.div`
|
|
4
|
+
display: flex;
|
|
5
|
+
width: 56px;
|
|
6
|
+
flex-shrink: 0;
|
|
7
|
+
justify-content: flex-end;
|
|
8
|
+
align-items: center;
|
|
9
|
+
opacity: 0;
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
const Item = styled.div`
|
|
13
|
+
display: flex;
|
|
14
|
+
padding: ${(p) => `${p.theme.spacing.s} 0 ${p.theme.spacing.xs} 0`};
|
|
15
|
+
border-bottom: 1px solid ${(p) => p.theme.color.uiLine};
|
|
16
|
+
&:hover {
|
|
17
|
+
${Action} {
|
|
18
|
+
opacity: 1;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
const PageInfo = styled.div`
|
|
24
|
+
flex-grow: 1;
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
const Title = styled.div`
|
|
28
|
+
${(p) => p.theme.textStyle.uiL};
|
|
29
|
+
color: ${(p) => p.theme.color.textHighEmphasis};
|
|
30
|
+
margin-bottom: ${(p) => p.theme.spacing.xxs};
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
const SubTitle = styled.div`
|
|
34
|
+
${(p) => p.theme.textStyle.uiXS};
|
|
35
|
+
color: ${(p) => p.theme.color.textMediumEmphasis};
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
const Type = styled.div`
|
|
39
|
+
position: relative;
|
|
40
|
+
display: flex;
|
|
41
|
+
width: 200px;
|
|
42
|
+
flex-shrink: 0;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
align-items: center;
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
const SiteInfo = styled.div`
|
|
48
|
+
position: relative;
|
|
49
|
+
display: flex;
|
|
50
|
+
width: 200px;
|
|
51
|
+
flex-shrink: 0;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
align-items: center;
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
export { Item, PageInfo, Title, SubTitle, Type, SiteInfo, Action };
|
|
@@ -1,21 +1,41 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { connect } from "react-redux";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import {
|
|
5
|
+
IAvailableSites,
|
|
6
|
+
IFilterValue,
|
|
7
|
+
IGetPagesParams,
|
|
8
|
+
IModal,
|
|
9
|
+
INavigation,
|
|
10
|
+
IPage,
|
|
11
|
+
IQueryValue,
|
|
12
|
+
ISite,
|
|
13
|
+
} from "@ax/types";
|
|
14
|
+
import { CheckGroupFilter, Loading, Modal } from "@ax/components";
|
|
15
|
+
import { getStructuredDataTitle } from "@ax/helpers";
|
|
8
16
|
import { useCategoryColors } from "@ax/hooks";
|
|
9
17
|
import { appActions } from "@ax/containers/App";
|
|
10
18
|
import { pageEditorActions } from "@ax/containers/PageEditor";
|
|
19
|
+
import { navigationActions } from "@ax/containers/Navigation";
|
|
11
20
|
import { sitesActions } from "@ax/containers/Sites";
|
|
12
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
addSiteOptions,
|
|
23
|
+
getFilterDataIds,
|
|
24
|
+
getFilterSitesIds,
|
|
25
|
+
getNavigations,
|
|
26
|
+
getPages,
|
|
27
|
+
getSite,
|
|
28
|
+
getSiteOptions,
|
|
29
|
+
getStructuredDataOptions,
|
|
30
|
+
} from "./utils";
|
|
31
|
+
import FormUseItem from "./FormUseItem";
|
|
13
32
|
|
|
14
33
|
import * as S from "./style";
|
|
15
34
|
|
|
16
35
|
const FormUseModal = (props: IFormUseModalModal): JSX.Element => {
|
|
17
|
-
const { isOpen, toggleModal, formInUse, isSiteView
|
|
18
|
-
const { page } = formInUse || {};
|
|
36
|
+
const { isOpen, toggleModal, formInUse, isSiteView } = props;
|
|
37
|
+
const { page, header, footer } = formInUse || {};
|
|
38
|
+
const navigationsIds = React.useMemo(() => [...(header ?? []), ...(footer ?? [])], [header, footer]);
|
|
19
39
|
|
|
20
40
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
21
41
|
const [filters, setFilters] = useState({
|
|
@@ -23,22 +43,16 @@ const FormUseModal = (props: IFormUseModalModal): JSX.Element => {
|
|
|
23
43
|
filterSites: [{ value: "all", label: "All" }],
|
|
24
44
|
});
|
|
25
45
|
const [options, setOptions] = useState<Record<string, IFilterValue[]>>({
|
|
26
|
-
sites: [],
|
|
27
|
-
structuredData: [],
|
|
46
|
+
sites: [{ value: "all", name: "all", title: "All" }],
|
|
47
|
+
structuredData: [{ value: "all", name: "all", title: "All" }],
|
|
28
48
|
});
|
|
29
|
-
const [items, setItems] = useState<IPage[]>([]);
|
|
49
|
+
const [items, setItems] = useState<{ pages: IPage[]; navigations: INavigation[] }>({ pages: [], navigations: [] });
|
|
30
50
|
const { categoryColors, addCategoryColors } = useCategoryColors();
|
|
31
51
|
const firstUpdate = useRef(true);
|
|
32
52
|
|
|
33
53
|
const getParams = useCallback(() => {
|
|
34
|
-
const sitesIDs = filters.filterSites
|
|
35
|
-
|
|
36
|
-
.map((item) => (typeof item.value === "string" ? parseInt(item.value) : item.value));
|
|
37
|
-
|
|
38
|
-
const dataIDs = filters.filterStructuredData
|
|
39
|
-
.filter((item) => item.value !== "all" && item.value !== "unique")
|
|
40
|
-
.map((item) => item.value);
|
|
41
|
-
|
|
54
|
+
const sitesIDs = getFilterSitesIds(filters.filterSites);
|
|
55
|
+
const dataIDs = getFilterDataIds(filters.filterStructuredData);
|
|
42
56
|
const isBasicChecked = filters.filterStructuredData.some((item) => item.value === "unique");
|
|
43
57
|
|
|
44
58
|
const params: IGetPagesParams = {
|
|
@@ -56,32 +70,69 @@ const FormUseModal = (props: IFormUseModalModal): JSX.Element => {
|
|
|
56
70
|
useEffect(() => {
|
|
57
71
|
let isMounted = true;
|
|
58
72
|
|
|
59
|
-
const
|
|
60
|
-
if (!isMounted) return;
|
|
73
|
+
const fetchData = async () => {
|
|
61
74
|
setIsLoading(true);
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
let allSites: IFilterValue[] = [];
|
|
78
|
+
let structuredData: IFilterValue[] = [];
|
|
79
|
+
let pagesData: IPage[] = [];
|
|
80
|
+
let navsData: INavigation[] = [];
|
|
81
|
+
|
|
82
|
+
if (page && page.length) {
|
|
83
|
+
const params = getParams();
|
|
84
|
+
const data = await getPages(params);
|
|
85
|
+
|
|
86
|
+
if (isMounted && data.length) {
|
|
87
|
+
pagesData = data;
|
|
88
|
+
|
|
89
|
+
if (firstUpdate.current) {
|
|
90
|
+
allSites = getSiteOptions(data);
|
|
91
|
+
structuredData = getStructuredDataOptions(data);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const dataIDs = getFilterDataIds(filters.filterStructuredData);
|
|
97
|
+
if (!dataIDs.length && navigationsIds.length) {
|
|
98
|
+
const data = await getNavigations(navigationsIds);
|
|
99
|
+
|
|
100
|
+
if (isMounted && data.length) {
|
|
101
|
+
const sitesIDs = getFilterSitesIds(filters.filterSites);
|
|
102
|
+
navsData = sitesIDs.length ? data.filter((item: INavigation) => sitesIDs.includes(item.site)) : data;
|
|
103
|
+
|
|
104
|
+
if (firstUpdate.current) {
|
|
105
|
+
const siteIds = data.map((item: INavigation) => item.site);
|
|
106
|
+
const sitesWithNavs = await addSiteOptions(allSites, siteIds);
|
|
107
|
+
allSites = sitesWithNavs;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setItems((prev) =>
|
|
113
|
+
prev.pages.length !== pagesData.length || prev.navigations.length !== navsData.length
|
|
114
|
+
? { pages: pagesData, navigations: navsData }
|
|
115
|
+
: prev
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (firstUpdate.current && isMounted) {
|
|
119
|
+
setOptions((state) => ({
|
|
120
|
+
...state,
|
|
121
|
+
sites: [...state.sites, ...allSites],
|
|
122
|
+
structuredData: [...state.structuredData, ...structuredData],
|
|
123
|
+
}));
|
|
72
124
|
firstUpdate.current = false;
|
|
73
125
|
}
|
|
74
|
-
}
|
|
75
|
-
console.
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error("Error general en fetchData:", error);
|
|
128
|
+
} finally {
|
|
129
|
+
if (isMounted) setIsLoading(false);
|
|
76
130
|
}
|
|
77
|
-
setIsLoading(false);
|
|
78
131
|
};
|
|
79
132
|
|
|
80
|
-
|
|
81
|
-
getPages();
|
|
82
|
-
}
|
|
133
|
+
fetchData();
|
|
83
134
|
|
|
84
|
-
return
|
|
135
|
+
return () => {
|
|
85
136
|
isMounted = false;
|
|
86
137
|
};
|
|
87
138
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -91,17 +142,8 @@ const FormUseModal = (props: IFormUseModalModal): JSX.Element => {
|
|
|
91
142
|
setFilters((state) => ({ ...state, [pointer]: filter }));
|
|
92
143
|
};
|
|
93
144
|
|
|
94
|
-
const getSite = async (siteID: number) => {
|
|
95
|
-
const response: { status: number; data: ISite } = await sites.getSiteInfo(siteID);
|
|
96
|
-
const { status, data } = response;
|
|
97
|
-
if (isReqOk(status)) {
|
|
98
|
-
return data;
|
|
99
|
-
} else {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
145
|
const goToPage = async (pageID: number, siteID: number | null) => {
|
|
146
|
+
const { setCurrentPageID, setSiteInfo, setHistoryPush } = props;
|
|
105
147
|
if (!isSiteView && siteID) {
|
|
106
148
|
const siteInfo = await getSite(siteID);
|
|
107
149
|
if (siteInfo) {
|
|
@@ -115,7 +157,27 @@ const FormUseModal = (props: IFormUseModalModal): JSX.Element => {
|
|
|
115
157
|
}
|
|
116
158
|
};
|
|
117
159
|
|
|
118
|
-
const
|
|
160
|
+
const goToNavigation = async (navID: number, siteID: number, type: "header" | "footer") => {
|
|
161
|
+
const { setHeader, setFooter, setSelectedDefault, setHistoryPush, setSiteInfo } = props;
|
|
162
|
+
const isHeader = type === "header";
|
|
163
|
+
|
|
164
|
+
if (!isSiteView) {
|
|
165
|
+
const siteInfo = await getSite(siteID);
|
|
166
|
+
if (siteInfo) {
|
|
167
|
+
await setSiteInfo(siteInfo);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
setSelectedDefault(isHeader ? "Headers" : "Footers");
|
|
171
|
+
isHeader ? setHeader(navID) : setFooter(navID);
|
|
172
|
+
setHistoryPush("/sites/navigations/editor", true);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const pagesText = items.pages.length ? `${items.pages.length} page${items.pages.length > 1 ? "s" : ""}` : "";
|
|
176
|
+
const navigationsText = items.navigations.length
|
|
177
|
+
? `${items.navigations.length} navigation module${items.navigations.length > 1 ? "s" : ""}`
|
|
178
|
+
: "";
|
|
179
|
+
const andText = items.navigations.length && items.pages.length ? " and " : "";
|
|
180
|
+
const textInfo = `This form appears on ${pagesText}${andText}${navigationsText}:`;
|
|
119
181
|
|
|
120
182
|
return (
|
|
121
183
|
<Modal isOpen={isOpen} hide={toggleModal} title="Using this form" size="L" height={640}>
|
|
@@ -157,7 +219,25 @@ const FormUseModal = (props: IFormUseModalModal): JSX.Element => {
|
|
|
157
219
|
<Loading />
|
|
158
220
|
) : (
|
|
159
221
|
<S.ListContent>
|
|
160
|
-
{items.map((item) => {
|
|
222
|
+
{items.navigations.map((item) => {
|
|
223
|
+
const { id, title, site, type } = item;
|
|
224
|
+
|
|
225
|
+
const handleGoToNavigation = () => id && goToNavigation(id, site, type);
|
|
226
|
+
const availableSiteNames =
|
|
227
|
+
options.sites.filter((item) => item.name === site).map((item) => item.title) || [];
|
|
228
|
+
|
|
229
|
+
return (
|
|
230
|
+
<FormUseItem
|
|
231
|
+
key={id}
|
|
232
|
+
title={title}
|
|
233
|
+
subtitle={"Navigation modules"}
|
|
234
|
+
availableSiteNames={availableSiteNames}
|
|
235
|
+
isSiteView={isSiteView}
|
|
236
|
+
goToItem={handleGoToNavigation}
|
|
237
|
+
/>
|
|
238
|
+
);
|
|
239
|
+
})}
|
|
240
|
+
{items.pages.map((item) => {
|
|
161
241
|
const { id, title, fullPath, structuredData, availableSites, site } = item;
|
|
162
242
|
const structuredDataTitle = structuredData ? getStructuredDataTitle(structuredData) : "Base Page";
|
|
163
243
|
|
|
@@ -165,34 +245,19 @@ const FormUseModal = (props: IFormUseModalModal): JSX.Element => {
|
|
|
165
245
|
|
|
166
246
|
const availableSiteNames = availableSites?.map((site: IAvailableSites) => site.name) || [];
|
|
167
247
|
|
|
248
|
+
const handleGoToPage = () => goToPage(id, site);
|
|
249
|
+
|
|
168
250
|
return (
|
|
169
|
-
<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
rounded={true}
|
|
180
|
-
/>
|
|
181
|
-
</S.Type>
|
|
182
|
-
{!isSiteView && (
|
|
183
|
-
<S.SiteInfo>
|
|
184
|
-
<ElementsTooltip
|
|
185
|
-
elements={availableSiteNames}
|
|
186
|
-
defaultColor="#E8E8EC"
|
|
187
|
-
elementsPerRow={1}
|
|
188
|
-
maxChar={30}
|
|
189
|
-
/>
|
|
190
|
-
</S.SiteInfo>
|
|
191
|
-
)}
|
|
192
|
-
<S.Action>
|
|
193
|
-
<IconAction icon="openOutside" onClick={() => goToPage(id, site)} />
|
|
194
|
-
</S.Action>
|
|
195
|
-
</S.Item>
|
|
251
|
+
<FormUseItem
|
|
252
|
+
key={id}
|
|
253
|
+
title={title}
|
|
254
|
+
subtitle={fullPath?.page || ""}
|
|
255
|
+
structuredDataTitle={structuredDataTitle}
|
|
256
|
+
categoryColors={categoryColors}
|
|
257
|
+
availableSiteNames={availableSiteNames}
|
|
258
|
+
isSiteView={isSiteView}
|
|
259
|
+
goToItem={handleGoToPage}
|
|
260
|
+
/>
|
|
196
261
|
);
|
|
197
262
|
})}
|
|
198
263
|
</S.ListContent>
|
|
@@ -203,17 +268,23 @@ const FormUseModal = (props: IFormUseModalModal): JSX.Element => {
|
|
|
203
268
|
};
|
|
204
269
|
|
|
205
270
|
interface IFormUseModalModal extends IModal {
|
|
206
|
-
formInUse: { page
|
|
271
|
+
formInUse: { page?: number[]; header?: number[]; footer?: number[] } | null;
|
|
207
272
|
isSiteView: boolean;
|
|
208
273
|
setHistoryPush: (path: string, isEditor: boolean) => void;
|
|
209
274
|
setCurrentPageID: (currentPageID: number | null) => void;
|
|
210
275
|
setSiteInfo(currentSiteInfo: ISite): Promise<void>;
|
|
276
|
+
setSelectedDefault(selectedDefault: string): void;
|
|
277
|
+
setHeader(id: number | null): void;
|
|
278
|
+
setFooter(id: number | null): void;
|
|
211
279
|
}
|
|
212
280
|
|
|
213
281
|
const mapDispatchToProps = {
|
|
214
282
|
setHistoryPush: appActions.setHistoryPush,
|
|
215
283
|
setCurrentPageID: pageEditorActions.setCurrentPageID,
|
|
216
284
|
setSiteInfo: sitesActions.setSiteInfo,
|
|
285
|
+
setSelectedDefault: navigationActions.setSelectedDefault,
|
|
286
|
+
setHeader: navigationActions.setHeader,
|
|
287
|
+
setFooter: navigationActions.setFooter,
|
|
217
288
|
};
|
|
218
289
|
|
|
219
290
|
export default connect(null, mapDispatchToProps)(FormUseModal);
|
|
@@ -34,32 +34,6 @@ const Action = styled.div`
|
|
|
34
34
|
opacity: 0;
|
|
35
35
|
`;
|
|
36
36
|
|
|
37
|
-
const Item = styled.div`
|
|
38
|
-
display: flex;
|
|
39
|
-
padding: ${(p) => `${p.theme.spacing.s} 0 ${p.theme.spacing.xs} 0`};
|
|
40
|
-
border-bottom: 1px solid ${(p) => p.theme.color.uiLine};
|
|
41
|
-
&:hover {
|
|
42
|
-
${Action} {
|
|
43
|
-
opacity: 1;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
`;
|
|
47
|
-
|
|
48
|
-
const PageInfo = styled.div`
|
|
49
|
-
flex-grow: 1;
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
|
-
const Title = styled.div`
|
|
53
|
-
${(p) => p.theme.textStyle.uiL};
|
|
54
|
-
color: ${(p) => p.theme.color.textHighEmphasis};
|
|
55
|
-
margin-bottom: ${(p) => p.theme.spacing.xxs};
|
|
56
|
-
`;
|
|
57
|
-
|
|
58
|
-
const SubTitle = styled.div`
|
|
59
|
-
${(p) => p.theme.textStyle.uiXS};
|
|
60
|
-
color: ${(p) => p.theme.color.textMediumEmphasis};
|
|
61
|
-
`;
|
|
62
|
-
|
|
63
37
|
const Type = styled.div`
|
|
64
38
|
position: relative;
|
|
65
39
|
display: flex;
|
|
@@ -78,4 +52,4 @@ const SiteInfo = styled.div`
|
|
|
78
52
|
align-items: center;
|
|
79
53
|
`;
|
|
80
54
|
|
|
81
|
-
export { ModalContent, ListHeader, HeaderText, ListContent,
|
|
55
|
+
export { ModalContent, ListHeader, HeaderText, ListContent, Type, SiteInfo, Action };
|
|
@@ -1,21 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { navigation, pages, sites } from "@ax/api";
|
|
2
|
+
import { getStructuredDataTitle, isReqOk } from "@ax/helpers";
|
|
3
|
+
import { IFilterValue, IGetPagesParams, INavigation, IPage, ISite } from "@ax/types";
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
const getSite = async (siteID: number) => {
|
|
6
|
+
try {
|
|
7
|
+
const response: { status: number; data: ISite } = await sites.getSiteInfo(siteID);
|
|
8
|
+
const { status, data } = response;
|
|
9
|
+
if (isReqOk(status)) {
|
|
10
|
+
return data;
|
|
11
|
+
} else {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const getSiteOptions = (pages: IPage[]): IFilterValue[] => {
|
|
20
|
+
const sites = pages.flatMap((page) => page.availableSites ?? []);
|
|
21
|
+
const uniqueSites = new Map<number, IFilterValue>();
|
|
22
|
+
|
|
23
|
+
for (const site of sites) {
|
|
24
|
+
uniqueSites.set(site.id, {
|
|
25
|
+
value: site.id.toString(),
|
|
26
|
+
title: site.name,
|
|
27
|
+
name: site.id,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return Array.from(uniqueSites.values());
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const addSiteOptions = async (baseOptions: IFilterValue[], siteIDs: number[]): Promise<IFilterValue[]> => {
|
|
35
|
+
const existingIds = new Set(baseOptions.map((opt) => Number(opt.value)));
|
|
36
|
+
const idsToAdd = siteIDs.filter((id) => !existingIds.has(id));
|
|
37
|
+
|
|
38
|
+
if (idsToAdd.length === 0) return baseOptions;
|
|
39
|
+
|
|
40
|
+
const newSites = await Promise.all(
|
|
41
|
+
idsToAdd.map(async (id) => {
|
|
42
|
+
try {
|
|
43
|
+
const site = await getSite(id);
|
|
44
|
+
if (!site) return null;
|
|
45
|
+
return {
|
|
46
|
+
value: site.id.toString(),
|
|
47
|
+
title: site.name,
|
|
48
|
+
name: site.id,
|
|
49
|
+
} as IFilterValue;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(`Error al obtener site ${id}:`, error);
|
|
52
|
+
return null;
|
|
15
53
|
}
|
|
16
|
-
|
|
17
|
-
}, {})
|
|
54
|
+
})
|
|
18
55
|
);
|
|
56
|
+
|
|
57
|
+
const filteredNewSites = newSites.filter((s): s is IFilterValue => s !== null);
|
|
58
|
+
if (filteredNewSites.length === 0) return baseOptions;
|
|
59
|
+
|
|
60
|
+
return [...baseOptions, ...filteredNewSites];
|
|
19
61
|
};
|
|
20
62
|
|
|
21
63
|
const getStructuredDataOptions = (pages: IPage[]) => {
|
|
@@ -36,4 +78,49 @@ const getStructuredDataOptions = (pages: IPage[]) => {
|
|
|
36
78
|
);
|
|
37
79
|
};
|
|
38
80
|
|
|
39
|
-
|
|
81
|
+
const getFilterSitesIds = (filters: { value: string; label: string }[]) =>
|
|
82
|
+
filters
|
|
83
|
+
.filter((item) => item.value !== "all")
|
|
84
|
+
.map((item) => (typeof item.value === "string" ? parseInt(item.value) : item.value));
|
|
85
|
+
|
|
86
|
+
const getFilterDataIds = (filters: { value: string; label: string }[]) =>
|
|
87
|
+
filters.filter((item) => item.value !== "all" && item.value !== "unique").map((item) => item.value);
|
|
88
|
+
|
|
89
|
+
const getNavigations = async (navigations: number[]) => {
|
|
90
|
+
try {
|
|
91
|
+
const response: { status: number; data: { items: INavigation[] } } = await navigation.getNavigations(navigations);
|
|
92
|
+
const { status, data } = response;
|
|
93
|
+
if (isReqOk(status)) {
|
|
94
|
+
return data.items;
|
|
95
|
+
} else {
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
} catch {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const getPages = async (params: IGetPagesParams) => {
|
|
104
|
+
try {
|
|
105
|
+
const response: { status: number; data: { items: IPage[] } } = await pages.getPages(params);
|
|
106
|
+
const { status, data } = response;
|
|
107
|
+
if (isReqOk(status)) {
|
|
108
|
+
return data.items;
|
|
109
|
+
} else {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
} catch {
|
|
113
|
+
return [];
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
getSiteOptions,
|
|
119
|
+
getStructuredDataOptions,
|
|
120
|
+
getSite,
|
|
121
|
+
addSiteOptions,
|
|
122
|
+
getFilterSitesIds,
|
|
123
|
+
getFilterDataIds,
|
|
124
|
+
getNavigations,
|
|
125
|
+
getPages,
|
|
126
|
+
};
|
package/src/types/forms.tsx
CHANGED