@griddo/ax 12.17.1 → 12.18.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.
- package/package.json +4 -4
- package/src/__tests__/components/ConfigPanel/Form/ConnectedField/PageConnectedField/TemplateManager/TemplateManagerWhiteList.test.tsx +89 -0
- package/src/__tests__/components/Login/LoginCollapsible.test.tsx +5 -5
- package/src/__tests__/components/Login/LoginDropdownCard.test.tsx +1 -1
- package/src/__tests__/components/Login/LoginGriddoId.test.tsx +13 -13
- package/src/__tests__/components/Login/LoginPending.test.tsx +273 -0
- package/src/__tests__/components/SideModal/SideModal.test.tsx +84 -1
- package/src/__tests__/containers/App/loginSSO.test.ts +57 -0
- package/src/__tests__/containers/PageEditor/pasteModule.test.ts +116 -0
- package/src/__tests__/hooks/pendingNavigation.test.tsx +214 -0
- package/src/__tests__/locales/loginLocale.test.ts +13 -2
- package/src/__tests__/modules/Login/Login.test.tsx +4 -4
- package/src/__tests__/modules/Login/signInOut.test.tsx +19 -1
- package/src/components/Button/index.tsx +8 -0
- package/src/components/ConfigPanel/Form/ConnectedField/PageConnectedField/TemplateManager/index.tsx +2 -1
- package/src/components/Login/LoginGriddoId/index.tsx +14 -27
- package/src/components/Login/LoginGriddoId/style.tsx +7 -2
- package/src/components/Login/LoginSSO/index.tsx +33 -10
- package/src/components/Login/LoginSSO/style.tsx +18 -0
- package/src/components/Login/index.tsx +1 -1
- package/src/components/SideModal/index.tsx +3 -1
- package/src/containers/App/actions.tsx +11 -3
- package/src/containers/PageEditor/actions.tsx +12 -7
- package/src/hooks/index.tsx +2 -0
- package/src/hooks/pendingNavigation.ts +63 -0
- package/src/locales/en-US.ts +2 -1
- package/src/locales/es-ES.ts +2 -1
- package/src/modules/Login/index.tsx +6 -4
- package/src/schemas/pages/GlobalPage.ts +3 -5
- package/src/schemas/pages/Page.ts +3 -5
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ErrorToast, Icon } from "@ax/components";
|
|
1
|
+
import { ErrorToast, Icon, Loader } from "@ax/components";
|
|
2
2
|
import type { IGlobalSettings } from "@ax/containers/App/reducer";
|
|
3
|
+
import { usePendingNavigation } from "@ax/hooks";
|
|
4
|
+
import { getLoginLocale } from "@ax/locales";
|
|
3
5
|
|
|
4
6
|
import LoginFooter from "../LoginFooter";
|
|
5
7
|
|
|
@@ -8,7 +10,16 @@ import * as S from "./style";
|
|
|
8
10
|
const LoginSSO = (props: ILoginSSOProps): JSX.Element => {
|
|
9
11
|
const { handleSSO, errorSSO, settings } = props;
|
|
10
12
|
|
|
11
|
-
const
|
|
13
|
+
const text = getLoginLocale();
|
|
14
|
+
// Una sola conexión SSO por clic: el botón se bloquea hasta que la página navega (o hasta que falla y se libera).
|
|
15
|
+
const { pending, run: handleClick } = usePendingNavigation(handleSSO);
|
|
16
|
+
const buttonProps = {
|
|
17
|
+
type: "button" as const,
|
|
18
|
+
iconFill: false,
|
|
19
|
+
onClick: handleClick,
|
|
20
|
+
disabled: pending,
|
|
21
|
+
"aria-busy": pending,
|
|
22
|
+
};
|
|
12
23
|
|
|
13
24
|
const welcomeText = settings.SSOWelcomeText?.length ? (
|
|
14
25
|
settings.SSOWelcomeText
|
|
@@ -36,21 +47,32 @@ const LoginSSO = (props: ILoginSSOProps): JSX.Element => {
|
|
|
36
47
|
{errorSSO ? (
|
|
37
48
|
<>
|
|
38
49
|
<S.StyledNotification text={errorSSO} type="error" closeButton={false} />
|
|
39
|
-
<S.StyledButton
|
|
50
|
+
<S.StyledButton {...buttonProps}>
|
|
40
51
|
<S.ContentButton>
|
|
41
|
-
|
|
52
|
+
{pending && (
|
|
53
|
+
<S.LoaderIcon>
|
|
54
|
+
<Loader name="circle" size="16" />
|
|
55
|
+
</S.LoaderIcon>
|
|
56
|
+
)}
|
|
57
|
+
<S.TextButton>{pending ? text.connecting : "Try again"}</S.TextButton>
|
|
42
58
|
</S.ContentButton>
|
|
43
59
|
</S.StyledButton>
|
|
44
60
|
</>
|
|
45
61
|
) : (
|
|
46
62
|
<>
|
|
47
63
|
<S.Text>{welcomeText}</S.Text>
|
|
48
|
-
<S.StyledButton
|
|
64
|
+
<S.StyledButton {...buttonProps}>
|
|
49
65
|
<S.ContentButton>
|
|
50
|
-
|
|
51
|
-
<
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
{pending ? (
|
|
67
|
+
<S.LoaderIcon>
|
|
68
|
+
<Loader name="circle" size="16" />
|
|
69
|
+
</S.LoaderIcon>
|
|
70
|
+
) : (
|
|
71
|
+
<S.IconButton>
|
|
72
|
+
<Icon name="microsoft" size="16" viewBox={16} />
|
|
73
|
+
</S.IconButton>
|
|
74
|
+
)}
|
|
75
|
+
<S.TextButton>{pending ? text.connecting : "Microsoft ID"}</S.TextButton>
|
|
54
76
|
</S.ContentButton>
|
|
55
77
|
</S.StyledButton>
|
|
56
78
|
</>
|
|
@@ -63,7 +85,8 @@ const LoginSSO = (props: ILoginSSOProps): JSX.Element => {
|
|
|
63
85
|
};
|
|
64
86
|
|
|
65
87
|
interface ILoginSSOProps {
|
|
66
|
-
|
|
88
|
+
/** Inicia el flujo SSO. Si devuelve (o resuelve a) `null` o `""` no hay URL y el botón se libera. */
|
|
89
|
+
handleSSO: () => Promise<unknown> | unknown;
|
|
67
90
|
errorSSO: string | null;
|
|
68
91
|
settings: IGlobalSettings;
|
|
69
92
|
}
|
|
@@ -62,6 +62,23 @@ const IconButton = styled.div`
|
|
|
62
62
|
margin-right: ${(p) => p.theme.spacing.xs};
|
|
63
63
|
`;
|
|
64
64
|
|
|
65
|
+
// Loader «conectando»: ocupa el hueco del icono de marca. `Button` posiciona todo `svg` en absoluto contra su etiqueta
|
|
66
|
+
// (pensado para su prop `loader`); aquí va en el flujo, junto al texto, para que el conjunto quede centrado.
|
|
67
|
+
const LoaderIcon = styled.div`
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
justify-content: center;
|
|
71
|
+
width: ${(p) => p.theme.spacing.s};
|
|
72
|
+
height: ${(p) => p.theme.spacing.s};
|
|
73
|
+
margin-right: ${(p) => p.theme.spacing.xs};
|
|
74
|
+
svg {
|
|
75
|
+
position: static;
|
|
76
|
+
transform: none;
|
|
77
|
+
width: 100%;
|
|
78
|
+
height: 100%;
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
81
|
+
|
|
65
82
|
const TextButton = styled.div``;
|
|
66
83
|
|
|
67
84
|
const StyledNotification = styled((props) => <Notification {...props} />)`
|
|
@@ -71,6 +88,7 @@ const StyledNotification = styled((props) => <Notification {...props} />)`
|
|
|
71
88
|
export {
|
|
72
89
|
ContentButton,
|
|
73
90
|
IconButton,
|
|
91
|
+
LoaderIcon,
|
|
74
92
|
Logo,
|
|
75
93
|
Main,
|
|
76
94
|
StartWrapper,
|
|
@@ -113,7 +113,7 @@ export interface ILoginProps {
|
|
|
113
113
|
handleRememberMe: () => void;
|
|
114
114
|
isLoginSuccess: boolean;
|
|
115
115
|
handleLoginSuccess: () => void;
|
|
116
|
-
handleSSO: () =>
|
|
116
|
+
handleSSO: () => Promise<unknown> | unknown;
|
|
117
117
|
/** Navega a `/sso/start` de la API (login con auth.griddo.io). */
|
|
118
118
|
handleGriddoId?: () => void;
|
|
119
119
|
errorSSO: string | null;
|
|
@@ -148,7 +148,9 @@ const SideModal = (props: ISideModalProps): JSX.Element | null => {
|
|
|
148
148
|
if (!name.includes(search)) return null;
|
|
149
149
|
}
|
|
150
150
|
return (
|
|
151
|
-
|
|
151
|
+
// Index suffix keeps keys unique when the same option arrives twice (sc-125145); `i` is stable while
|
|
152
|
+
// searching because non-matching options render null instead of being removed.
|
|
153
|
+
<SideModalOption option={option} handleClick={handleClick} key={`${optionKey}-${i}`} theme={theme}>
|
|
152
154
|
{displayName}
|
|
153
155
|
</SideModalOption>
|
|
154
156
|
);
|
|
@@ -322,18 +322,26 @@ function login(loginData: {
|
|
|
322
322
|
};
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
+
/**
|
|
326
|
+
* Pide a la API la URL del SSO. Marca `isLogging` al empezar; si no hay URL (estado HTTP no OK, cuerpo vacío o error de red) lo
|
|
327
|
+
* repone a `false` y devuelve `null`. Con URL lo deja en `true`: la página se descarga al navegar.
|
|
328
|
+
*
|
|
329
|
+
* @returns La URL a la que navegar, o `null` si no se pudo obtener.
|
|
330
|
+
*/
|
|
325
331
|
function loginSSO(): (dispatch: Dispatch) => Promise<string | null> {
|
|
326
332
|
return async (dispatch) => {
|
|
327
333
|
try {
|
|
328
334
|
dispatch(setIsLogging(true));
|
|
329
335
|
const response: { status: number; data: any } = await global.login();
|
|
330
336
|
|
|
331
|
-
if (isReqOk(response?.status)) {
|
|
337
|
+
if (isReqOk(response?.status) && response.data) {
|
|
332
338
|
return response.data;
|
|
333
|
-
} else {
|
|
334
|
-
return null;
|
|
335
339
|
}
|
|
340
|
+
|
|
341
|
+
dispatch(setIsLogging(false));
|
|
342
|
+
return null;
|
|
336
343
|
} catch (_error) {
|
|
344
|
+
dispatch(setIsLogging(false));
|
|
337
345
|
return null;
|
|
338
346
|
}
|
|
339
347
|
};
|
|
@@ -1098,21 +1098,26 @@ function pasteModule(
|
|
|
1098
1098
|
const validatedModuleCopy: any = deepClone(element);
|
|
1099
1099
|
|
|
1100
1100
|
if (element.hasDistributorData) {
|
|
1101
|
-
const { mode, fixed } = element.data;
|
|
1101
|
+
const { mode, fixed, fullRelations, site } = element.data;
|
|
1102
1102
|
const isManualMode = mode === "manual" && !!fixed?.length;
|
|
1103
1103
|
if (isManualMode) {
|
|
1104
|
-
|
|
1104
|
+
// Same request the manual distributor list (ReferenceField/ItemList) uses, so what the module
|
|
1105
|
+
// shows is what survives the paste. `data.site` is only the selector's value when the editor
|
|
1106
|
+
// pressed Add, not the site the data belong to, so it must not be used to filter.
|
|
1107
|
+
const response = await structuredData.getDistributorContent(currentSiteInfo?.id ?? "global", {
|
|
1108
|
+
mode: "manual",
|
|
1109
|
+
fixed,
|
|
1110
|
+
fullRelations,
|
|
1111
|
+
site,
|
|
1112
|
+
});
|
|
1105
1113
|
if (isReqOk(response.status)) {
|
|
1106
|
-
const validDataIds: number[] =
|
|
1107
|
-
response.data.items.forEach((data: IStructuredDataContent) => {
|
|
1108
|
-
data.relatedSite && validDataIds.push(data.id);
|
|
1109
|
-
});
|
|
1114
|
+
const validDataIds: number[] = response.data.map((data: IStructuredDataContent) => data.id);
|
|
1110
1115
|
const hasInvalidData = validDataIds.length < fixed.length;
|
|
1111
1116
|
validatedModuleCopy.data.fixed = validDataIds;
|
|
1112
1117
|
if (hasInvalidData) {
|
|
1113
1118
|
error = {
|
|
1114
1119
|
type: "warning",
|
|
1115
|
-
text: "Some distributor data were not copied because they
|
|
1120
|
+
text: "Some distributor data were not copied because they no longer exist",
|
|
1116
1121
|
};
|
|
1117
1122
|
}
|
|
1118
1123
|
}
|
package/src/hooks/index.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import { useOnMessageReceivedFromIframe, useOnMessageReceivedFromOutside } from
|
|
|
15
15
|
import { useURLSearchParam } from "./location";
|
|
16
16
|
import { useContextMenu, useHandleClickOutside, useModal, useModals, useToast } from "./modals";
|
|
17
17
|
import { useNetworkStatus } from "./network";
|
|
18
|
+
import { usePendingNavigation } from "./pendingNavigation";
|
|
18
19
|
import { useResizable } from "./resize";
|
|
19
20
|
import {
|
|
20
21
|
type KeyCombo,
|
|
@@ -83,6 +84,7 @@ export {
|
|
|
83
84
|
useNetworkStatus,
|
|
84
85
|
useOnMessageReceivedFromIframe,
|
|
85
86
|
useOnMessageReceivedFromOutside,
|
|
87
|
+
usePendingNavigation,
|
|
86
88
|
usePermission,
|
|
87
89
|
usePermissions,
|
|
88
90
|
usePermissionsForPage,
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Protege una acción que acaba navegando fuera de la página (SSO, Griddo ID): tras lanzarla, el estado `pending`
|
|
5
|
+
* se mantiene (la página se descarga) y los clics siguientes se ignoran.
|
|
6
|
+
*
|
|
7
|
+
* - La guarda es síncrona (`useRef`): dos clics antes del re-render lanzan una sola acción.
|
|
8
|
+
* - `pending` vuelve a `false` si la acción devuelve `null` o `""` (no hay URL) o falla; con cualquier otro valor
|
|
9
|
+
* (una URL, o `undefined` cuando la propia acción navega) se mantiene.
|
|
10
|
+
* - `pageshow` con `persisted` (el navegador restaura la página desde su caché con «Atrás») reinicia guarda y estado.
|
|
11
|
+
* - Tras desmontar no actualiza estado.
|
|
12
|
+
*
|
|
13
|
+
* @param action Acción a ejecutar; puede ser síncrona o asíncrona. Siempre se usa la última recibida.
|
|
14
|
+
* @returns `pending` para pintar el botón y `run` para el `onClick`. `run` nunca rechaza.
|
|
15
|
+
*/
|
|
16
|
+
const usePendingNavigation = (action: () => unknown) => {
|
|
17
|
+
const [pending, setPending] = useState(false);
|
|
18
|
+
const busy = useRef(false);
|
|
19
|
+
const mounted = useRef(true);
|
|
20
|
+
const actionRef = useRef(action);
|
|
21
|
+
actionRef.current = action;
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
mounted.current = true;
|
|
25
|
+
|
|
26
|
+
const handlePageShow = (e: PageTransitionEvent) => {
|
|
27
|
+
if (!e.persisted) return;
|
|
28
|
+
busy.current = false;
|
|
29
|
+
setPending(false);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
window.addEventListener("pageshow", handlePageShow);
|
|
33
|
+
|
|
34
|
+
return () => {
|
|
35
|
+
mounted.current = false;
|
|
36
|
+
window.removeEventListener("pageshow", handlePageShow);
|
|
37
|
+
};
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
40
|
+
const release = useCallback(() => {
|
|
41
|
+
busy.current = false;
|
|
42
|
+
if (mounted.current) setPending(false);
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
const run = useCallback(async (): Promise<void> => {
|
|
46
|
+
if (busy.current) return;
|
|
47
|
+
|
|
48
|
+
busy.current = true;
|
|
49
|
+
setPending(true);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const result = await actionRef.current();
|
|
53
|
+
if (result === null || result === "") release();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(error);
|
|
56
|
+
release();
|
|
57
|
+
}
|
|
58
|
+
}, [release]);
|
|
59
|
+
|
|
60
|
+
return { pending, run };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export { usePendingNavigation };
|
package/src/locales/en-US.ts
CHANGED
|
@@ -29,7 +29,8 @@ export const enUS = {
|
|
|
29
29
|
typeSomething: "Type something",
|
|
30
30
|
},
|
|
31
31
|
login: {
|
|
32
|
-
|
|
32
|
+
connecting: "Connecting…",
|
|
33
|
+
griddoIdButton: "Sign in with Griddo ID",
|
|
33
34
|
griddoIdText: "To start using Griddo, sign in with your Griddo account.",
|
|
34
35
|
welcome: "Welcome",
|
|
35
36
|
startPublishing: "Login to start publishing",
|
package/src/locales/es-ES.ts
CHANGED
|
@@ -29,7 +29,8 @@ export const esES = {
|
|
|
29
29
|
typeSomething: "Escribe algo",
|
|
30
30
|
},
|
|
31
31
|
login: {
|
|
32
|
-
|
|
32
|
+
connecting: "Conectando…",
|
|
33
|
+
griddoIdButton: "Sign in with Griddo ID",
|
|
33
34
|
griddoIdText: "Para empezar a usar Griddo, entra con tu cuenta de Griddo.",
|
|
34
35
|
welcome: "Welcome",
|
|
35
36
|
startPublishing: "Login to start publishing",
|
|
@@ -70,11 +70,13 @@ const LoginModule = (props: IProps) => {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
// Devuelve la URL (o `null`) para que el botón se libere si no hay a dónde navegar.
|
|
74
|
+
const handleClickSSO = async (): Promise<string | null> => {
|
|
74
75
|
const urlSSO = await loginSSO();
|
|
75
|
-
if (urlSSO)
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
if (!urlSSO) return null;
|
|
77
|
+
|
|
78
|
+
window.open(urlSSO, "_self");
|
|
79
|
+
return urlSSO;
|
|
78
80
|
};
|
|
79
81
|
|
|
80
82
|
// Navegación completa a la API: arranca el flujo OIDC (state, nonce y PKCE los genera la API). Lleva el email
|
|
@@ -137,29 +137,27 @@ export default {
|
|
|
137
137
|
title: "Meta robots advanced",
|
|
138
138
|
type: "CheckGroup",
|
|
139
139
|
key: "metasAdvanced",
|
|
140
|
+
// A CheckGroup saves the `name` of each checked option. `noimage` is not a
|
|
141
|
+
// robots directive: CX writes it as `noimageindex`. Renaming it would leave
|
|
142
|
+
// the pages that already saved it unchecked.
|
|
140
143
|
options: [
|
|
141
144
|
{
|
|
142
|
-
value: "noimageindex",
|
|
143
145
|
title: "No image index",
|
|
144
146
|
name: "noimage",
|
|
145
147
|
},
|
|
146
148
|
{
|
|
147
|
-
value: "nosnippet",
|
|
148
149
|
title: "No snippet",
|
|
149
150
|
name: "nosnippet",
|
|
150
151
|
},
|
|
151
152
|
{
|
|
152
|
-
value: "noodp",
|
|
153
153
|
title: "No ODP",
|
|
154
154
|
name: "noodp",
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
|
-
value: "noarchive",
|
|
158
157
|
title: "No archive",
|
|
159
158
|
name: "noarchive",
|
|
160
159
|
},
|
|
161
160
|
{
|
|
162
|
-
value: "noTranslate",
|
|
163
161
|
title: "No translate",
|
|
164
162
|
name: "noTranslate",
|
|
165
163
|
},
|
|
@@ -203,29 +203,27 @@ export default {
|
|
|
203
203
|
title: "Meta robots advanced",
|
|
204
204
|
type: "CheckGroup",
|
|
205
205
|
key: "metasAdvanced",
|
|
206
|
+
// A CheckGroup saves the `name` of each checked option. `noimage` is not a
|
|
207
|
+
// robots directive: CX writes it as `noimageindex`. Renaming it would leave
|
|
208
|
+
// the pages that already saved it unchecked.
|
|
206
209
|
options: [
|
|
207
210
|
{
|
|
208
|
-
value: "noimageindex",
|
|
209
211
|
title: "No image index",
|
|
210
212
|
name: "noimage",
|
|
211
213
|
},
|
|
212
214
|
{
|
|
213
|
-
value: "nosnippet",
|
|
214
215
|
title: "No snippet",
|
|
215
216
|
name: "nosnippet",
|
|
216
217
|
},
|
|
217
218
|
{
|
|
218
|
-
value: "noodp",
|
|
219
219
|
title: "No ODP",
|
|
220
220
|
name: "noodp",
|
|
221
221
|
},
|
|
222
222
|
{
|
|
223
|
-
value: "noarchive",
|
|
224
223
|
title: "No archive",
|
|
225
224
|
name: "noarchive",
|
|
226
225
|
},
|
|
227
226
|
{
|
|
228
|
-
value: "noTranslate",
|
|
229
227
|
title: "No translate",
|
|
230
228
|
name: "noTranslate",
|
|
231
229
|
},
|