|
|
|
|
@ -4,7 +4,7 @@ import { createRef, useCallback, useEffect, useMemo, useRef, useState } from 're
|
|
|
|
|
import useSWR from 'swr'
|
|
|
|
|
import { createContext, useContext, useContextSelector } from 'use-context-selector'
|
|
|
|
|
import type { FC, ReactNode } from 'react'
|
|
|
|
|
import { fetchCurrentWorkspace, fetchLanggeniusVersion, fetchUserProfile } from '@/service/common'
|
|
|
|
|
import { fetchCurrentWorkspace, fetchLangGeniusVersion, fetchUserProfile } from '@/service/common'
|
|
|
|
|
import type { ICurrentWorkspace, LangGeniusVersionResponse, UserProfileResponse } from '@/models/common'
|
|
|
|
|
import MaintenanceNotice from '@/app/components/header/maintenance-notice'
|
|
|
|
|
import { noop } from 'lodash-es'
|
|
|
|
|
@ -19,7 +19,7 @@ export type AppContextValue = {
|
|
|
|
|
isCurrentWorkspaceDatasetOperator: boolean
|
|
|
|
|
mutateCurrentWorkspace: VoidFunction
|
|
|
|
|
pageContainerRef: React.RefObject<HTMLDivElement | null>
|
|
|
|
|
langeniusVersionInfo: LangGeniusVersionResponse
|
|
|
|
|
langGeniusVersionInfo: LangGeniusVersionResponse
|
|
|
|
|
useSelector: typeof useSelector
|
|
|
|
|
isLoadingCurrentWorkspace: boolean
|
|
|
|
|
}
|
|
|
|
|
@ -33,7 +33,7 @@ const userProfilePlaceholder = {
|
|
|
|
|
is_password_set: false,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initialLangeniusVersionInfo = {
|
|
|
|
|
const initialLangGeniusVersionInfo = {
|
|
|
|
|
current_env: '',
|
|
|
|
|
current_version: '',
|
|
|
|
|
latest_version: '',
|
|
|
|
|
@ -63,7 +63,7 @@ const AppContext = createContext<AppContextValue>({
|
|
|
|
|
mutateUserProfile: noop,
|
|
|
|
|
mutateCurrentWorkspace: noop,
|
|
|
|
|
pageContainerRef: createRef(),
|
|
|
|
|
langeniusVersionInfo: initialLangeniusVersionInfo,
|
|
|
|
|
langGeniusVersionInfo: initialLangGeniusVersionInfo,
|
|
|
|
|
useSelector,
|
|
|
|
|
isLoadingCurrentWorkspace: false,
|
|
|
|
|
})
|
|
|
|
|
@ -82,7 +82,7 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
|
|
|
|
|
const { data: currentWorkspaceResponse, mutate: mutateCurrentWorkspace, isLoading: isLoadingCurrentWorkspace } = useSWR({ url: '/workspaces/current', params: {} }, fetchCurrentWorkspace)
|
|
|
|
|
|
|
|
|
|
const [userProfile, setUserProfile] = useState<UserProfileResponse>(userProfilePlaceholder)
|
|
|
|
|
const [langeniusVersionInfo, setLangeniusVersionInfo] = useState<LangGeniusVersionResponse>(initialLangeniusVersionInfo)
|
|
|
|
|
const [langGeniusVersionInfo, setLangGeniusVersionInfo] = useState<LangGeniusVersionResponse>(initialLangGeniusVersionInfo)
|
|
|
|
|
const [currentWorkspace, setCurrentWorkspace] = useState<ICurrentWorkspace>(initialWorkspaceInfo)
|
|
|
|
|
const isCurrentWorkspaceManager = useMemo(() => ['owner', 'admin'].includes(currentWorkspace.role), [currentWorkspace.role])
|
|
|
|
|
const isCurrentWorkspaceOwner = useMemo(() => currentWorkspace.role === 'owner', [currentWorkspace.role])
|
|
|
|
|
@ -94,8 +94,8 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
|
|
|
|
|
setUserProfile(result)
|
|
|
|
|
const current_version = userProfileResponse.headers.get('x-version')
|
|
|
|
|
const current_env = process.env.NODE_ENV === 'development' ? 'DEVELOPMENT' : userProfileResponse.headers.get('x-env')
|
|
|
|
|
const versionData = await fetchLanggeniusVersion({ url: '/version', params: { current_version } })
|
|
|
|
|
setLangeniusVersionInfo({ ...versionData, current_version, latest_version: versionData.version, current_env })
|
|
|
|
|
const versionData = await fetchLangGeniusVersion({ url: '/version', params: { current_version } })
|
|
|
|
|
setLangGeniusVersionInfo({ ...versionData, current_version, latest_version: versionData.version, current_env })
|
|
|
|
|
}
|
|
|
|
|
}, [userProfileResponse])
|
|
|
|
|
|
|
|
|
|
@ -113,7 +113,7 @@ export const AppContextProvider: FC<AppContextProviderProps> = ({ children }) =>
|
|
|
|
|
userProfile,
|
|
|
|
|
mutateUserProfile,
|
|
|
|
|
pageContainerRef,
|
|
|
|
|
langeniusVersionInfo,
|
|
|
|
|
langGeniusVersionInfo,
|
|
|
|
|
useSelector,
|
|
|
|
|
currentWorkspace,
|
|
|
|
|
isCurrentWorkspaceManager,
|
|
|
|
|
|