Browse Source

🐛 (dashboard-v6): channel 设置页 Webhooks 页签 404、不存在的 channel 白屏(BUG-1、BUG-4)

- BUG-1:设置页页签与 webhook 链接还拼旧的 /studio/{名}/channel/… 路由,v6 没有这条路由。
  补上 setting/:type 与 setting/:type/:id 两条路由,链接改到 /workspace/channel/…
- BUG-4:访问不存在(或看不见)的 channel 时显示 React Router 默认的 Unexpected Application Error。
  新增 components/general/RouteError 挂在 :channelId 路由的 errorElement;面包屑 crumb 在加载失败时
  拿不到数据会崩,channel 与团队两处改成可选取值

两条都是 2026-09 测试日志里登记过的回归断言(dashboard-test channel.spec),现在转绿。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 1 day ago
parent
commit
7313b0451a

+ 36 - 0
dashboard-v6/src/components/general/RouteError.tsx

@@ -0,0 +1,36 @@
+import { Button, Result } from "antd";
+import { useIntl } from "react-intl";
+import { isRouteErrorResponse, useNavigate, useRouteError } from "react-router";
+
+interface IWidget {
+  /** 「返回」按钮去哪里 */
+  backTo?: string;
+}
+
+/**
+ * 路由数据加载失败时的错误页(loader 抛出的 404 / 403 等),代替 React Router 默认的
+ * 「Unexpected Application Error」。挂在路由的 errorElement 上。
+ */
+const RouteError = ({ backTo = "/workspace" }: IWidget) => {
+  const intl = useIntl();
+  const navigate = useNavigate();
+  const error = useRouteError();
+  const status = isRouteErrorResponse(error) ? error.status : 500;
+  const known = status === 403 || status === 404;
+
+  return (
+    <Result
+      status={known ? (String(status) as "403" | "404") : "error"}
+      title={intl.formatMessage({
+        id: known ? `labels.route-error.${status}` : "labels.route-error.other",
+      })}
+      extra={
+        <Button type="primary" onClick={() => navigate(backTo)}>
+          {intl.formatMessage({ id: "buttons.back" })}
+        </Button>
+      }
+    />
+  );
+};
+
+export default RouteError;

+ 3 - 7
dashboard-v6/src/components/webhook/WebhookEdit.tsx

