Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restarting closed container from UI results in navigation to main page #559

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {useEffect} from "react"
import React from "react"
import {Modal, Button} from "antd"
import {useRouter} from "next/router"
import {Variant} from "@/lib/Types"
import {createUseStyles} from "react-jss"

const useStyles = createUseStyles({
Expand All @@ -19,15 +18,13 @@ interface Props {
setIsModalOpen: (value: boolean) => void
handleRemove: () => void
handleCancel: () => void
variants: Variant[]
}

const VariantRemovalWarningModal: React.FC<Props> = ({
isModalOpen,
setIsModalOpen,
handleRemove,
handleCancel,
variants,
}) => {
const classes = useStyles()
const handleCloseModal = () => setIsModalOpen(false)
Expand All @@ -38,12 +35,6 @@ const VariantRemovalWarningModal: React.FC<Props> = ({
handleCloseModal()
}

useEffect(() => {
mmabrouk marked this conversation as resolved.
Show resolved Hide resolved
if (variants.length < 1) {
router.push(`/apps`)
}
}, [variants])

const handleDismiss = () => {
handleCancel()
handleCloseModal()
Expand Down
8 changes: 4 additions & 4 deletions agenta-web/src/components/Playground/VersionTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Tabs, message} from "antd"
import ViewNavigation from "./ViewNavigation"
import VariantRemovalWarningModal from "./VariantRemovalWarningModal"
import NewVariantModal from "./NewVariantModal"
import {useRouter} from "next/router"
import router, {useRouter} from "next/router"
import {fetchVariants, removeVariant} from "@/lib/services/api"
import {Variant, PlaygroundTabsItem} from "@/lib/Types"

Expand Down Expand Up @@ -54,7 +54,9 @@ function addTab(
function removeTab(setActiveKey: any, setVariants: any, variants: Variant[], activeKey: string) {
console.log(activeKey)
const newVariants = variants.filter((variant) => variant.variantName !== activeKey)

if (newVariants.length < 1) {
router.push(`/apps`)
}
let newActiveKey = ""
if (newVariants.length > 0) {
newActiveKey = newVariants[newVariants.length - 1].variantName
Expand Down Expand Up @@ -196,14 +198,12 @@ const VersionTabs: React.FC = () => {
setTemplateVariantName={setTemplateVariantName}
/>
<VariantRemovalWarningModal
variants={variants}
isModalOpen={isWarningModalOpen1}
setIsModalOpen={setRemovalWarningModalOpen1}
handleRemove={handleRemove}
handleCancel={handleCancel1}
/>
<VariantRemovalWarningModal
variants={variants}
isModalOpen={isWarningModalOpen2}
setIsModalOpen={setRemovalWarningModalOpen2}
handleRemove={handleBackendRemove}
Expand Down
13 changes: 4 additions & 9 deletions agenta-web/src/components/Playground/ViewNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {useRouter} from "next/router"
import {useState} from "react"
import axios from "axios"
import {createUseStyles} from "react-jss"
import {getAppContainerURL, restartAppVariantContainer} from "@/lib/services/api"
import {getAppContainerURL, restartAppVariantContainer, waitForAppToStart} from "@/lib/services/api"

interface Props {
variant: Variant
Expand Down Expand Up @@ -99,17 +99,12 @@ const ViewNavigation: React.FC<Props> = ({
})

// Set restarting to false
await waitForAppToStart(appName)
router.reload()
setRestarting(false)
setTimeout(() => {
// Wait for 3s before reloading component
router.reload()
}, 3000)
}
} catch (err: any) {
if (axios.isAxiosError(err) && err.response?.status === 500) {
// Set restarting to flase
setRestarting(false)
}
setRestarting(false)
}
}

Expand Down
7 changes: 1 addition & 6 deletions agenta-web/src/lib/helpers/axiosConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ axios.interceptors.response.use(
}`
error.message = msg

const apiCallUrl: string = error.response.request.responseURL
if (apiCallUrl && apiCallUrl.endsWith("openapi.json")) {
globalErrorHandler("Docker container is currently not running. Consider restarting it.")
} else {
globalErrorHandler(error)
}
globalErrorHandler(error)

throw error
},
Expand Down