mirror of
https://github.com/hexastack/hexabot
synced 2025-04-24 08:14:35 +00:00
feat(frontend): add router query for visual editor flows
This commit is contained in:
parent
1f61e43f58
commit
94e3a4b647
@ -29,6 +29,7 @@ import {
|
|||||||
DiagramModel,
|
DiagramModel,
|
||||||
DiagramModelGenerics,
|
DiagramModelGenerics,
|
||||||
} from "@projectstorm/react-diagrams";
|
} from "@projectstorm/react-diagrams";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
import {
|
import {
|
||||||
SyntheticEvent,
|
SyntheticEvent,
|
||||||
useCallback,
|
useCallback,
|
||||||
@ -52,7 +53,7 @@ import useDebouncedUpdate from "@/hooks/useDebouncedUpdate";
|
|||||||
import { getDisplayDialogs, useDialog } from "@/hooks/useDialog";
|
import { getDisplayDialogs, useDialog } from "@/hooks/useDialog";
|
||||||
import { useSearch } from "@/hooks/useSearch";
|
import { useSearch } from "@/hooks/useSearch";
|
||||||
import { useTranslate } from "@/hooks/useTranslate";
|
import { useTranslate } from "@/hooks/useTranslate";
|
||||||
import { EntityType, Format, QueryType } from "@/services/types";
|
import { EntityType, Format, QueryType, RouterType } from "@/services/types";
|
||||||
import { IBlock } from "@/types/block.types";
|
import { IBlock } from "@/types/block.types";
|
||||||
import { ICategory } from "@/types/category.types";
|
import { ICategory } from "@/types/category.types";
|
||||||
import { BlockPorts } from "@/types/visual-editor.types";
|
import { BlockPorts } from "@/types/visual-editor.types";
|
||||||
@ -65,6 +66,8 @@ import { AdvancedLinkModel } from "./AdvancedLink/AdvancedLinkModel";
|
|||||||
|
|
||||||
const Diagrams = () => {
|
const Diagrams = () => {
|
||||||
const { t } = useTranslate();
|
const { t } = useTranslate();
|
||||||
|
const router = useRouter();
|
||||||
|
const flowId = router.query.id?.toString();
|
||||||
const [model, setModel] = useState<
|
const [model, setModel] = useState<
|
||||||
DiagramModel<DiagramModelGenerics> | undefined
|
DiagramModel<DiagramModelGenerics> | undefined
|
||||||
>();
|
>();
|
||||||
@ -95,7 +98,9 @@ const Diagrams = () => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess([{ id, zoom, offset }]) {
|
onSuccess([{ id, zoom, offset }]) {
|
||||||
if (id) {
|
if (flowId) {
|
||||||
|
setSelectedCategoryId?.(flowId);
|
||||||
|
} else if (id) {
|
||||||
setSelectedCategoryId?.(id);
|
setSelectedCategoryId?.(id);
|
||||||
if (engine?.getModel()) {
|
if (engine?.getModel()) {
|
||||||
setViewerOffset(offset || [0, 0]);
|
setViewerOffset(offset || [0, 0]);
|
||||||
@ -161,6 +166,8 @@ const Diagrams = () => {
|
|||||||
if (id) {
|
if (id) {
|
||||||
setSelectedCategoryId?.(id);
|
setSelectedCategoryId?.(id);
|
||||||
setSelectedBlockId(undefined); // Reset selected block when switching categories, resetting edit & remove buttons
|
setSelectedBlockId(undefined); // Reset selected block when switching categories, resetting edit & remove buttons
|
||||||
|
|
||||||
|
router.push(`/${RouterType.VISUAL_EDITOR}/flows/${id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -181,6 +188,12 @@ const Diagrams = () => {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSelectedCategoryId(flowId || "");
|
||||||
|
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [flowId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { canvas, model, engine } = buildDiagram({
|
const { canvas, model, engine } = buildDiagram({
|
||||||
zoom: currentCategory?.zoom || 100,
|
zoom: currentCategory?.zoom || 100,
|
||||||
|
11
frontend/src/pages/visual-editor/flows/[id]/index.tsx
Normal file
11
frontend/src/pages/visual-editor/flows/[id]/index.tsx
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import VisualEditorPage from "../..";
|
||||||
|
|
||||||
|
export default VisualEditorPage;
|
11
frontend/src/pages/visual-editor/flows/index.tsx
Normal file
11
frontend/src/pages/visual-editor/flows/index.tsx
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import VisualEditorPage from "..";
|
||||||
|
|
||||||
|
export default VisualEditorPage;
|
Loading…
Reference in New Issue
Block a user