Prechádzať zdrojové kódy

fix(dashboard): term 页面版本选择面板更新 URL channel 参数

右边栏版本面板点击版本名称时,补全 term 页面的 channel 选择链路:
- TermEditor 透传 onChannelSelect 与 articleType=term 给 Editor
- term show 页读取/写回 ?channel= 查询参数
visuddhinanda 3 dní pred
rodič
commit
548433e38f

+ 7 - 0
dashboard-v6/src/features/editor/Term.tsx

@@ -4,6 +4,7 @@
 
 
 import { useEffect } from "react";
 import { useEffect } from "react";
 import type { ArticleMode } from "../../api/article";
 import type { ArticleMode } from "../../api/article";
+import type { IChannel } from "../../api/channel";
 import TypeTerm from "../../components/article/TypeTerm";
 import TypeTerm from "../../components/article/TypeTerm";
 import Editor from "../../components/editor";
 import Editor from "../../components/editor";
 import { Recent } from "../../components/recent/Recent";
 import { Recent } from "../../components/recent/Recent";
@@ -24,6 +25,9 @@ export interface ArticleEditorProps {
   /** 选择了新的 term 时触发 */
   /** 选择了新的 term 时触发 */
   onTermSelect?: (id: string) => void;
   onTermSelect?: (id: string) => void;
 
 
+  /** 右边栏「版本」面板选中频道时触发 */
+  onChannelSelect?: (selected: IChannel[]) => void;
+
   onEdit?: () => void;
   onEdit?: () => void;
 }
 }
 
 
@@ -36,6 +40,7 @@ export default function TermEditor({
   anthologyId,
   anthologyId,
   mode = "read",
   mode = "read",
   channelId,
   channelId,
+  onChannelSelect,
   onEdit,
   onEdit,
 }: ArticleEditorProps) {
 }: ArticleEditorProps) {
   const currUser = useAppSelector(currentUser);
   const currUser = useAppSelector(currentUser);
@@ -65,7 +70,9 @@ export default function TermEditor({
       }
       }
       articleId={termId}
       articleId={termId}
       anthologyId={anthologyId}
       anthologyId={anthologyId}
+      articleType={"term"}
       channelId={channelId}
       channelId={channelId}
+      onChannelSelect={onChannelSelect}
     >
     >
       {({ expandButton }) => (
       {({ expandButton }) => (
         <TypeTerm
         <TypeTerm

+ 10 - 1
dashboard-v6/src/pages/workspace/term/show.tsx

@@ -1,4 +1,4 @@
-import { useMatches, useNavigate, useParams } from "react-router";
+import { useMatches, useNavigate, useParams, useSearchParams } from "react-router";
 import { useIntl } from "react-intl";
 import { useIntl } from "react-intl";
 
 
 import TermEditor from "../../../features/editor/Term";
 import TermEditor from "../../../features/editor/Term";
@@ -6,6 +6,7 @@ import TermEditor from "../../../features/editor/Term";
 const Widget = () => {
 const Widget = () => {
   const { id } = useParams();
   const { id } = useParams();
   const navigate = useNavigate();
   const navigate = useNavigate();
+  const [searchParams, setSearchParams] = useSearchParams();
   const intl = useIntl();
   const intl = useIntl();
   const matches = useMatches() as {
   const matches = useMatches() as {
     data?: { title?: string; name?: string; word?: string };
     data?: { title?: string; name?: string; word?: string };
@@ -13,12 +14,20 @@ const Widget = () => {
   const data = [...matches].reverse().find((m) => m.data)?.data;
   const data = [...matches].reverse().find((m) => m.data)?.data;
   const name = data?.title ?? data?.name ?? data?.word;
   const name = data?.title ?? data?.name ?? data?.word;
   const prefix = intl.formatMessage({ id: "columns.studio.term.title" });
   const prefix = intl.formatMessage({ id: "columns.studio.term.title" });
+  const channelId = searchParams.get("channel");
 
 
   return (
   return (
     <>
     <>
       <title>{name ? `${prefix}-${name}` : prefix}</title>
       <title>{name ? `${prefix}-${name}` : prefix}</title>
       <TermEditor
       <TermEditor
         termId={id}
         termId={id}
+        channelId={channelId}
+        onChannelSelect={(selected) => {
+          const channelsParams = selected.map((item) => item.id).join("_");
+          const newParams = new URLSearchParams(searchParams);
+          newParams.set("channel", channelsParams);
+          setSearchParams(newParams);
+        }}
         onEdit={() => {
         onEdit={() => {
           navigate(`/workspace/term/${id}/edit`);
           navigate(`/workspace/term/${id}/edit`);
         }}
         }}