/* * Copyright 2025 coze-dev Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { useNavigate, useParams } from 'react-router-dom'; import { SpaceAppEnum, BaseEnum } from '@coze-arch/web-context'; import { I18n } from '@coze-arch/i18n'; import { IconCozArrowLeft } from '@coze-arch/coze-design/icons'; import { Typography, Avatar, Breadcrumb as SemiBreadcrumb, Button, } from '@coze-arch/coze-design'; import { type DynamicParams } from '@coze-arch/bot-typings/teamspace'; import { useSpaceStore } from '@coze-arch/bot-studio-store'; import { type BreadcrumbProps as SemiBreadcrumbProps } from '@coze-arch/bot-semi/Breadcrumb'; import { useRouteConfig } from '@coze-arch/bot-hooks'; import type { DataSetInfo } from '@coze-arch/bot-api/memory'; import { type DocumentInfo } from '@coze-arch/bot-api/knowledge'; import { type DraftBot, type PluginMetaInfo, type PluginAPIInfo, } from '@coze-arch/bot-api/developer_api'; import { type MockSet } from '@coze-arch/bot-api/debugger_api'; import { useSpaceApp } from '@coze-foundation/space-store'; import s from './index.module.less'; export interface BreadCrumbProps extends SemiBreadcrumbProps { botInfo?: DraftBot; datasetInfo?: DataSetInfo; documentinfo?: DocumentInfo; pluginInfo?: PluginMetaInfo; pluginToolInfo?: PluginAPIInfo; isPublish?: boolean; mockSetInfo?: MockSet; } // eslint-disable-next-line @coze-arch/max-line-per-function export const UIBreadcrumb: React.FC = ({ botInfo, datasetInfo, documentinfo, pluginInfo, pluginToolInfo, mockSetInfo, isPublish, ...props }) => { const { menuKey: base } = useRouteConfig(); const spaceApp = useSpaceApp(); const id = useSpaceStore(store => store.space.id); const navigate = useNavigate(); const params = useParams(); const goBack = () => { if (base === BaseEnum.Explore) { navigate('/explore'); } else { navigate(`/space/${id}/library`); } }; const goBackToDoc = () => { navigate(`/space/${id}/${spaceApp}/${params.dataset_id}`); }; const goBackToPluginIdList = () => { navigate(`/space/${id}/${spaceApp}/${params.plugin_id}`); }; const goBackToBot = () => { navigate(`/space/${id}/${spaceApp}/${params.bot_id}`); }; const goBackToToolIdList = () => { navigate( `/space/${id}/${spaceApp}/${params.plugin_id}/tool/${params.tool_id}?mode=preview`, ); }; const goBackToMockSetList = () => { navigate( `/space/${id}/${spaceApp}/${params.plugin_id}/tool/${params.tool_id}/plugin-mock-set`, ); }; const renderBreadcrumbItemForPlugin = () => { let breadCrumbList: React.ReactNode[] = []; let onBackClick: () => void; if (pluginInfo?.name) { onBackClick = goBack; } if (pluginToolInfo?.name) { onBackClick = goBackToPluginIdList; } if (mockSetInfo) { onBackClick = goBackToToolIdList; if (mockSetInfo?.name) { onBackClick = goBackToMockSetList; } } breadCrumbList = [ , ]; return breadCrumbList; }; const renderBreadcrumbItem = () => { if (base === BaseEnum.Explore) { return [ Explore ,
{botInfo?.name}
, ]; } switch (spaceApp) { case SpaceAppEnum.BOT: { if (isPublish) { return [ {I18n.t('menu_bots')} ,
{botInfo?.name}
,
{I18n.t('Publish')}
, ]; } else { return [ {I18n.t('menu_bots')} ,
{botInfo?.name}
, ]; } } case SpaceAppEnum.KNOWLEDGE: { if (!params.doc_id) { return [ { goBack(); }} > {I18n.t('datasets_title')} , {datasetInfo?.name} , ]; } return [ { goBack(); }} > {I18n.t('datasets_title')} , {datasetInfo?.name} , {documentinfo?.name} , ]; } case SpaceAppEnum.PLUGIN: { return renderBreadcrumbItemForPlugin(); } default: return null; } }; return (
{renderBreadcrumbItem()}
); };