From 277d21cccbb1e5e2bd7ce583de24a713b94e2505 Mon Sep 17 00:00:00 2001 From: JzoNg Date: Thu, 14 Mar 2024 12:22:08 +0800 Subject: [PATCH] fix webapp url --- .../[appId]/overview/cardView.tsx | 24 +++++++++++-------- web/app/components/app/log/index.tsx | 10 ++++++-- web/app/components/app/overview/appCard.tsx | 6 ++--- .../develop/template/template_workflow.en.mdx | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/cardView.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/cardView.tsx index b376ffeb97..733439b9e7 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/cardView.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/cardView.tsx @@ -3,7 +3,6 @@ import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import { useContext } from 'use-context-selector' -import useSWR, { useSWRConfig } from 'swr' import AppCard from '@/app/components/app/overview/appCard' import Loading from '@/app/components/base/loading' import { ToastContext } from '@/app/components/base/toast' @@ -18,20 +17,22 @@ import type { UpdateAppSiteCodeResponse } from '@/models/app' import { asyncRunSafe } from '@/utils' import { NEED_REFRESH_APP_LIST_KEY } from '@/config' import type { IAppCardProps } from '@/app/components/app/overview/appCard' +import { useStore as useAppStore } from '@/app/components/app/store' export type ICardViewProps = { appId: string } const CardView: FC = ({ appId }) => { - const detailParams = { url: '/apps', id: appId } - const { data: response } = useSWR(detailParams, fetchAppDetail) - const { mutate } = useSWRConfig() - const { notify } = useContext(ToastContext) const { t } = useTranslation() + const { notify } = useContext(ToastContext) + const { appDetail, setAppDetail } = useAppStore() - if (!response) - return + const updateAppDetail = async () => { + fetchAppDetail({ url: '/apps', id: appId }).then((res) => { + setAppDetail(res) + }) + } const handleCallbackResult = (err: Error | null, message?: string) => { const type = err ? 'error' : 'success' @@ -39,7 +40,7 @@ const CardView: FC = ({ appId }) => { message ||= (type === 'success' ? 'modifiedSuccessfully' : 'modifiedUnsuccessfully') if (type === 'success') - mutate(detailParams) + updateAppDetail() notify({ type, @@ -92,10 +93,13 @@ const CardView: FC = ({ appId }) => { handleCallbackResult(err, err ? 'generatedUnsuccessfully' : 'generatedSuccessfully') } + if (!appDetail) + return + return (
= ({ appId }) => { />
diff --git a/web/app/components/app/log/index.tsx b/web/app/components/app/log/index.tsx index 851cb9f02d..f4572c563d 100644 --- a/web/app/components/app/log/index.tsx +++ b/web/app/components/app/log/index.tsx @@ -15,7 +15,7 @@ import s from './style.module.css' import Loading from '@/app/components/base/loading' import { fetchChatConversations, fetchCompletionConversations } from '@/service/log' import { APP_PAGE_LIMIT } from '@/config' -import type { App } from '@/types/app' +import type { App, AppMode } from '@/types/app' export type ILogsProps = { appDetail: App } @@ -67,6 +67,12 @@ const Logs: FC = ({ appDetail }) => { ...omit(queryParams, ['period']), } + const getWebAppType = (appType: AppMode) => { + if (appType === 'completion' || appType === 'workflow') + return 'completion' + return 'chat' + } + // Get the app type first const isChatMode = appDetail.mode !== 'completion' @@ -96,7 +102,7 @@ const Logs: FC = ({ appDetail }) => { ? : total > 0 ? - : + : } {/* Show Pagination only if the total is more than the limit */} {(total && total > APP_PAGE_LIMIT) diff --git a/web/app/components/app/overview/appCard.tsx b/web/app/components/app/overview/appCard.tsx index 28c16e1bef..a8c5dac55a 100644 --- a/web/app/components/app/overview/appCard.tsx +++ b/web/app/components/app/overview/appCard.tsx @@ -25,7 +25,6 @@ import CopyFeedback from '@/app/components/base/copy-feedback' import ShareQRCode from '@/app/components/base/qrcode' import SecretKeyButton from '@/app/components/develop/secret-key/secret-key-button' import type { AppDetailResponse } from '@/models/app' -import { AppType } from '@/types/app' import { useAppContext } from '@/context/app-context' export type IAppCardProps = { @@ -69,7 +68,7 @@ function AppCard({ api: [{ opName: t('appOverview.overview.apiInfo.doc'), opIcon: DocumentTextIcon }], app: [], } - if (appInfo.mode === AppType.chat) + if (appInfo.mode !== 'completion' && appInfo.mode !== 'workflow') operationsMap.webapp.push({ opName: t('appOverview.overview.appInfo.embedded.entry'), opIcon: EmbedIcon }) if (isCurrentWorkspaceManager) @@ -84,7 +83,8 @@ function AppCard({ : t('appOverview.overview.apiInfo.title') const runningStatus = isApp ? appInfo.enable_site : appInfo.enable_api const { app_base_url, access_token } = appInfo.site ?? {} - const appUrl = `${app_base_url}/${appInfo.mode}/${access_token}` + const appMode = appInfo.mode === ('completion' || appInfo.mode === 'workflow') ? 'completion' : 'chat' + const appUrl = `${app_base_url}/${appMode}/${access_token}` const apiUrl = appInfo?.api_base_url let bgColor = 'bg-primary-50 bg-opacity-40' diff --git a/web/app/components/develop/template/template_workflow.en.mdx b/web/app/components/develop/template/template_workflow.en.mdx index 769e2b25bd..e82a1897f3 100644 --- a/web/app/components/develop/template/template_workflow.en.mdx +++ b/web/app/components/develop/template/template_workflow.en.mdx @@ -17,7 +17,7 @@ Workflow applications offers non-session support and is ideal for translation, a The Service API uses `API-Key` authentication. **Strongly recommend storing your API Key on the server-side, not shared or stored on the client-side, to avoid possible API-Key leakage that can lead to serious consequences.** - For all API requests, include your API Key in the `Authorization`HTTP Header, as shown below: + For all API requests, include your API Key in the `Authorization` HTTP Header, as shown below: ```javascript