Jon/sky 5820 make browser task block flippable with code (#3165)
This commit is contained in:
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 };
|
||||
Reference in New Issue
Block a user