@griddo/ax 12.15.1-astro-rc.0 → 12.16.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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The class names of client CSS modules must never need escaping in a selector.
3
+ * css-loader escapes them, and postcss-selector-parser >= 7.2.0 escapes them again
4
+ * (`.x__u\+nIs` lands in the CSS as `.x__u\\\+nIs`), so the rule stops matching
5
+ * the class the JS puts in the HTML.
6
+ */
7
+ const getCSSModuleLocalIdent = require("../webpack/getCSSModuleLocalIdent");
8
+
9
+ // css-loader passes the loader context and `{ context: rootContext, ... }`.
10
+ const localIdent = (file, localName) =>
11
+ getCSSModuleLocalIdent({ rootContext: "/project", resourcePath: `/project/${file}` }, "", localName, {
12
+ context: "/project",
13
+ });
14
+
15
+ describe("getCSSModuleLocalIdent", () => {
16
+ test.each([
17
+ // react-dev-utils hashes in standard base64: `tgnq+` and `dX/xb`
18
+ ["src/Search/styles.module.css", "header"],
19
+ ["src/Search/styles.module.css", "content"],
20
+ // characters css-loader escapes can also come from the folder or the class
21
+ ["src/Search (copy)/index.module.css", "menu"],
22
+ ["src/Search/styles.module.scss", "a+b"],
23
+ ])("%s .%s only uses [A-Za-z0-9_-]", (file, localName) => {
24
+ expect(localIdent(file, localName)).toMatch(/^[A-Za-z0-9_-]+$/);
25
+ });
26
+
27
+ test("keeps the react-dev-utils name when it has nothing to escape", () => {
28
+ expect(localIdent("src/Search/styles.module.css", "container")).toBe("styles_container__1dPva");
29
+ });
30
+ });
@@ -0,0 +1,10 @@
1
+ const getCRALocalIdent = require("react-dev-utils/getCSSModuleLocalIdent");
2
+
3
+ // Class names for client CSS modules, made only of characters that never need escaping.
4
+ //
5
+ // react-dev-utils names them `[name]_[local]__[hash]` with a standard base64 hash, so about
6
+ // one class in thirteen gets a `+`. css-loader escapes it (`.x__u\+nIs`) and, from 7.2.0 on,
7
+ // postcss-selector-parser escapes it again (`.x__u\\\+nIs`): the CSS rule stops matching the
8
+ // class the JS puts in the HTML (postcss/postcss-selector-parser#362). With nothing to escape,
9
+ // the selector comes out the same whatever version the client project installs.
10
+ module.exports = (...args) => getCRALocalIdent(...args).replace(/[^A-Za-z0-9_-]/g, "_");
@@ -10,7 +10,7 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
10
10
  const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
11
11
  const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
12
12
  const InterpolateHtmlPlugin = require("react-dev-utils/InterpolateHtmlPlugin");
13
- const getCSSModuleLocalIdent = require("react-dev-utils/getCSSModuleLocalIdent");
13
+ const getCSSModuleLocalIdent = require("./webpack/getCSSModuleLocalIdent");
14
14
  const paths = require("./paths");
15
15
  const modules = require("./modules");
16
16
  const getClientEnvironment = require("./env");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@griddo/ax",
3
3
  "description": "Griddo Author Experience",
4
- "version": "12.15.1-astro-rc.0",
4
+ "version": "12.16.0",
5
5
  "homepage": "https://griddo.io",
6
6
  "repository": {
7
7
  "type": "git",
@@ -127,7 +127,7 @@
127
127
  },
128
128
  "devDependencies": {
129
129
  "@biomejs/biome": "2.5.15",
130
- "@griddo/core": "12.15.1-astro-rc.0",
130
+ "@griddo/core": "12.16.0",
131
131
  "@types/redux-mock-store": "1.5.0",
132
132
  "@vitest/coverage-v8": "4.1.11",
133
133
  "axios-mock-adapter": "1.22.0",
@@ -138,7 +138,7 @@
138
138
  "vitest-styled-components": "1.0.0"
139
139
  },
140
140
  "peerDependencies": {
141
- "@griddo/core": "12.15.1-astro-rc.0"
141
+ "@griddo/core": "12.16.0"
142
142
  },
