Fix modal opening bug when not supposed to (#1795)
* fix opening modal error * Fix cleanOnClose behavior in IOModal component * Refactor useEffect dependency in CollectionCardComponent * remove console * add console.log for debugging --------- Co-authored-by: anovazzi1 <otavio2204@gmail.com>
This commit is contained in:
parent
dfc62752f3
commit
9c0ae350bf
3 changed files with 257 additions and 246 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { getComponent, postLikeComponent } from "../../controllers/API";
|
import { getComponent, postLikeComponent } from "../../controllers/API";
|
||||||
import DeleteConfirmationModal from "../../modals/DeleteConfirmationModal";
|
import DeleteConfirmationModal from "../../modals/DeleteConfirmationModal";
|
||||||
|
import IOModal from "../../modals/IOModal";
|
||||||
import useAlertStore from "../../stores/alertStore";
|
import useAlertStore from "../../stores/alertStore";
|
||||||
|
import useFlowStore from "../../stores/flowStore";
|
||||||
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
import useFlowsManagerStore from "../../stores/flowsManagerStore";
|
||||||
import { useStoreStore } from "../../stores/storeStore";
|
import { useStoreStore } from "../../stores/storeStore";
|
||||||
import { storeComponent } from "../../types/store";
|
import { storeComponent } from "../../types/store";
|
||||||
|
|
@ -18,11 +20,6 @@ import {
|
||||||
CardHeader,
|
CardHeader,
|
||||||
CardTitle,
|
CardTitle,
|
||||||
} from "../ui/card";
|
} from "../ui/card";
|
||||||
import IOModal from "../../modals/IOModal";
|
|
||||||
import useFlowStore from "../../stores/flowStore";
|
|
||||||
import { set } from "lodash";
|
|
||||||
import LoadingComponent from "../loadingComponent";
|
|
||||||
import { f } from "million/dist/shared/million.9d4df3c1";
|
|
||||||
import Loading from "../ui/loading";
|
import Loading from "../ui/loading";
|
||||||
|
|
||||||
export default function CollectionCardComponent({
|
export default function CollectionCardComponent({
|
||||||
|
|
@ -31,7 +28,7 @@ export default function CollectionCardComponent({
|
||||||
disabled = false,
|
disabled = false,
|
||||||
button,
|
button,
|
||||||
onDelete,
|
onDelete,
|
||||||
playground
|
playground,
|
||||||
}: {
|
}: {
|
||||||
data: storeComponent;
|
data: storeComponent;
|
||||||
authorized?: boolean;
|
authorized?: boolean;
|
||||||
|
|
@ -62,25 +59,32 @@ export default function CollectionCardComponent({
|
||||||
const setNodes = useFlowStore((state) => state.setNodes);
|
const setNodes = useFlowStore((state) => state.setNodes);
|
||||||
const setEdges = useFlowStore((state) => state.setEdges);
|
const setEdges = useFlowStore((state) => state.setEdges);
|
||||||
const [openPlayground, setOpenPlayground] = useState(false);
|
const [openPlayground, setOpenPlayground] = useState(false);
|
||||||
const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId);
|
const setCurrentFlowId = useFlowsManagerStore(
|
||||||
|
(state) => state.setCurrentFlowId
|
||||||
|
);
|
||||||
const [loadingPlayground, setLoadingPlayground] = useState(false);
|
const [loadingPlayground, setLoadingPlayground] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
const name = data.is_component ? "Component" : "Flow";
|
const name = data.is_component ? "Component" : "Flow";
|
||||||
|
|
||||||
async function getFlowData() {
|
async function getFlowData() {
|
||||||
const res = await getComponent(data.id)
|
const res = await getComponent(data.id);
|
||||||
const newFlow = cloneFLowWithParent(res, res.id, data.is_component, true);
|
const newFlow = cloneFLowWithParent(res, res.id, data.is_component, true);
|
||||||
return newFlow;
|
return newFlow;
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentFlowId && playground) {
|
if (currentFlowId && playground) {
|
||||||
|
if(openPlayground){
|
||||||
setNodes(currentFlow?.data?.nodes ?? [], true);
|
setNodes(currentFlow?.data?.nodes ?? [], true);
|
||||||
setEdges(currentFlow?.data?.edges ?? [], true);
|
setEdges(currentFlow?.data?.edges ?? [], true);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
setNodes([], true);
|
||||||
|
setEdges([], true);
|
||||||
cleanFlowPool();
|
cleanFlowPool();
|
||||||
}
|
}
|
||||||
}, [currentFlowId]);
|
}
|
||||||
|
}, [openPlayground]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -100,7 +104,8 @@ export default function CollectionCardComponent({
|
||||||
addFlow(true, newFlow)
|
addFlow(true, newFlow)
|
||||||
.then((id) => {
|
.then((id) => {
|
||||||
setSuccessData({
|
setSuccessData({
|
||||||
title: `${name} ${isStore ? "Downloaded" : "Installed"
|
title: `${name} ${
|
||||||
|
isStore ? "Downloaded" : "Installed"
|
||||||
} Successfully.`,
|
} Successfully.`,
|
||||||
});
|
});
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
@ -108,7 +113,8 @@ export default function CollectionCardComponent({
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: `Error ${isStore ? "downloading" : "installing"
|
title: `Error ${
|
||||||
|
isStore ? "downloading" : "installing"
|
||||||
} the ${name}`,
|
} the ${name}`,
|
||||||
list: [error["response"]["data"]["detail"]],
|
list: [error["response"]["data"]["detail"]],
|
||||||
});
|
});
|
||||||
|
|
@ -159,6 +165,7 @@ export default function CollectionCardComponent({
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<Card
|
<Card
|
||||||
className={cn(
|
className={cn(
|
||||||
"group relative flex min-h-[11rem] flex-col justify-between overflow-hidden transition-all hover:shadow-md",
|
"group relative flex min-h-[11rem] flex-col justify-between overflow-hidden transition-all hover:shadow-md",
|
||||||
|
|
@ -202,7 +209,10 @@ export default function CollectionCardComponent({
|
||||||
)}
|
)}
|
||||||
<ShadTooltip content="Likes">
|
<ShadTooltip content="Likes">
|
||||||
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||||
<IconComponent name="Heart" className={cn("h-4 w-4 ")} />
|
<IconComponent
|
||||||
|
name="Heart"
|
||||||
|
className={cn("h-4 w-4 ")}
|
||||||
|
/>
|
||||||
<span data-testid={`likes-${data.name}`}>
|
<span data-testid={`likes-${data.name}`}>
|
||||||
{likes_count ?? 0}
|
{likes_count ?? 0}
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -210,7 +220,10 @@ export default function CollectionCardComponent({
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
<ShadTooltip content="Downloads">
|
<ShadTooltip content="Downloads">
|
||||||
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
<span className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||||
<IconComponent name="DownloadCloud" className="h-4 w-4" />
|
<IconComponent
|
||||||
|
name="DownloadCloud"
|
||||||
|
className="h-4 w-4"
|
||||||
|
/>
|
||||||
<span data-testid={`downloads-${data.name}`}>
|
<span data-testid={`downloads-${data.name}`}>
|
||||||
{downloads_count ?? 0}
|
{downloads_count ?? 0}
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -365,7 +378,9 @@ export default function CollectionCardComponent({
|
||||||
data-testid={`install-${data.name}`}
|
data-testid={`install-${data.name}`}
|
||||||
>
|
>
|
||||||
<IconComponent
|
<IconComponent
|
||||||
name={loading ? "Loader2" : isStore ? "Download" : "Plus"}
|
name={
|
||||||
|
loading ? "Loader2" : isStore ? "Download" : "Plus"
|
||||||
|
}
|
||||||
className={cn(
|
className={cn(
|
||||||
loading ? "h-5 w-5 animate-spin" : "h-5 w-5",
|
loading ? "h-5 w-5 animate-spin" : "h-5 w-5",
|
||||||
!authorized ? " text-ring" : ""
|
!authorized ? " text-ring" : ""
|
||||||
|
|
@ -376,7 +391,7 @@ export default function CollectionCardComponent({
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{button && button}
|
{button && button}
|
||||||
{playground &&
|
{playground && (
|
||||||
<Button
|
<Button
|
||||||
disabled={loadingPlayground}
|
disabled={loadingPlayground}
|
||||||
key={data.id}
|
key={data.id}
|
||||||
|
|
@ -384,44 +399,49 @@ export default function CollectionCardComponent({
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="whitespace-nowrap "
|
className="whitespace-nowrap "
|
||||||
data-testid={
|
data-testid={"playground-flow-button-" + data.id}
|
||||||
"playground-flow-button-" + data.id
|
|
||||||
}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setLoadingPlayground(true);
|
setLoadingPlayground(true);
|
||||||
if (getFlowById(data.id)) {
|
if (getFlowById(data.id)) {
|
||||||
setCurrentFlowId(data.id);
|
setCurrentFlowId(data.id);
|
||||||
setOpenPlayground(true);
|
setOpenPlayground(true);
|
||||||
setLoadingPlayground(false);
|
setLoadingPlayground(false);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
getFlowData().then((res) => {
|
getFlowData().then((res) => {
|
||||||
setCurrentFlow(res);
|
setCurrentFlow(res);
|
||||||
setOpenPlayground(true);
|
setOpenPlayground(true);
|
||||||
setLoadingPlayground(false);
|
setLoadingPlayground(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{!loadingPlayground ?
|
{!loadingPlayground ? (
|
||||||
<>
|
<>
|
||||||
<IconComponent
|
<IconComponent
|
||||||
name="ExternalLink"
|
name="ExternalLink"
|
||||||
className="main-page-nav-button select-none"
|
className="main-page-nav-button select-none"
|
||||||
/>
|
/>
|
||||||
Playground
|
Playground
|
||||||
</>:
|
</>
|
||||||
|
) : (
|
||||||
<Loading />
|
<Loading />
|
||||||
}
|
)}
|
||||||
{openPlayground && < IOModal cleanOnClose={true} open={openPlayground} setOpen={setOpenPlayground}>
|
|
||||||
<></>
|
|
||||||
</IOModal>}
|
|
||||||
</Button>
|
</Button>
|
||||||
}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{openPlayground && (
|
||||||
|
<IOModal
|
||||||
|
cleanOnClose={true}
|
||||||
|
open={openPlayground}
|
||||||
|
setOpen={setOpenPlayground}
|
||||||
|
>
|
||||||
|
<></>
|
||||||
|
</IOModal>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,8 @@ export default function IOModal({
|
||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
disable,
|
disable,
|
||||||
cleanOnClose=false,
|
|
||||||
}: IOModalPropsType): JSX.Element {
|
}: IOModalPropsType): JSX.Element {
|
||||||
const allNodes = useFlowStore((state) => state.nodes);
|
const allNodes = useFlowStore((state) => state.nodes);
|
||||||
const cleanFlowPool = useFlowStore((state) => state.CleanFlowPool);
|
|
||||||
const inputs = useFlowStore((state) => state.inputs).filter(
|
const inputs = useFlowStore((state) => state.inputs).filter(
|
||||||
(input) => input.type !== "ChatInput"
|
(input) => input.type !== "ChatInput"
|
||||||
);
|
);
|
||||||
|
|
@ -85,12 +83,6 @@ export default function IOModal({
|
||||||
return updateVerticesOrder(currentFlow!.id, null);
|
return updateVerticesOrder(currentFlow!.id, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// if (open) {
|
|
||||||
// updateVertices();
|
|
||||||
// }
|
|
||||||
// }, [open, currentFlow]);
|
|
||||||
|
|
||||||
async function sendMessage(count = 1): Promise<void> {
|
async function sendMessage(count = 1): Promise<void> {
|
||||||
if (isBuilding) return;
|
if (isBuilding) return;
|
||||||
setIsBuilding(true);
|
setIsBuilding(true);
|
||||||
|
|
@ -129,13 +121,6 @@ export default function IOModal({
|
||||||
open={open}
|
open={open}
|
||||||
setOpen={setOpen}
|
setOpen={setOpen}
|
||||||
disable={disable}
|
disable={disable}
|
||||||
onChangeOpenModal={(open)=>{
|
|
||||||
if(!open && cleanOnClose){
|
|
||||||
console.log("cleaning flow pool")
|
|
||||||
cleanFlowPool();
|
|
||||||
}
|
|
||||||
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<BaseModal.Trigger>{children}</BaseModal.Trigger>
|
<BaseModal.Trigger>{children}</BaseModal.Trigger>
|
||||||
{/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */}
|
{/* TODO ADAPT TO ALL TYPES OF INPUTS AND OUTPUTS */}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ export default function PlaygroundPage() {
|
||||||
|
|
||||||
// Set flow tab id
|
// Set flow tab id
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log("id", id);
|
||||||
if (getFlowById(id!)) {
|
if (getFlowById(id!)) {
|
||||||
setCurrentFlowId(id!);
|
setCurrentFlowId(id!);
|
||||||
}
|
}
|
||||||
|
|
@ -44,6 +45,11 @@ export default function PlaygroundPage() {
|
||||||
cleanFlowPool();
|
cleanFlowPool();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
return () => {
|
||||||
|
setNodes([], true);
|
||||||
|
setEdges([], true);
|
||||||
|
cleanFlowPool();
|
||||||
|
};
|
||||||
}, [currentFlow]);
|
}, [currentFlow]);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue