Jon/sky 5820 make browser task block flippable with code (#3165)
This commit is contained in:
18
skyvern-frontend/src/store/BlockActionContext.ts
Normal file
18
skyvern-frontend/src/store/BlockActionContext.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { createContext } from "react";
|
||||
|
||||
type DeleteNodeCallback = (id: string) => void;
|
||||
type ToggleScriptForNodeCallback = (opts: {
|
||||
id?: string;
|
||||
label?: string;
|
||||
show: boolean;
|
||||
}) => void;
|
||||
|
||||
const BlockActionContext = createContext<
|
||||
| {
|
||||
deleteNodeCallback: DeleteNodeCallback;
|
||||
toggleScriptForNodeCallback?: ToggleScriptForNodeCallback;
|
||||
}
|
||||
| undefined
|
||||
>(undefined);
|
||||
|
||||
export { BlockActionContext };
|
||||
45
skyvern-frontend/src/store/BlockScriptStore.ts
Normal file
45
skyvern-frontend/src/store/BlockScriptStore.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* A store to hold the scripts for individual blocks in a workflow. As each
|
||||
* workflow has uniquely (and differently) labelled blocks, and those labels
|
||||
* are block identity, we'll eschew strong typing for this, and use a loose
|
||||
* object literal instead.
|
||||
*/
|
||||
|
||||
import { create } from "zustand";
|
||||
|
||||
interface BlockScriptStore {
|
||||
scriptId?: string;
|
||||
scripts: { [k: string]: string };
|
||||
// --
|
||||
setScript: (blockId: string, script: string) => void;
|
||||
setScripts: (scripts: { [k: string]: string }) => void;
|
||||
reset: () => void;
|
||||
}
|
||||
|
||||
const useBlockScriptStore = create<BlockScriptStore>((set) => {
|
||||
return {
|
||||
scriptId: undefined,
|
||||
scripts: {},
|
||||
// --
|
||||
setScript: (blockId: string, script: string) => {
|
||||
set((state) => ({
|
||||
scripts: {
|
||||
...state.scripts,
|
||||
[blockId]: script,
|
||||
},
|
||||
}));
|
||||
},
|
||||
setScripts: (scripts: { [k: string]: string }) => {
|
||||
set(() => ({
|
||||
scripts,
|
||||
}));
|
||||
},
|
||||
reset: () => {
|
||||
set({
|
||||
scripts: {},
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
export { useBlockScriptStore };
|
||||
@@ -1,9 +0,0 @@
|
||||
import { createContext } from "react";
|
||||
|
||||
type DeleteNodeCallback = (id: string) => void;
|
||||
|
||||
const DeleteNodeCallbackContext = createContext<DeleteNodeCallback | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
export { DeleteNodeCallbackContext };
|
||||
Reference in New Issue
Block a user