143
143
  "babel": {
144
144
  "presets": [
@@ -169,8 +169,7 @@
169
169
  "tsconfig.paths.json"
170
170
  ],
171
171
  "publishConfig": {
172
- "access": "public",
173
- "tag": "astro"
172
+ "access": "public"
174
173
  },
175
- "gitHead": "b416f7ba9579926b989d7f5f322e31d443cd0cc6"
174
+ "gitHead": "470a8ac4612e195620b63961403f7a2b25879b37"
176
175
  }
@@ -1,12 +1,17 @@
1
1
  import * as React from "react";
2
- import { ThemeProvider } from "styled-components";
2
+
3
+ import { pages } from "@ax/api";
4
+ import TranslateButton, { type ITranslateButtonProps } from "@ax/components/Fields/TranslateButton";
5
+ import { SET_CURRENT_PAGE_NAME, SET_EDITOR_CONTENT } from "@ax/containers/PageEditor/constants";
3
6
  import { parseTheme } from "@ax/helpers";
4
7
  import globalTheme from "@ax/themes/theme.json";
5
- import { render, cleanup, screen } from "../../../../../config/tests/test-utils";
6
- import { mock } from "vitest-mock-extended";
8
+
7
9
  import configureStore from "redux-mock-store";
8
10
  import thunk from "redux-thunk";
9
- import TranslateButton, { type ITranslateButtonProps } from "@ax/components/Fields/TranslateButton";
11
+ import { ThemeProvider } from "styled-components";
12
+ import { mock } from "vitest-mock-extended";
13
+
14
+ import { cleanup, fireEvent, render, screen, waitFor, within } from "../../../../../config/tests/test-utils";
10
15
 
11
16
  afterEach(cleanup);
12
17
 
@@ -263,3 +268,115 @@ describe("Translate Button component rendering", () => {
263
268
  expect(translatedNotificationWrapper).toBeFalsy();
264
269
  });
265
270
  });
271
+
272
+ // sc-123263 — la actualización reconstruye la versión traducida entera desde la original y la API
273
+ // la guarda en la misma llamada: los módulos que solo existían en la traducción se pierden. El
274
+ // modal solo avisaba de los textos.
275
+ describe("[UC-AX-translate-page] actualizar con IA una traducción existente", () => {
276
+ const ORIGINAL_LANG = 1;
277
+ const TRANSLATION_LANG = 2;
278
+ const TRANSLATION_ID = 26922;
279
+
280
+ const translatedPage = {
281
+ id: TRANSLATION_ID,
282
+ component: "Page",
283
+ title: "Previous title",
284
+ canBeTranslated: false,
285
+ originalLanguage: ORIGINAL_LANG,
286
+ };
287
+ const retranslatedPage = { ...translatedPage, title: "Retranslated title" };
288
+
289
+ const ui = (lang: number) => (
290
+ <ThemeProvider theme={parseTheme(globalTheme)}>
291
+ <TranslateButton {...({ lang, contentType: "page", disabled: false } as ITranslateButtonProps)} />
292
+ </ThemeProvider>
293
+ );
294
+
295
+ // La acción real corre contra el store: `generatePageContent` lee de él la plantilla, las
296
+ // navegaciones por defecto y el módulo seleccionado, y el contenido del editor lleva los
297
+ // `editorID` que le pone la carga de la página (el breadcrumb los busca).
298
+ const renderEditor = (lang = TRANSLATION_LANG) => {
299
+ const store = mockStore({
300
+ app: { globalSettings: { autoTranslation: true } },
301
+ pageEditor: {
302
+ editorContent: { ...translatedPage, editorID: 0, parentEditorID: null },
303
+ selectedEditorID: 0,
304
+ isNewTranslation: false,
305
+ template: null,
306
+ },
307
+ navigation: { currentDefaultsContent: [] },
308
+ dataPacks: { configFormData: null },
309
+ structuredData: { form: null },
310
+ forms: { formContent: null },
311
+ });
312
+ return { store, ...render(ui(lang), { store }) };
313
+ };
314
+
315
+ const openUpdateModal = () => {
316
+ fireEvent.click(screen.getByRole("button", { name: /Update translation with AI/ }));
317
+ return within(screen.getByTestId("modal-component"));
318
+ };
319
+
320
+ it("AC8 · en una versión traducida se ofrece actualizarla con IA; en la original, no", () => {
321
+ const { rerender } = renderEditor();
322
+
323
+ const notice = screen.getByTestId("update-translation-button-wrapper");
324
+ expect(notice.textContent).toContain("already been translated");
325
+ expect(within(notice).getByRole("button", { name: /Update translation with AI/ })).toBeTruthy();
326
+
327
+ rerender(ui(ORIGINAL_LANG));
328
+ expect(screen.queryByTestId("update-translation-button-wrapper")).toBeFalsy();
329
+ });
330
+
331
+ it("AC9 · el modal avisa de que se sobrescribe la traducción, textos y módulos se igualan a la original y no se puede deshacer", () => {
332
+ renderEditor();
333
+ openUpdateModal();
334
+
335
+ const warning = screen.getByTestId("modal-component").textContent;
336
+ expect(warning).toContain("overwrite the current translation");
337
+ expect(warning).toContain("text and modules will be replaced to match the original page");
338
+ expect(warning).toContain("can’t be undone");
339
+ });
340
+
341
+ it("AC10 · confirmar regenera la versión traducida y el editor toma su contenido y su título; cancelar no pide nada", async () => {
342
+ const retranslate = vi
343
+ .spyOn(pages, "getPageRetranslation")
344
+ .mockResolvedValue({ status: 200, data: retranslatedPage } as any);
345
+ const { store } = renderEditor();
346
+
347
+ fireEvent.click(openUpdateModal().getByText("Cancel"));
348
+ expect(screen.queryByTestId("modal-component")).toBeFalsy();
349
+ expect(retranslate).not.toHaveBeenCalled();
350
+
351
+ fireEvent.click(openUpdateModal().getByText("Update translation with AI"));
352
+
353
+ await waitFor(() =>
354
+ expect(store.getActions()).toContainEqual({
355
+ type: SET_CURRENT_PAGE_NAME,
356
+ payload: { currentPageName: "Retranslated title" },
357
+ }),
358
+ );
359
+ expect(retranslate).toHaveBeenCalledWith(TRANSLATION_ID);
360
+ expect(store.getActions()).toContainEqual({
361
+ type: SET_EDITOR_CONTENT,
362
+ payload: { editorContent: expect.objectContaining({ id: TRANSLATION_ID, title: "Retranslated title" }) },
363
+ });
364
+ });
365
+
366
+ it("AC11 · si la actualización falla, avisa de que el contenido anterior se conserva y no lo sustituye", async () => {
367
+ vi.spyOn(pages, "getPageRetranslation").mockResolvedValue({
368
+ status: 400,
369
+ data: { code: 400, message: "Translation failed" },
370
+ } as any);
371
+ const { store } = renderEditor();
372
+
373
+ fireEvent.click(openUpdateModal().getByText("Update translation with AI"));
374
+
375
+ expect(
376
+ await screen.findByText("The translation could not be completed. Your previous content has been preserved."),
377
+ ).toBeTruthy();
378
+ const types = store.getActions().map((action) => action.type);
379
+ expect(types).not.toContain(SET_EDITOR_CONTENT);
380
+ expect(types).not.toContain(SET_CURRENT_PAGE_NAME);
381
+ });
382
+ });
@@ -83,12 +83,8 @@ const TranslateButton = (props: ITranslateButtonProps): JSX.Element => {
83
83
  }
84
84
  };
85
85
 
86
- const buttonText = state.error ? "Try againg" : state.isLoading ? "Processing..." : "Translate page with AI";
87
- const updateButtonText = state.error
88
- ? "Try againg"
89
- : state.isLoading
90
- ? "Processing..."
91
- : "Update translation with AI";
86
+ const buttonText = state.error ? "Try again" : state.isLoading ? "Processing..." : "Translate page with AI";
87
+ const updateButtonText = state.error ? "Try again" : state.isLoading ? "Processing..." : "Update translation with AI";
92
88
 
93
89
  return (
94
90
  <>
@@ -132,9 +128,8 @@ const TranslateButton = (props: ITranslateButtonProps): JSX.Element => {
132
128
  height="auto"
133
129
  >
134
130
  <S.ModalContent>
135
- This page <strong>already has a translation</strong>. Updating it{" "}
136
- <strong>will replace all existing text in this language</strong>, including any manual edits made after
137
- the previous translation. This action cannot be undone.
131
+ This will <strong>overwrite</strong> the current translation. All <strong>text and modules</strong> will
132
+ be replaced to match the original page. This can’t be undone.
138
133
  </S.ModalContent>
139
134
  </Modal>
140
135
  )}