fix: stop building with abort controller (#3634)
* Added buildController and stopBuilding controllers * Used stop building in header Stop button * Set the build controller in API performstreamingrequest * added setbuildcontroller to types
This commit is contained in:
parent
96872f3aa5
commit
882c35ef6b
4 changed files with 13 additions and 1 deletions
|
|
@ -50,6 +50,7 @@ export const MenuBar = ({}: {}): JSX.Element => {
|
||||||
const updatedAt = currentSavedFlow?.updated_at;
|
const updatedAt = currentSavedFlow?.updated_at;
|
||||||
const onFlowPage = useFlowStore((state) => state.onFlowPage);
|
const onFlowPage = useFlowStore((state) => state.onFlowPage);
|
||||||
const setCurrentFlow = useFlowsManagerStore((state) => state.setCurrentFlow);
|
const setCurrentFlow = useFlowsManagerStore((state) => state.setCurrentFlow);
|
||||||
|
const stopBuilding = useFlowStore((state) => state.stopBuilding);
|
||||||
|
|
||||||
const changesNotSaved =
|
const changesNotSaved =
|
||||||
customStringify(currentFlow) !== customStringify(currentSavedFlow) &&
|
customStringify(currentFlow) !== customStringify(currentSavedFlow) &&
|
||||||
|
|
@ -310,7 +311,7 @@ export const MenuBar = ({}: {}): JSX.Element => {
|
||||||
disabled={!isBuilding}
|
disabled={!isBuilding}
|
||||||
onClick={(_) => {
|
onClick={(_) => {
|
||||||
if (isBuilding) {
|
if (isBuilding) {
|
||||||
window.stop();
|
stopBuilding();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
className={
|
className={
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,7 @@ async function performStreamingRequest({
|
||||||
headers["Authorization"] = `Bearer ${accessToken}`;
|
headers["Authorization"] = `Bearer ${accessToken}`;
|
||||||
}
|
}
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
|
useFlowStore.getState().setBuildController(controller);
|
||||||
const params = {
|
const params = {
|
||||||
method: method,
|
method: method,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,9 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
nodes: [],
|
nodes: [],
|
||||||
edges: [],
|
edges: [],
|
||||||
isBuilding: false,
|
isBuilding: false,
|
||||||
|
stopBuilding: () => {
|
||||||
|
get().buildController.abort();
|
||||||
|
},
|
||||||
isPending: true,
|
isPending: true,
|
||||||
setHasIO: (hasIO) => {
|
setHasIO: (hasIO) => {
|
||||||
set({ hasIO });
|
set({ hasIO });
|
||||||
|
|
@ -766,6 +769,10 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
buildController: new AbortController(),
|
||||||
|
setBuildController: (controller) => {
|
||||||
|
set({ buildController: controller });
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export default useFlowStore;
|
export default useFlowStore;
|
||||||
|
|
|
||||||
|
|
@ -180,4 +180,7 @@ export type FlowStoreType = {
|
||||||
edges?: Edge[];
|
edges?: Edge[];
|
||||||
viewport?: Viewport;
|
viewport?: Viewport;
|
||||||
}) => void;
|
}) => void;
|
||||||
|
stopBuilding: () => void;
|
||||||
|
buildController: AbortController;
|
||||||
|
setBuildController: (controller: AbortController) => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue