Skip to content

Commit

Permalink
Merge pull request #1431 from VenkataRavitejaGullapudi/main
Browse files Browse the repository at this point in the history
fix: Delete evaluator modal is light in dark mode #1424
  • Loading branch information
aakrem authored Mar 18, 2024
2 parents 6d03919 + 3a7b84a commit 79d175f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
8 changes: 7 additions & 1 deletion agenta-web/src/components/AlertPopup/AlertPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, {ReactNode} from "react"
import {Modal, ModalFuncProps} from "antd"
import {ExclamationCircleOutlined} from "@ant-design/icons"
import {globalErrorHandler} from "@/lib/helpers/errorHandler"
import {getAppValues, useAppsData} from "@/contexts/app.context"
import {HookAPI} from "antd/es/modal/useModal"

function handleCb(cb: AlertPopupProps["onOk"]) {
if (typeof cb !== "function") return cb
Expand All @@ -19,6 +21,7 @@ function handleCb(cb: AlertPopupProps["onOk"]) {
export type AlertPopupProps = ModalFuncProps & {
message: ReactNode
cancellable?: boolean
type?: keyof HookAPI
}

export default function AlertPopup({
Expand All @@ -32,7 +35,10 @@ export default function AlertPopup({
type,
...ModalProps
}: AlertPopupProps) {
return Modal[type || "confirm"]({
const {modalInstance} = getAppValues()
const modal = modalInstance || Modal

return modal[type || "confirm"]({
title,
content: message,
okText,
Expand Down
18 changes: 16 additions & 2 deletions agenta-web/src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import React, {useEffect, useMemo, useState} from "react"
import {Breadcrumb, Button, ConfigProvider, Dropdown, Layout, Space, Tooltip, theme} from "antd"
import {
Breadcrumb,
Button,
ConfigProvider,
Dropdown,
Layout,
Modal,
Space,
Tooltip,
theme,
} from "antd"
import Sidebar from "../Sidebar/Sidebar"
import {GithubFilled, LinkedinFilled, TwitterOutlined} from "@ant-design/icons"
import Link from "next/link"
Expand Down Expand Up @@ -117,7 +127,7 @@ type LayoutProps = {
const App: React.FC<LayoutProps> = ({children}) => {
const {user} = useProfileData()
const {appTheme, themeMode, toggleAppTheme} = useAppTheme()
const {currentApp} = useAppsData()
const {currentApp, setModalInstance} = useAppsData()
const capitalizedAppName = renameVariablesCapitalizeAll(currentApp?.app_name || "")
const [footerRef, {height: footerHeight}] = useElementSize()
const classes = useStyles({themeMode: appTheme, footerHeight} as StyleProps)
Expand All @@ -126,6 +136,7 @@ const App: React.FC<LayoutProps> = ({children}) => {
const appId = router.query.app_id as string
const isDarkTheme = appTheme === "dark"
const {token} = theme.useToken()
const [modal, contextHolder] = Modal.useModal()

useEffect(() => {
if (user && isDemo()) {
Expand Down Expand Up @@ -192,6 +203,8 @@ const App: React.FC<LayoutProps> = ({children}) => {
}
}
githubRepo()

setModalInstance(modal)
}, [])

useEffect(() => {
Expand Down Expand Up @@ -284,6 +297,7 @@ const App: React.FC<LayoutProps> = ({children}) => {
</Space>
<ErrorBoundary FallbackComponent={ErrorFallback}>
{children}
{contextHolder}
</ErrorBoundary>
</Content>
<Footer ref={footerRef} className={classes.footer}>
Expand Down
14 changes: 13 additions & 1 deletion agenta-web/src/contexts/app.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import {useRouter} from "next/router"
import {PropsWithChildren, createContext, useContext, useEffect, useMemo, useState} from "react"
import useSWR from "swr"
import {dynamicContext} from "@/lib/helpers/dynamic"
import {HookAPI} from "antd/es/modal/useModal"

type AppContextType = {
currentApp: ListAppsItem | null
apps: ListAppsItem[]
error: any
isLoading: boolean
mutate: () => void

modalInstance?: HookAPI
setModalInstance: (context: any) => void
}

const initialValues: AppContextType = {
Expand All @@ -20,6 +24,8 @@ const initialValues: AppContextType = {
error: null,
isLoading: false,
mutate: () => {},

setModalInstance: (context) => {},
}

const useApps = () => {
Expand Down Expand Up @@ -68,14 +74,20 @@ const AppContextProvider: React.FC<PropsWithChildren> = ({children}) => {
[apps, appId],
)

const [modalInstance, setModalInstance] = useState()

appContextValues.currentApp = currentApp
appContextValues.apps = apps
appContextValues.error = error
appContextValues.isLoading = isLoading
appContextValues.mutate = mutate
appContextValues.modalInstance = modalInstance
appContextValues.setModalInstance = setModalInstance

return (
<AppContext.Provider value={{currentApp, apps, error, isLoading, mutate}}>
<AppContext.Provider
value={{currentApp, apps, error, isLoading, mutate, modalInstance, setModalInstance}}
>
{children}
</AppContext.Provider>
)
Expand Down

0 comments on commit 79d175f

Please sign in to comment.