Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/function_feature' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AruSeito committed Apr 29, 2024
2 parents e0e5ffc + 5971bc6 commit 43bcbe3
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {
import { recentTabActions } from "@/redux/ui/recentTab/slice"
import { DEFAULT_CHAT_ID } from "@/redux/ui/recentTab/state"
import { useRemoveRecentTabReducer } from "@/utils/recentTabs/baseHook"
import { getChatPath } from "@/utils/routeHelper"
import { genTabNavigateLink, getChatPath } from "@/utils/routeHelper"
import { useGetCurrentTeamInfo } from "@/utils/team"
import {
baseActionIconContainerStyle,
baseMenuItemContainerStyle,
} from "../../baseTabStyle"
import { SHOULD_MODEL_TIP_TAB_TYPES } from "../constant"
import { menuItemNameStyle, menuItemStyle, navLinkStyle } from "../style"
import { genTabNavigateLink, getIconByTabInfo, useGetTabName } from "../utils"
import { getIconByTabInfo, useGetTabName } from "../utils"
import { IMobileTipisTabProps } from "./interface"

const MobileTipisTab: FC<IMobileTipisTabProps> = (props) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { recentTabActions } from "@/redux/ui/recentTab/slice"
import { DEFAULT_CHAT_ID } from "@/redux/ui/recentTab/state"
import { useRemoveRecentTabReducer } from "@/utils/recentTabs/baseHook"
import { getChatPath } from "@/utils/routeHelper"
import { genTabNavigateLink, getChatPath } from "@/utils/routeHelper"
import { useGetCurrentTeamInfo } from "@/utils/team"
import DropIndicator from "../../DropIndicator/DropIndicator"
import {
Expand All @@ -24,7 +24,7 @@ import {
import { DRAG_TAB_TYPES, useTabSortableItem } from "../../hook"
import { SHOULD_MODEL_TIP_TAB_TYPES } from "../constant"
import { menuItemNameStyle, menuItemStyle, navLinkStyle } from "../style"
import { genTabNavigateLink, getIconByTabInfo, useGetTabName } from "../utils"
import { getIconByTabInfo, useGetTabName } from "../utils"
import { IPCTipisTab } from "./interface"

const PCTipisTab: FC<IPCTipisTab> = (props) => {
Expand Down
45 changes: 0 additions & 45 deletions apps/agent/src/Layout/Workspace/components/Tab/TipisTab/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ import FunctionIcon from "@/assets/workspace/function.svg?react"
import MarketplaceIcon from "@/assets/workspace/marketplace.svg?react"
import { TAB_TYPE } from "@/redux/ui/recentTab/interface"
import { DEFAULT_CHAT_ID } from "@/redux/ui/recentTab/state"
import {
getChatPath,
getCreateFunctionPath,
getCreateTipiPath,
getEditFunctionPath,
getEditTipiPath,
getExploreFunctionsPath,
getExploreTipisPath,
getMarketTipiDetailPath,
getRunTipiPath,
getTipiDetailPath,
} from "@/utils/routeHelper"
import { basePCMenuItemButtonCustomIconContainerStyle } from "../baseTabStyle"
import { chatIconStyle, menuItemIconContainerStyle } from "./style"

Expand Down Expand Up @@ -104,36 +92,3 @@ export const useGetTabName = () => {

return getTabName
}

export const genTabNavigateLink = (
teamIdentifier: string = "",
tabType: TAB_TYPE,
cacheID: string,
tabID: string,
) => {
switch (tabType) {
case TAB_TYPE.CREATE_TIPIS:
return getCreateTipiPath(teamIdentifier)
case TAB_TYPE.EDIT_TIPIS:
return getEditTipiPath(teamIdentifier, cacheID)
case TAB_TYPE.RUN_TIPIS:
return `${getRunTipiPath(teamIdentifier, cacheID, tabID)}`
case TAB_TYPE.CHAT:
return getChatPath(teamIdentifier, cacheID)
case TAB_TYPE.CREATE_FUNCTION:
return getCreateFunctionPath(teamIdentifier, cacheID)
case TAB_TYPE.EDIT_FUNCTION:
return getEditFunctionPath(teamIdentifier, cacheID)
case TAB_TYPE.EXPLORE_TIPIS:
return getExploreTipisPath(teamIdentifier)
case TAB_TYPE.EXPLORE_FUNCTION:
return getExploreFunctionsPath(teamIdentifier)
case TAB_TYPE.EXPLORE_TIPIS_DETAIL:
return getTipiDetailPath(teamIdentifier, cacheID)
case TAB_TYPE.EXPLORE_MARKET_TIPIS_DETAIL:
return getMarketTipiDetailPath(teamIdentifier, cacheID)
case TAB_TYPE.EXPLORE_MARKET_FUNCTION_DETAIL:
case TAB_TYPE.EXPLORE_FUNCTION_DETAIL:
return ""
}
}
115 changes: 94 additions & 21 deletions apps/agent/src/page/WorkSpace/Function/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { App } from "antd"
import { FC, useCallback, useEffect } from "react"
import { FormProvider, useForm, useWatch } from "react-hook-form"
import { useTranslation } from "react-i18next"
import { useBeforeUnload, useParams } from "react-router-dom"
import {
useBeforeUnload,
useNavigate,
useParams,
useSearchParams,
} from "react-router-dom"
// import { DraggableModal } from "@illa-public/draggable-modal"
import { getFunctionInitDataByType } from "@illa-public/public-configs"
import { IBaseFunction, TIntegrationType } from "@illa-public/public-types"
Expand All @@ -16,12 +21,22 @@ import {
getFormDataByTabID,
setFormDataByTabID,
} from "@/utils/localForage/formData"
import {
useFindRecentTabByTabID,
useRemoveRecentTabReducer,
} from "@/utils/recentTabs/baseHook"
import { CREATE_FUNCTION_ID } from "@/utils/recentTabs/constants"
import {
useAddCreateFunction,
useUpdateCreateToEditFunctionTab,
useUpdateCurrentTabToTipisDashboard,
} from "@/utils/recentTabs/hook"
import {
CREATE_FUNCTION_FROM_SINGLE,
CREATE_FUNCTION_FROM_SINGLE_KEY,
CREATE_FUNCTION_FROM_TAB_KEY,
genTabNavigateLink,
} from "@/utils/routeHelper"
import { useGetCurrentTeamInfo } from "@/utils/team"
import TestRunResult from "./components/TestRunResult"
import { IFunctionForm } from "./interface"
Expand All @@ -34,12 +49,16 @@ const CreateFunction: FC = () => {
const { functionType } = useParams()
const { message, modal } = App.useApp()
const { t } = useTranslation()
const [searchParams] = useSearchParams()

const INITConfig = getFunctionInitDataByType(functionType as TIntegrationType)
const createFunctionTab = useAddCreateFunction()
const currentTeamInfo = useGetCurrentTeamInfo()!
const updateCreateToEditFunctionTab = useUpdateCreateToEditFunctionTab()
const updateCurrentTabToTipisDashboard = useUpdateCurrentTabToTipisDashboard()
const removeTab = useRemoveRecentTabReducer()
const findTabByTabID = useFindRecentTabByTabID()
const navigate = useNavigate()

const methods = useForm<IFunctionForm>({
defaultValues: INITConfig,
Expand Down Expand Up @@ -109,26 +128,80 @@ const CreateFunction: FC = () => {
},
},
}).unwrap()
modal.success({
closable: true,
title: t("function.edit.modal.save.title"),
content: t("function.edit.modal.save.desc"),
okText: t("function.edit.modal.save.button"),
onOk: async () => {
return updateCurrentTabToTipisDashboard({
tabName: serverData.name,
tabIcon: "",
cacheID: serverData.aiToolID,
})
},
onCancel: async () => {
return updateCreateToEditFunctionTab(CREATE_FUNCTION_ID, {
tabName: serverData.name,
tabIcon: "",
cacheID: serverData.aiToolID,
})
},
})

const defaultAlertMethod = () => {
modal.success({
closable: true,
title: t("function.edit.modal.save.title"),
content: t("function.edit.modal.save.desc"),
okText: t("function.edit.modal.save.button"),
onOk: async () => {
return updateCurrentTabToTipisDashboard({
tabName: serverData.name,
tabIcon: "",
cacheID: serverData.aiToolID,
})
},
onCancel: async () => {
return updateCreateToEditFunctionTab(CREATE_FUNCTION_ID, {
tabName: serverData.name,
tabIcon: "",
cacheID: serverData.aiToolID,
})
},
})
}

const from = searchParams.get(
CREATE_FUNCTION_FROM_SINGLE_KEY,
) as CREATE_FUNCTION_FROM_SINGLE

const createFromTabID = searchParams.get(CREATE_FUNCTION_FROM_TAB_KEY)

if (!from || !createFromTabID) {
defaultAlertMethod()
return
}

const tabInfo = findTabByTabID(createFromTabID)

if (!tabInfo) {
defaultAlertMethod()
return
}

switch (from) {
case CREATE_FUNCTION_FROM_SINGLE.EDIT_TIPIS: {
message.success(t("function.edit.modal.save.title"))
await removeTab(functionType!)
navigate(
genTabNavigateLink(
currentTeamInfo.identifier,
tabInfo.tabType,
tabInfo.cacheID,
tabInfo.tabID,
),
)
break
}
case CREATE_FUNCTION_FROM_SINGLE.CREATE_TIPIS: {
message.success(t("function.edit.modal.save.title"))
await removeTab(functionType!)
navigate(
genTabNavigateLink(
currentTeamInfo.identifier,
tabInfo.tabType,
tabInfo.cacheID,
tabInfo.tabID,
),
)

break
}
case CREATE_FUNCTION_FROM_SINGLE.DASHBOARD: {
defaultAlertMethod()
}
}
} catch (e) {
message.error(t("function.edit.message.failed_to_create"))
}
Expand Down
12 changes: 12 additions & 0 deletions apps/agent/src/utils/recentTabs/baseHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,15 @@ export const useInitRecentTab = () => {
initRecentTab()
}, [initRecentTab])
}

export const useFindRecentTabByTabID = () => {
const recentTabs = useSelector(getRecentTabInfos)
const findRecentTabByID = useCallback(
(tabID: string) => {
return recentTabs.find((tab) => tab.tabID === tabID)
},
[recentTabs],
)

return findRecentTabByID
}
4 changes: 3 additions & 1 deletion apps/agent/src/utils/recentTabs/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ export const useAddCreateFunction = () => {
async (functionType: string) => {
const historyTabs = getRecentTabInfos(store.getState())
const createFunctionTab = historyTabs.find(
(tab) => tab.tabType === TAB_TYPE.CREATE_FUNCTION,
(tab) =>
tab.tabType === TAB_TYPE.CREATE_FUNCTION &&
tab.cacheID === functionType,
)
if (!createFunctionTab) {
const tabsInfo: ITabInfo = {
Expand Down
6 changes: 6 additions & 0 deletions apps/agent/src/utils/routeHelper/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ import { findRecentTeamInfo, useGetCurrentTeamInfo } from "../team"
export const NOT_HAS_TEAM_INFO_KEY = "NOT_HAS_TEAM_INFO"
export const NOT_HAS_TARGET_TEAM_INFO_KEY = "NOT_HAS_TARGET_TEAM_INFO"

export const useNavigateByTabID = () => {
const navigateByTabID = useCallback(async () => {}, [])

return navigateByTabID
}

export const useNavigateTargetWorkspace = () => {
const navigate = useNavigate()
const [getTeamsInfo] = useLazyGetTeamsInfoQuery()
Expand Down
43 changes: 43 additions & 0 deletions apps/agent/src/utils/routeHelper/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TAB_TYPE } from "@/redux/ui/recentTab/interface"
import { DEFAULT_CHAT_ID } from "@/redux/ui/recentTab/state"

export const getExploreTipisPath = (teamIdentifier: string) => {
Expand Down Expand Up @@ -74,9 +75,51 @@ export const getTeamInfoSetting = (teamIdentifier: string) => {
return `/setting/${teamIdentifier}/team-settings`
}

export const genTabNavigateLink = (
teamIdentifier: string = "",
tabType: TAB_TYPE,
cacheID: string,
tabID: string,
) => {
switch (tabType) {
case TAB_TYPE.CREATE_TIPIS:
return getCreateTipiPath(teamIdentifier)
case TAB_TYPE.EDIT_TIPIS:
return getEditTipiPath(teamIdentifier, cacheID)
case TAB_TYPE.RUN_TIPIS:
return `${getRunTipiPath(teamIdentifier, cacheID, tabID)}`
case TAB_TYPE.CHAT:
return getChatPath(teamIdentifier, cacheID)
case TAB_TYPE.CREATE_FUNCTION:
return getCreateFunctionPath(teamIdentifier, cacheID)
case TAB_TYPE.EDIT_FUNCTION:
return getEditFunctionPath(teamIdentifier, cacheID)
case TAB_TYPE.EXPLORE_TIPIS:
return getExploreTipisPath(teamIdentifier)
case TAB_TYPE.EXPLORE_FUNCTION:
return getExploreFunctionsPath(teamIdentifier)
case TAB_TYPE.EXPLORE_TIPIS_DETAIL:
return getTipiDetailPath(teamIdentifier, cacheID)
case TAB_TYPE.EXPLORE_MARKET_TIPIS_DETAIL:
return getMarketTipiDetailPath(teamIdentifier, cacheID)
case TAB_TYPE.EXPLORE_MARKET_FUNCTION_DETAIL:
case TAB_TYPE.EXPLORE_FUNCTION_DETAIL:
return ""
}
}

export const REGISTER_PATH = "/user/register"
export const FORGOT_PASSWORD_PATH = "/user/forgotPassword"
export const LOGIN_PATH = "/user/login"
export const PASSWORD_PATH = "/setting/password"
export const LINKED_PATH = "/setting/linked"
export const EMPTY_TEAM_PATH = "/empty-workspace"

export enum CREATE_FUNCTION_FROM_SINGLE {
CREATE_TIPIS = "createTipis",
EDIT_TIPIS = "editTipis",
DASHBOARD = "dashboard",
}

export const CREATE_FUNCTION_FROM_SINGLE_KEY = "from"
export const CREATE_FUNCTION_FROM_TAB_KEY = "fromTabID"

0 comments on commit 43bcbe3

Please sign in to comment.