mirror of
https://github.com/hexastack/hexabot
synced 2024-11-25 13:27:58 +00:00
feat(frontend): catch websocket textToAction event
This commit is contained in:
parent
48d795df26
commit
5a18780aca
@ -51,11 +51,12 @@ import { EntityType, Format } 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";
|
||||||
|
import { useSocket, useSocketGetQuery } from "@/websocket/socket-hooks";
|
||||||
|
|
||||||
import { AdvancedLinkModel } from "./AdvancedLink/AdvancedLinkModel";
|
|
||||||
import BlockDialog from "../BlockDialog";
|
import BlockDialog from "../BlockDialog";
|
||||||
import { ZOOM_LEVEL } from "../constants";
|
import { ZOOM_LEVEL } from "../constants";
|
||||||
import { useVisualEditor } from "../hooks/useVisualEditor";
|
import { useVisualEditor } from "../hooks/useVisualEditor";
|
||||||
|
import { AdvancedLinkModel } from "./AdvancedLink/AdvancedLinkModel";
|
||||||
|
|
||||||
const Diagrams = () => {
|
const Diagrams = () => {
|
||||||
const { t } = useTranslate();
|
const { t } = useTranslate();
|
||||||
@ -79,15 +80,23 @@ const Diagrams = () => {
|
|||||||
const { searchPayload } = useSearch<IBlock>({
|
const { searchPayload } = useSearch<IBlock>({
|
||||||
$eq: [{ category: selectedCategoryId }],
|
$eq: [{ category: selectedCategoryId }],
|
||||||
});
|
});
|
||||||
const { data: categories } = useFind(
|
const [hasTextToActions, setHasTextToActions] = useState(false);
|
||||||
|
const { data: categories, refetch } = useFind(
|
||||||
{ entity: EntityType.CATEGORY },
|
{ entity: EntityType.CATEGORY },
|
||||||
{
|
{
|
||||||
hasCount: false,
|
hasCount: false,
|
||||||
initialSortState: [{ field: "createdAt", sort: "asc" }],
|
initialSortState: [{ field: "createdAt", sort: "asc" }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess([{ id, zoom, offset }]) {
|
onSuccess(categories) {
|
||||||
if (id) {
|
const { id, zoom, offset } = categories[0];
|
||||||
|
const aiGeneratedFlowId = categories.find(
|
||||||
|
(category) => category.label === "AI Flow",
|
||||||
|
)?.id;
|
||||||
|
|
||||||
|
if (aiGeneratedFlowId && hasTextToActions) {
|
||||||
|
setSelectedCategoryId?.(aiGeneratedFlowId);
|
||||||
|
} else if (id) {
|
||||||
setSelectedCategoryId?.(id);
|
setSelectedCategoryId?.(id);
|
||||||
if (engine?.getModel()) {
|
if (engine?.getModel()) {
|
||||||
setViewerOffset(offset || [0, 0]);
|
setViewerOffset(offset || [0, 0]);
|
||||||
@ -429,6 +438,23 @@ const Diagrams = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useSocketGetQuery("/subscriber/subscribe/");
|
||||||
|
|
||||||
|
const { socket } = useSocket();
|
||||||
|
|
||||||
|
socket?.on(
|
||||||
|
"actions",
|
||||||
|
async (event: { op: "textToActions"; msg: string[] }) => {
|
||||||
|
if (
|
||||||
|
event?.op === "textToActions" &&
|
||||||
|
event.msg.includes("navigateToAiFlow")
|
||||||
|
) {
|
||||||
|
setHasTextToActions(true);
|
||||||
|
await refetch();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="visual-editor"
|
className="visual-editor"
|
||||||
|
Loading…
Reference in New Issue
Block a user