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

Warn users when they leave the playground without saving a variant #557

Closed
wants to merge 85 commits into from
Closed
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
f1777d9
adds state to monitor changes in playground
bekossy Aug 19, 2023
48d2d2b
creates modal to warn users about unsaved changes
bekossy Aug 19, 2023
8e3dec0
runs prettier
bekossy Aug 19, 2023
4d806a8
minor fix
bekossy Aug 19, 2023
481a33f
Merge branch 'main' into issue-340
bekossy Aug 19, 2023
3ba7c13
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 23, 2023
f0b3dae
Merge branch 'main' into issue-340
bekossy Aug 29, 2023
93210ee
fixes bug
bekossy Aug 29, 2023
d309330
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 30, 2023
dfdc97f
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 30, 2023
b598cf9
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 30, 2023
b840c19
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 30, 2023
c93b6fd
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 30, 2023
39e3ae6
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 31, 2023
9f2356e
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 31, 2023
243be95
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 31, 2023
d15dc96
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 31, 2023
11bf2ec
Merge branch 'Agenta-AI:main' into issue-340
bekossy Aug 31, 2023
1c45394
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 1, 2023
579e96a
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 1, 2023
caa78ad
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 2, 2023
48dcea7
removes state
bekossy Sep 2, 2023
ae3524d
add confirmation dialog for unsaved config changes
bekossy Sep 2, 2023
2b8e04e
runs prettier
bekossy Sep 2, 2023
b94d061
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 3, 2023
96c4bab
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 3, 2023
9e1f182
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 3, 2023
2912218
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 4, 2023
9659667
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 4, 2023
c0d34df
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 4, 2023
bfcebce
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 5, 2023
9506e85
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 5, 2023
c00c175
removes isChanged state
bekossy Sep 5, 2023
8ced7a2
revert changes
bekossy Sep 5, 2023
7596888
Merge branch 'main' into issue-340
bekossy Sep 6, 2023
4310b83
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 6, 2023
3759315
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 7, 2023
b1600f3
runs prettier
bekossy Sep 7, 2023
46863f9
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 7, 2023
e282271
refactors fix
bekossy Sep 8, 2023
906ae50
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 8, 2023
6b6396a
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 8, 2023
3a88e41
Merge branch 'issue-340' of https://github.com/bekossy/agenta into is…
bekossy Sep 9, 2023
e5ef063
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 10, 2023
247922a
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 10, 2023
2212dc3
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 11, 2023
88e5155
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 11, 2023
b34df44
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 12, 2023
11eef1d
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 12, 2023
4056c4b
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 12, 2023
9548ab3
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 12, 2023
3e5872a
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 13, 2023
57fb381
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 13, 2023
31083a4
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 13, 2023
6da7f6d
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 13, 2023
09b82d2
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 14, 2023
a15c3b6
Fix: Restored missing code
bekossy Sep 14, 2023
9431ba5
fea: Add unsaved configuration warning
bekossy Sep 14, 2023
2f7ec33
refactor code
bekossy Sep 14, 2023
99a3b38
bug fix
bekossy Sep 14, 2023
b5b0f5b
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 15, 2023
41fd05c
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 15, 2023
6b9145f
revert changes
bekossy Sep 15, 2023
8ab5eaa
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 15, 2023
1f3cbca
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 17, 2023
e866bba
fix multiple warning modals
bekossy Sep 18, 2023
650901f
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 18, 2023
fff45d2
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 19, 2023
45a0f11
bug fix
bekossy Sep 19, 2023
4277df3
Merge branch 'main' into issue-340
bekossy Sep 20, 2023
9aee0ae
format fix
bekossy Sep 20, 2023
ecdad70
bug fix
bekossy Sep 20, 2023
c90403b
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 21, 2023
c12bee3
saves Variant change
bekossy Sep 24, 2023
aeed433
fixes delete bug
bekossy Sep 24, 2023
24f8f00
minor changes
bekossy Sep 24, 2023
9c5178c
bug: conditional checks to save variants
bekossy Sep 25, 2023
4b5b507
refactors functionality and bug fix
bekossy Sep 25, 2023
bffc3db
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 25, 2023
390a9a6
Merge branch 'issue-340' of https://github.com/bekossy/agenta into is…
bekossy Sep 25, 2023
bef659b
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 25, 2023
685778a
bug fix
bekossy Sep 25, 2023
e5f810e
mod: adds message component
bekossy Sep 25, 2023
6856f46
Merge branch 'Agenta-AI:main' into issue-340
bekossy Sep 29, 2023
a9f9b3d
Merge branch 'Agenta-AI:main' into issue-340
bekossy Oct 3, 2023
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
15 changes: 13 additions & 2 deletions agenta-web/src/components/Playground/VersionTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function addTab(
variants: Variant[],
templateVariantName: string,
newVariantName: string,
setIsChanged: React.Dispatch<React.SetStateAction<boolean>>,
) {
// Find the template variant
const templateVariant = variants.find((variant) => variant.variantName === templateVariantName)
Expand Down Expand Up @@ -51,6 +52,7 @@ function addTab(

setVariants((prevState: any) => [...prevState, newVariant])
setActiveKey(updateNewVariantName)
setIsChanged(true)
}

function removeTab(setActiveKey: any, setVariants: any, variants: Variant[], activeKey: string) {
Expand All @@ -73,7 +75,6 @@ const VersionTabs: React.FC = () => {
const appName = router.query.app_name as unknown as string
const [templateVariantName, setTemplateVariantName] = useState("") // We use this to save the template variant name when the user creates a new variant
const [activeKey, setActiveKey] = useState("1")
const [tabList, setTabList] = useState([])
const [isModalOpen, setIsModalOpen] = useState(false)
const [variants, setVariants] = useState<Variant[]>([]) // These are the variants that exist in the backend
const [isLoading, setIsLoading] = useState(true)
Expand All @@ -84,6 +85,7 @@ const VersionTabs: React.FC = () => {
const [removalVariantName, setRemovalVariantName] = useState<string | null>(null)
const [isDeleteLoading, setIsDeleteLoading] = useState(false)
const [messageApi, contextHolder] = message.useMessage()
const [isChanged, setIsChanged] = useState(false)

const fetchData = async () => {
try {
Expand Down Expand Up @@ -164,6 +166,8 @@ const VersionTabs: React.FC = () => {
setRemovalVariantName={setRemovalVariantName}
setRemovalWarningModalOpen={setRemovalWarningModalOpen2}
isDeleteLoading={isDeleteLoading && removalVariantName === variant.variantName}
isChanged={isChanged}
setIsChanged={setIsChanged}
/>
),
closable: !variant.persistent,
Expand Down Expand Up @@ -203,7 +207,14 @@ const VersionTabs: React.FC = () => {
isModalOpen={isModalOpen}
setIsModalOpen={setIsModalOpen}
addTab={() =>
addTab(setActiveKey, setVariants, variants, templateVariantName, newVariantName)
addTab(
setActiveKey,
setVariants,
variants,
templateVariantName,
newVariantName,
setIsChanged,
)
}
variants={variants}
setNewVariantName={setNewVariantName}
Expand Down
30 changes: 29 additions & 1 deletion agenta-web/src/components/Playground/ViewNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from "react"
import React, {useEffect} from "react"
import {Col, Row, Divider, Button, Tooltip, Spin, notification} from "antd"
import TestView from "./Views/TestView"
import ParametersView from "./Views/ParametersView"
import {useVariant} from "@/lib/hooks/useVariant"
import {RestartVariantDocker, Variant} from "@/lib/Types"
import {useRouter} from "next/router"
import {useState} from "react"
import useBlockNavigation from "@/hooks/useBlockNavigation"
import useStateCallback from "@/hooks/useStateCallback"
import axios from "axios"
import {createUseStyles} from "react-jss"
import {getAppContainerURL, restartAppVariantContainer, waitForAppToStart} from "@/lib/services/api"
Expand All @@ -16,6 +18,8 @@ interface Props {
setRemovalVariantName: (variantName: string) => void
setRemovalWarningModalOpen: (value: boolean) => void
isDeleteLoading: boolean
isChanged: boolean
setIsChanged: React.Dispatch<React.SetStateAction<boolean>>
}

const useStyles = createUseStyles({
Expand All @@ -33,6 +37,8 @@ const ViewNavigation: React.FC<Props> = ({
setRemovalVariantName,
setRemovalWarningModalOpen,
isDeleteLoading,
isChanged,
setIsChanged,
}) => {
const classes = useStyles()
const router = useRouter()
Expand All @@ -48,6 +54,26 @@ const ViewNavigation: React.FC<Props> = ({
isLoading,
} = useVariant(appName, variant)

const [unSavedChanges, setUnSavedChanges] = useStateCallback(false)

useBlockNavigation(unSavedChanges, {
title: "Unsaved changes",
message:
"You have unsaved changes in your playground. Do you want to save these changes before leaving the page?",
okText: "Save",
onOk: async () => {
await saveOptParams(optParams!, true, variant.persistent)
return !!optParams
},
cancelText: "Proceed without saving",
})

useEffect(() => {
if (isChanged) {
setUnSavedChanges(true)
}
}, [optParams])

const [isParamsCollapsed, setIsParamsCollapsed] = useState("1")
const [containerURIPath, setContainerURIPath] = useState("")
const [restarting, setRestarting] = useState<boolean>(false)
Expand Down Expand Up @@ -192,6 +218,8 @@ const ViewNavigation: React.FC<Props> = ({
isDeleteLoading={isDeleteLoading}
isParamsCollapsed={isParamsCollapsed}
setIsParamsCollapsed={setIsParamsCollapsed}
setUnSavedChanges={setUnSavedChanges}
setIsChanged={setIsChanged}
/>
</Col>
</Row>
Expand Down
10 changes: 9 additions & 1 deletion agenta-web/src/components/Playground/Views/ParametersView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useState} from "react"
import {Dispatch, useState} from "react"
import React from "react"
import {Parameter} from "@/lib/Types"
import {Row, Col, Button, Tooltip, message, Space, Collapse} from "antd"
Expand All @@ -17,6 +17,8 @@ interface Props {
isPersistent: boolean
isParamsCollapsed: string
setIsParamsCollapsed: (value: string) => void
setUnSavedChanges: Dispatch<React.SetStateAction<boolean>>
setIsChanged: React.Dispatch<React.SetStateAction<boolean>>
}

const useStyles = createUseStyles({
Expand Down Expand Up @@ -53,19 +55,23 @@ const ParametersView: React.FC<Props> = ({
isPersistent,
isParamsCollapsed,
setIsParamsCollapsed,
setUnSavedChanges,
setIsChanged,
}) => {
const classes = useStyles()
const [inputValue, setInputValue] = useState(1)
const [messageApi, contextHolder] = message.useMessage()
const onChange = (param: Parameter, newValue: number | string) => {
setInputValue(+newValue)
handleParamChange(param.name, newValue)
setIsChanged(true)
}
const handleParamChange = (name: string, newVal: any) => {
const newOptParams = optParams?.map((param) =>
param.name === name ? {...param, default: newVal} : param,
)
newOptParams && onOptParamsChange(newOptParams, false, false)
setIsChanged(true)
}
const success = () => {
messageApi.open({
Expand Down Expand Up @@ -93,6 +99,8 @@ const ParametersView: React.FC<Props> = ({
type="primary"
onClick={async () => {
await onOptParamsChange(optParams!, true, isPersistent)
setUnSavedChanges(false)
setIsChanged(false)
success()
}}
loading={isParamSaveLoading}
Expand Down