"Refactor: Add playground check before opening" (#1845)
Refactor: Add playground check before opening (#1844)
This commit is contained in:
parent
81d31b1337
commit
0226706391
1 changed files with 51 additions and 5 deletions
|
|
@ -7,7 +7,9 @@ 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";
|
||||||
import cloneFLowWithParent from "../../utils/storeUtils";
|
import cloneFLowWithParent, {
|
||||||
|
getInputsAndOutputs,
|
||||||
|
} from "../../utils/storeUtils";
|
||||||
import { cn, convertTestName } from "../../utils/utils";
|
import { cn, convertTestName } from "../../utils/utils";
|
||||||
import IconComponent from "../genericIconComponent";
|
import IconComponent from "../genericIconComponent";
|
||||||
import ShadTooltip from "../shadTooltipComponent";
|
import ShadTooltip from "../shadTooltipComponent";
|
||||||
|
|
@ -20,6 +22,7 @@ import {
|
||||||
CardTitle,
|
CardTitle,
|
||||||
} from "../ui/card";
|
} from "../ui/card";
|
||||||
import Loading from "../ui/loading";
|
import Loading from "../ui/loading";
|
||||||
|
import { FlowType } from "../../types/flow";
|
||||||
|
|
||||||
export default function CollectionCardComponent({
|
export default function CollectionCardComponent({
|
||||||
data,
|
data,
|
||||||
|
|
@ -74,6 +77,15 @@ export default function CollectionCardComponent({
|
||||||
return newFlow;
|
return newFlow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hasPlayground(flow?: FlowType) {
|
||||||
|
if (!flow) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const { inputs, outputs } = getInputsAndOutputs(flow?.data?.nodes ?? []);
|
||||||
|
console.log(inputs, outputs);
|
||||||
|
return inputs.length > 0 || outputs.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (currentFlowId && playground) {
|
if (currentFlowId && playground) {
|
||||||
if (openPlayground) {
|
if (openPlayground) {
|
||||||
|
|
@ -296,7 +308,7 @@ export default function CollectionCardComponent({
|
||||||
<div className="flex w-full flex-wrap items-end justify-end gap-2">
|
<div className="flex w-full flex-wrap items-end justify-end gap-2">
|
||||||
{playground && data?.metadata !== undefined ? (
|
{playground && data?.metadata !== undefined ? (
|
||||||
<Button
|
<Button
|
||||||
disabled={loadingPlayground}
|
disabled={loadingPlayground || !authorized}
|
||||||
key={data.id}
|
key={data.id}
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|
@ -307,12 +319,29 @@ export default function CollectionCardComponent({
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
setLoadingPlayground(true);
|
setLoadingPlayground(true);
|
||||||
if (getFlowById(data.id)) {
|
const flow = getFlowById(data.id);
|
||||||
|
if (flow) {
|
||||||
|
if (!hasPlayground(flow)) {
|
||||||
|
setErrorData({
|
||||||
|
title: "Error",
|
||||||
|
list: ["This flow doesn't have a playground."],
|
||||||
|
});
|
||||||
|
setLoadingPlayground(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setCurrentFlowId(data.id);
|
setCurrentFlowId(data.id);
|
||||||
setOpenPlayground(true);
|
setOpenPlayground(true);
|
||||||
setLoadingPlayground(false);
|
setLoadingPlayground(false);
|
||||||
} else {
|
} else {
|
||||||
getFlowData().then((res) => {
|
getFlowData().then((res) => {
|
||||||
|
if (!hasPlayground(res)) {
|
||||||
|
setErrorData({
|
||||||
|
title: "Error",
|
||||||
|
list: ["This flow doesn't have a playground."],
|
||||||
|
});
|
||||||
|
setLoadingPlayground(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setCurrentFlow(res);
|
setCurrentFlow(res);
|
||||||
setOpenPlayground(true);
|
setOpenPlayground(true);
|
||||||
setLoadingPlayground(false);
|
setLoadingPlayground(false);
|
||||||
|
|
@ -439,7 +468,7 @@ export default function CollectionCardComponent({
|
||||||
)}
|
)}
|
||||||
{playground && data?.metadata === undefined && (
|
{playground && data?.metadata === undefined && (
|
||||||
<Button
|
<Button
|
||||||
disabled={loadingPlayground}
|
disabled={loadingPlayground || !authorized}
|
||||||
key={data.id}
|
key={data.id}
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
variant="primary"
|
variant="primary"
|
||||||
|
|
@ -450,12 +479,29 @@ export default function CollectionCardComponent({
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
setLoadingPlayground(true);
|
setLoadingPlayground(true);
|
||||||
if (getFlowById(data.id)) {
|
const flow = getFlowById(data.id);
|
||||||
|
if (flow) {
|
||||||
|
if (!hasPlayground(flow)) {
|
||||||
|
setErrorData({
|
||||||
|
title: "Error",
|
||||||
|
list: ["This flow doesn't have a playground."],
|
||||||
|
});
|
||||||
|
setLoadingPlayground(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setCurrentFlowId(data.id);
|
setCurrentFlowId(data.id);
|
||||||
setOpenPlayground(true);
|
setOpenPlayground(true);
|
||||||
setLoadingPlayground(false);
|
setLoadingPlayground(false);
|
||||||
} else {
|
} else {
|
||||||
getFlowData().then((res) => {
|
getFlowData().then((res) => {
|
||||||
|
if (!hasPlayground(res)) {
|
||||||
|
setErrorData({
|
||||||
|
title: "Error",
|
||||||
|
list: ["This flow doesn't have a playground."],
|
||||||
|
});
|
||||||
|
setLoadingPlayground(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setCurrentFlow(res);
|
setCurrentFlow(res);
|
||||||
setOpenPlayground(true);
|
setOpenPlayground(true);
|
||||||
setLoadingPlayground(false);
|
setLoadingPlayground(false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue