fix: 修复模板画布点选与保存切页回归
This commit is contained in:
1 parent
e6d843b4a7
commit
cd2992c00a
15 files changed
+98
-40
No files matched your search
@@ -168,6 +168,6 @@
|
||||
display: block;
|
||||
}
|
||||
|
||||
.component-template-preview__overlay-host > * {
|
||||
.component-template-preview__overlay-host > .component-template-preview__composite-select {
|
||||
pointer-events: auto;
|
||||
}
|
||||
@@ -2,11 +2,7 @@ import { Alert, Button, Grid, Select, Segmented, Space, Typography } from "antd"
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type {
|
||||
AdminTemplateContent,
|
||||
RuntimeWorkspace,
|
||||
TemplateAdminSection,
|
||||
} from "@personal-brand/api-client";
|
||||
import type { AdminTemplateContent, RuntimeWorkspace } from "@personal-brand/api-client";
|
||||
import type { BrandProfile } from "@personal-brand/api-client";
|
||||
import { StatusTag } from "../../components/StatusTag.js";
|
||||
import { RecordContentEditor } from "../../components/RecordContentEditor.js";
|
||||
@@ -18,10 +14,7 @@ import {
|
||||
type PreviewSelection,
|
||||
type PreviewTarget,
|
||||
} from "./preview-selection.js";
|
||||
import {
|
||||
filterSectionsForPreviewTarget,
|
||||
type PresentationValues,
|
||||
} from "../../lib/presentation/presentation-bindings.js";
|
||||
import { filterSectionsForPreviewTarget } from "../../lib/presentation/presentation-bindings.js";
|
||||
import "./PresentationEditor.css";
|
||||
import { useEditorDraft } from "./use-editor-draft.js";
|
||||
import {
|
||||
@@ -213,7 +206,14 @@ export function PresentationEditor({
|
||||
: pageLinks;
|
||||
const formState = useBrandPresentationForm({ brand, config, sections });
|
||||
const { form, initialValues } = formState;
|
||||
const save = useBrandSaveMutation({ ...formState, brand, config, sections, queryClient });
|
||||
const save = useBrandSaveMutation({
|
||||
...formState,
|
||||
brand,
|
||||
config,
|
||||
sections,
|
||||
queryClient,
|
||||
onSaved: () => setBrandDirty(false),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const initialPage =
|
||||
|
||||
@@ -7,6 +7,7 @@ import { TemplateAssetContext } from "./taro-web-components.jsx";
|
||||
const templateRenderers = import.meta.glob("../../../../../packages/template-*/taro/index.tsx", {
|
||||
eager: true,
|
||||
});
|
||||
const resolvedRenderers = new Map();
|
||||
|
||||
function pageContent({ workspace, page }) {
|
||||
if (page === "inquiry") return <Inquiry workspace={workspace} preview />;
|
||||
@@ -22,15 +23,18 @@ export function resolveTemplateRenderer(workspace) {
|
||||
? config.visualTemplateKey
|
||||
: undefined;
|
||||
if (typeof key !== "string") return null;
|
||||
if (resolvedRenderers.has(key)) return resolvedRenderers.get(key);
|
||||
const suffix = `/template-${key}/taro/index.tsx`;
|
||||
const entry = Object.entries(templateRenderers).find(([path]) => path.endsWith(suffix));
|
||||
const TemplatePage = entry?.[1]?.TemplatePage;
|
||||
if (!TemplatePage) return null;
|
||||
return function TemplatePreview(props) {
|
||||
function TemplatePreview(props) {
|
||||
return (
|
||||
<TemplateAssetContext.Provider value={key}>
|
||||
<TemplatePage {...props}>{pageContent(props)}</TemplatePage>
|
||||
</TemplateAssetContext.Provider>
|
||||
);
|
||||
};
|
||||
}
|
||||
resolvedRenderers.set(key, TemplatePreview);
|
||||
return TemplatePreview;
|
||||
}
|
||||
@@ -98,6 +98,7 @@ interface BrandSaveMutationOptions extends BrandPresentationFormState {
|
||||
config: Record<string, unknown> | null | undefined;
|
||||
sections: TemplateAdminSection[];
|
||||
queryClient: QueryClient;
|
||||
onSaved: () => void;
|
||||
}
|
||||
|
||||
export function useBrandSaveMutation({
|
||||
@@ -105,6 +106,7 @@ export function useBrandSaveMutation({
|
||||
config,
|
||||
sections,
|
||||
queryClient,
|
||||
onSaved,
|
||||
}: BrandSaveMutationOptions) {
|
||||
return useMutation({
|
||||
mutationFn: (values: PresentationValues) => {
|
||||
@@ -125,6 +127,7 @@ export function useBrandSaveMutation({
|
||||
return createApiClient().updateAdminBrand({ ...changed, config: contentConfig });
|
||||
},
|
||||
onSuccess: () => {
|
||||
onSaved();
|
||||
message.success("页面内容已保存为草稿,发布后小程序才会更新");
|
||||
window.dispatchEvent(new Event("template-preview-refresh"));
|
||||
void queryClient.invalidateQueries({ queryKey: ["admin-brand"] });
|
||||
|
||||
@@ -860,6 +860,9 @@ test("real template declarations persist brand offering and trust bindings throu
|
||||
};
|
||||
let checked = 0;
|
||||
for (const slug of ["default-brand", "linjing-doors"]) {
|
||||
const originalPublicWorkspace = JSON.parse(
|
||||
(await request("/public/workspace?brandSlug=" + slug)).body,
|
||||
);
|
||||
const original = await prisma.brandProfile.findUniqueOrThrow({ where: { slug } });
|
||||
const originalOffering = await prisma.offering.findFirstOrThrow({
|
||||
where: { brandId: original.id, isEnabled: true },
|
||||
@@ -1030,6 +1033,15 @@ test("real template declarations persist brand offering and trust bindings throu
|
||||
);
|
||||
checked += 1;
|
||||
}
|
||||
const unpublishedWorkspace = JSON.parse(
|
||||
(await request("/public/workspace?brandSlug=" + slug)).body,
|
||||
);
|
||||
for (const key of ["brand", "templateData", "offerings", "trustItems", "trustPresentation"])
|
||||
assert.deepEqual(
|
||||
unpublishedWorkspace[key],
|
||||
originalPublicWorkspace[key],
|
||||
slug + " unpublished edits must preserve public " + key,
|
||||
);
|
||||
const publish = await request("/admin/releases/publish", {
|
||||
method: "POST",
|
||||
headers,
|
||||
|
||||
@@ -33,6 +33,7 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
|
||||
for (let index = 0; index < (await elements.count()); index++) {
|
||||
const element = elements.nth(index);
|
||||
if (!(await element.isVisible())) continue;
|
||||
await element.scrollIntoViewIfNeeded();
|
||||
const leafIndex = await element.evaluate((node, key) => {
|
||||
return Array.from(node.querySelectorAll("*")).findIndex((child) => {
|
||||
const rect = child.getBoundingClientRect();
|
||||
@@ -40,7 +41,11 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
|
||||
child.childElementCount === 0 &&
|
||||
rect.width > 0 &&
|
||||
rect.height > 0 &&
|
||||
child.closest("[data-editor-target]")?.getAttribute("data-editor-target") === key
|
||||
child.closest("[data-editor-target]")?.getAttribute("data-editor-target") === key &&
|
||||
document
|
||||
.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2)
|
||||
?.closest("[data-editor-target]")
|
||||
?.getAttribute("data-editor-target") === key
|
||||
);
|
||||
});
|
||||
}, target);
|
||||
@@ -61,6 +66,19 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
|
||||
};
|
||||
});
|
||||
expect(point.target, "实际命中区域:" + target).toBe(target);
|
||||
const originalNode = await content.elementHandle();
|
||||
expect(originalNode).not.toBeNull();
|
||||
await page.mouse.move(point.x, point.y);
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview
|
||||
.locator(".component-template-preview__outline")
|
||||
.evaluateAll((outlines) =>
|
||||
outlines.every((outline) => getComputedStyle(outline).pointerEvents === "none"),
|
||||
),
|
||||
)
|
||||
.toBe(true);
|
||||
expect(await originalNode!.evaluate((node) => node.isConnected)).toBe(true);
|
||||
await page.mouse.click(point.x, point.y);
|
||||
await expect(
|
||||
preview.locator(".component-template-preview__outline.is-selected"),
|
||||
@@ -161,6 +179,7 @@ const runtimeWorkspace = {
|
||||
trustItems: [{ ...adminTrust }],
|
||||
trustPresentation: {},
|
||||
capabilities: [],
|
||||
plugins: [{ key: "inquiry", status: "enabled", config: {} }],
|
||||
theme: { colors: {} },
|
||||
};
|
||||
const templateContent = JSON.parse(
|
||||
@@ -390,9 +409,10 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
);
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
|
||||
await expect(page.getByRole("dialog", { name: "有尚未保存的修改" })).toHaveCount(0);
|
||||
await expect(preview.locator(".offering-card")).toHaveCount(1);
|
||||
await preview.locator('[data-editor-target="acheng-campus-food.offerings.item"]').click();
|
||||
await preview.locator(".offering-card .dish-name").click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-record-id",
|
||||
adminOffering.id,
|
||||
@@ -411,7 +431,7 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => adminOffering.name).toBe("编辑后的家庭餐");
|
||||
await page.reload();
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
|
||||
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
|
||||
await page.getByText("出摊服务", { exact: true }).click();
|
||||
await preview.locator('[data-editor-target="trust:schedule"]').click();
|
||||
@@ -487,7 +507,7 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
await page.getByText("记录页", { exact: true }).click();
|
||||
await expect(preview.locator(".records-page")).toBeVisible();
|
||||
await expect(preview.locator(".records-page")).toContainText("请在微信小程序内登录查看");
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
|
||||
await page.getByRole("button", { name: "点选编辑" }).click();
|
||||
await expect
|
||||
.poll(() =>
|
||||
@@ -769,9 +789,9 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
await stats.click();
|
||||
const inspector = page.locator(".presentation-editor__inspector");
|
||||
await expect(inspector.getByRole("heading", { name: "信任数据" })).toBeVisible();
|
||||
await expect(page.getByLabel("1. 数字或成果")).toHaveValue("10 年");
|
||||
await expect(page.getByLabel("2. 说明")).toHaveValue("项目落地");
|
||||
await page.getByLabel("1. 数字或成果").fill("25 年");
|
||||
await expect(page.getByLabel("数字或成果", { exact: true }).nth(0)).toHaveValue("10 年");
|
||||
await expect(page.getByLabel("说明", { exact: true }).nth(1)).toHaveValue("项目落地");
|
||||
await page.getByLabel("数字或成果", { exact: true }).nth(0).fill("25 年");
|
||||
await expect(stats.locator(".stat-value").first()).toContainText("25 年");
|
||||
await inspector.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => editorialWorkspace.trustItems[0].config.stats[0].value).toBe("25 年");
|
||||
@@ -787,7 +807,7 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
await expect(preview.locator(".founder-copy .quote")).toContainText("跨页面共享的简介回归");
|
||||
await expect(stats.locator(".stat-value").first()).toContainText("25 年");
|
||||
await page.getByRole("button", { name: "信任数据", exact: true }).click();
|
||||
await expect(page.getByLabel("1. 数字或成果")).toHaveValue("25 年");
|
||||
await expect(page.getByLabel("数字或成果", { exact: true }).nth(0)).toHaveValue("25 年");
|
||||
await preview.locator('[data-editor-target="editorial.home.hero"]').click();
|
||||
await expect(page.getByLabel("首页主标题")).toBeVisible();
|
||||
await page.getByLabel("设计理念", { exact: true }).fill("模板专属理念回归");
|
||||
@@ -804,20 +824,20 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
await page.reload();
|
||||
await expect(stats.locator(".stat-value").first()).toContainText("200+");
|
||||
await preview.locator(".pillar-title").first().click();
|
||||
await expect(page.getByLabel("1. 方法说明")).toBeVisible();
|
||||
await page.getByLabel("1. 方法名称").fill("方法名称回归");
|
||||
await expect(page.getByLabel("方法说明", { exact: true }).nth(0)).toBeVisible();
|
||||
await page.getByLabel("方法名称", { exact: true }).nth(0).fill("方法名称回归");
|
||||
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await expect(page.getByText("已保存内容草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
|
||||
await preview.locator(".flow-name").first().click();
|
||||
await expect(page.getByLabel("1. 步骤编号")).toBeVisible();
|
||||
await expect(page.getByLabel("1. 步骤名称")).toBeVisible();
|
||||
await page.getByLabel("1. 步骤说明").fill("步骤说明回归");
|
||||
await expect(page.getByLabel("步骤编号", { exact: true }).nth(0)).toBeVisible();
|
||||
await expect(page.getByLabel("步骤名称", { exact: true }).nth(0)).toBeVisible();
|
||||
await page.getByLabel("步骤说明", { exact: true }).nth(0).fill("步骤说明回归");
|
||||
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await expect(page.getByText("已保存内容草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
|
||||
await preview.locator(".work-card").click();
|
||||
@@ -826,12 +846,12 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
await page.getByLabel("项目地点", { exact: true }).fill("项目地点回归");
|
||||
await expect(preview.locator(".work-category")).toContainText("项目地点回归");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await expect(page.getByText("已保存内容草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(preview.locator(".work-category")).toContainText("项目地点回归");
|
||||
await page.getByText("主理人与我", { exact: true }).click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||
await preview.locator('[data-editor-target="linjing-editorial.profile.identity"]').click();
|
||||
await preview.locator(".editorial-profile .founder").click();
|
||||
await expect(page.getByRole("button", { name: "信任数据", exact: true })).toHaveCount(0);
|
||||
await expect(page.getByLabel("主理人姓名")).toBeVisible();
|
||||
await page.getByLabel("主理人姓名").fill("修改后的主理人");
|
||||
|
||||
@@ -179,7 +179,10 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
|
||||
await expect(preview.locator(".food-detail")).toContainText("列表实时预览餐品");
|
||||
await expect(page.getByLabel("餐品介绍")).toHaveValue("弹窗编辑后的餐品介绍");
|
||||
|
||||
await page.locator(".ant-modal-footer").getByRole("button", { name: "OK" }).click();
|
||||
await page
|
||||
.locator(".ant-modal-footer")
|
||||
.getByRole("button", { name: "确 定", exact: true })
|
||||
.click();
|
||||
await expect(page.getByText("业务提供项已保存")).toBeVisible();
|
||||
await page.locator(".ant-modal-wrap").waitFor({ state: "hidden" });
|
||||
|
||||
@@ -199,11 +202,14 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
|
||||
expect(savedBody.name).toBe("小程序页保存后的餐品");
|
||||
expect(savedBody.summary).toBe("跨入口保存后的业务简介");
|
||||
await page.goBack();
|
||||
await expect(page.getByText("小程序内容:业务展示与详情")).toBeVisible();
|
||||
await expect(page.getByRole("heading", { name: "业务提供项", exact: true })).toBeVisible();
|
||||
await page.getByRole("button", { name: "编辑详情" }).click();
|
||||
await expect(page.getByLabel("名称", { exact: true })).toHaveValue("小程序页保存后的餐品");
|
||||
await expect(page.getByLabel("餐品介绍")).toHaveValue("弹窗编辑后的餐品介绍");
|
||||
await page.locator(".ant-modal-footer").getByRole("button", { name: "OK" }).click();
|
||||
await page
|
||||
.locator(".ant-modal-footer")
|
||||
.getByRole("button", { name: "确 定", exact: true })
|
||||
.click();
|
||||
await expect(page.getByText("业务提供项已保存")).toBeVisible();
|
||||
expect(savedBody.name).toBe("小程序页保存后的餐品");
|
||||
expect(savedBody.summary).toBe("跨入口保存后的业务简介");
|
||||
|
||||
Reference in new issue
Block a user