@@ -22,7 +22,6 @@ import type { TResType } from "../../api/discussion";
 const { Title } = Typography;
 
 interface IWidget {
-  studioName?: string;
   channelId?: string;
   id?: string;
   res_type?: TResType;
@@ -30,7 +29,6 @@ interface IWidget {
   onSuccess?: () => void;
 }
 const WebhookEditWidget = ({
-  studioName,
   channelId,
   id,
   res_type = "channel",
@@ -44,9 +42,7 @@ const WebhookEditWidget = ({
   return (
     <Space orientation="vertical">
       <Title level={4}>
-        <Link
-          to={`/studio/${studioName}/channel/${channelId}/setting/webhooks`}
-        >
+        <Link to={`/workspace/channel/${channelId}/setting/webhooks`}>
           List
         </Link>{" "}
         / {id ? "Manage webhook" : "New"}
@@ -64,12 +60,12 @@ const WebhookEditWidget = ({
           if (typeof id === "undefined") {
             res = await post<IWebhookRequest, IWebhookResponse>(
               `/api/v2/webhook`,
-              data
+              data,
             );
           } else {
             res = await put<IWebhookRequest, IWebhookResponse>(
               `/api/v2/webhook/${id}`,
-              data
+              data,
             );
           }
           console.log(res);

+ 3 - 6
dashboard-v6/src/components/webhook/WebhookList.tsx

@@ -21,10 +21,9 @@ const { Text } = Typography;
 
 interface IWidget {
   channelId?: string;
-  studioName?: string;
 }
 
-const WebhookListWidget = ({ channelId, studioName }: IWidget) => {
+const WebhookListWidget = ({ channelId }: IWidget) => {
   const intl = useIntl();
   const navigate = useNavigate();
 
@@ -175,7 +174,7 @@ const WebhookListWidget = ({ channelId, studioName }: IWidget) => {
                   }}
                 >
                   <Link
-                    to={`/studio/${studioName}/channel/${channelId}/setting/webhooks/${row.id}`}
+                    to={`/workspace/channel/${channelId}/setting/webhooks/${row.id}`}
                   >
                     {intl.formatMessage({
                       id: "buttons.edit",
@@ -220,9 +219,7 @@ const WebhookListWidget = ({ channelId, studioName }: IWidget) => {
             icon={<PlusOutlined />}
             type="primary"
             onClick={() =>
-              navigate(
-                `/studio/${studioName}/channel/${channelId}/setting/webhooks/new`
-              )
+              navigate(`/workspace/channel/${channelId}/setting/webhooks/new`)
             }
           >
             {intl.formatMessage({ id: "buttons.create" })}

+ 1 - 0
dashboard-v6/src/locales/en-US/buttons.ts

@@ -119,6 +119,7 @@ const items = {
   "buttons.word_count": "Word Count",
   "buttons.teamspace.switch": "Switch to teamspace",
   "buttons.teamspace.leave": "Back to personal space",
+  "buttons.back": "Back",
 };
 
 export default items;

+ 3 - 0
dashboard-v6/src/locales/en-US/label.ts

@@ -164,6 +164,9 @@ const items = {
   "labels.group.share.missing": "(deleted)",
   "labels.group.share.editor": "Can edit",
   "labels.group.share.reader": "Read only",
+  "labels.route-error.404": "This content does not exist or has been deleted",
+  "labels.route-error.403": "You are not allowed to view this content",
+  "labels.route-error.other": "Failed to load. Please try again later",
 };
 
 export default items;

+ 1 - 0
dashboard-v6/src/locales/zh-Hans/buttons.ts

@@ -120,6 +120,7 @@ const items = {
   "buttons.word_count": "字数统计",
   "buttons.teamspace.switch": "切换到团队空间",
   "buttons.teamspace.leave": "切回个人空间",
+  "buttons.back": "返回",
 };
 
 export default items;

+ 3 - 0
dashboard-v6/src/locales/zh-Hans/label.ts

@@ -171,6 +171,9 @@ const items = {
   "labels.group.share.missing": "(资源已删除)",
   "labels.group.share.editor": "可编辑",
   "labels.group.share.reader": "只读",
+  "labels.route-error.404": "要找的内容不存在,或已被删除",
+  "labels.route-error.403": "你没有权限查看这个内容",
+  "labels.route-error.other": "加载失败,请稍后再试",
 };
 
 export default items;

+ 1 - 0
dashboard-v6/src/locales/zh-Hant/buttons.ts

@@ -120,6 +120,7 @@ const items = {
   "buttons.word_count": "字數統計",
   "buttons.teamspace.switch": "切換到團隊空間",
   "buttons.teamspace.leave": "切回個人空間",
+  "buttons.back": "返回",
 };
 
 export default items;

+ 3 - 0
dashboard-v6/src/locales/zh-Hant/label.ts

@@ -171,6 +171,9 @@ const items = {
   "labels.group.share.missing": "(資源已刪除)",
   "labels.group.share.editor": "可編輯",
   "labels.group.share.reader": "唯讀",
+  "labels.route-error.404": "要找的內容不存在,或已被刪除",
+  "labels.route-error.403": "你沒有權限查看這個內容",
+  "labels.route-error.other": "載入失敗,請稍後再試",
 };
 
 export default items;

+ 22 - 7
dashboard-v6/src/routes/channelRoutes.ts

@@ -1,16 +1,15 @@
 // src/routes/channelRoutes.ts
-import { lazy } from "react";
+import { createElement, lazy } from "react";
 import type { RouteObject } from "react-router";
 import { channelLoader } from "../api/channel";
+import RouteError from "../components/general/RouteError";
 
-const WorkspaceChannel = lazy(
-  () => import("../pages/workspace/channel/list")
-);
+const WorkspaceChannel = lazy(() => import("../pages/workspace/channel/list"));
 const WorkspaceChannelShow = lazy(
-  () => import("../pages/workspace/channel/show")
+  () => import("../pages/workspace/channel/show"),
 );
 const WorkspaceChannelSetting = lazy(
-  () => import("../pages/workspace/channel/setting")
+  () => import("../pages/workspace/channel/setting"),
 );
 
 const channelRoutes: RouteObject[] = [
@@ -25,8 +24,13 @@ const channelRoutes: RouteObject[] = [
       {
         path: ":channelId",
         loader: channelLoader,
+        // channel 不存在(404)或看不见(v3 回 403,loader 统一抛 404)时给友好提示
+        errorElement: createElement(RouteError, {
+          backTo: "/workspace/channel",
+        }),
         handle: {
-          crumb: (match: { data: { name: string } }) => match.data.name,
+          crumb: (match: { data?: { name?: string } }) =>
+            match.data?.name ?? "",
         },
         children: [
           {
@@ -38,6 +42,17 @@ const channelRoutes: RouteObject[] = [
             Component: WorkspaceChannelSetting,
             handle: { id: "workspace.channel.setting", crumb: "setting" },
           },
+          // 设置页的页签(basic / webhooks)与 webhook 详情(new 或 webhook id)
+          {
+            path: "setting/:type",
+            Component: WorkspaceChannelSetting,
+            handle: { id: "workspace.channel.setting", crumb: "setting" },
+          },
+          {
+            path: "setting/:type/:id",
+            Component: WorkspaceChannelSetting,
+            handle: { id: "workspace.channel.setting", crumb: "setting" },
+          },
         ],
       },
     ],

+ 2 - 1
dashboard-v6/src/routes/teamRoutes.ts

@@ -27,7 +27,8 @@ const channelRoutes: RouteObject[] = [
         path: ":teamId",
         loader: groupLoader,
         handle: {
-          crumb: (match: { data: { name: string } }) => match.data.name,
+          crumb: (match: { data?: { name?: string } }) =>
+            match.data?.name ?? "",
         },
         children: [
           {