Skip to content

feat: add url parameter to playground modal #7270

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 10 additions & 2 deletions src/frontend/src/components/core/flowToolbarComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { track } from "@/customization/utils/analytics";
import { Panel } from "@xyflow/react";
import { useEffect, useMemo, useState } from "react";
import { useHotkeys } from "react-hotkeys-hook";
import { useSearchParams } from "react-router-dom";
import ApiModal from "../../../modals/apiModal";
import ShareModal from "../../../modals/shareModal";
import useFlowStore from "../../../stores/flowStore";
Expand All @@ -20,18 +21,25 @@ import FlowToolbarOptions from "./components/flow-toolbar-options";

export default function FlowToolbar(): JSX.Element {
const preventDefault = true;
const [open, setOpen] = useState<boolean>(false);

const [searchParams, setSearchParams] = useSearchParams();
const [openCodeModal, setOpenCodeModal] = useState<boolean>(false);
const [openShareModal, setOpenShareModal] = useState<boolean>(false);
function handleAPIWShortcut(e: KeyboardEvent) {
if (isThereModal() && !openCodeModal) return;
setOpenCodeModal((oldOpen) => !oldOpen);
}

const open = searchParams.get("playground") === "true";

function setOpen(isOpen: boolean) {
setSearchParams({ playground: isOpen ? "true" : "false" });
}

function handleChatWShortcut(e: KeyboardEvent) {
if (isThereModal() && !open) return;
if (useFlowStore.getState().hasIO) {
setOpen((oldState) => !oldState);
setOpen(!open);
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/frontend/src/pages/FlowPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export default function FlowPage({ view }: { view?: boolean }): JSX.Element {
(currentFlow?.data?.nodes?.length ?? 0) > 0;

const isBuilding = useFlowStore((state) => state.isBuilding);
const blocker = useBlocker(changesNotSaved || isBuilding);
const blocker = useBlocker(
({ currentLocation, nextLocation }) =>
(changesNotSaved || isBuilding) &&
!checkIsPlaygroundModalNavigation(currentLocation, nextLocation),
);

const setOnFlowPage = useFlowStore((state) => state.setOnFlowPage);
const { id } = useParams();
Expand Down Expand Up @@ -84,6 +88,13 @@ export default function FlowPage({ view }: { view?: boolean }): JSX.Element {
}
};

const checkIsPlaygroundModalNavigation = (currentLocation, nextLocation) => {
return (
nextLocation.search.includes("playground") &&
currentLocation.pathname === nextLocation.pathname
);
};

useEffect(() => {
const handleBeforeUnload = (event: BeforeUnloadEvent) => {
if (changesNotSaved || isBuilding) {
Expand Down
Loading