({
currentScript,
collections,
dispatchCurrentScript,
dispatchCollections,
forceSetScriptResult,
}: ScriptPanelProps)
| 71 | }; |
| 72 | |
| 73 | function ScriptPanel({ |
| 74 | currentScript, |
| 75 | collections, |
| 76 | dispatchCurrentScript, |
| 77 | dispatchCollections, |
| 78 | forceSetScriptResult, |
| 79 | }: ScriptPanelProps) { |
| 80 | const { colorMode } = useColorMode(); |
| 81 | const toast = useToast(); |
| 82 | const [isRunning, setIsRunning] = useState(false); |
| 83 | |
| 84 | const envNames = useMemo(() => { |
| 85 | const collection = findCollection(collections, currentScript.collectionId); |
| 86 | if (!collection) return []; |
| 87 | return Object.keys(collection.data?.envs ?? {}); |
| 88 | }, [collections, currentScript.collectionId]); |
| 89 | |
| 90 | const setName = useCallback( |
| 91 | (name: string) => { |
| 92 | dispatchCurrentScript({ |
| 93 | type: CurrentScriptActionType.PATCH_DATA, |
| 94 | data: { name }, |
| 95 | }); |
| 96 | }, |
| 97 | [dispatchCurrentScript], |
| 98 | ); |
| 99 | |
| 100 | const setDescription = useCallback( |
| 101 | (description: string) => { |
| 102 | dispatchCurrentScript({ |
| 103 | type: CurrentScriptActionType.PATCH_DATA, |
| 104 | data: { description }, |
| 105 | }); |
| 106 | }, |
| 107 | [dispatchCurrentScript], |
| 108 | ); |
| 109 | |
| 110 | const handleRunClick = useCallback(async () => { |
| 111 | try { |
| 112 | if (isRunning) return; |
| 113 | setIsRunning(true); |
| 114 | const envName = currentScript.data.selectedEnvName; |
| 115 | const res = await api.runScript(currentScript, envName); |
| 116 | if (res.status !== 200) throw new Error(); |
| 117 | const newResult = await res.json(); |
| 118 | dispatchCurrentScript({ |
| 119 | type: CurrentScriptActionType.PATCH_DATA, |
| 120 | data: { results: [newResult, ...(currentScript.data.results ?? [])] }, |
| 121 | }); |
| 122 | dispatchCollections({ |
| 123 | type: CollectionsActionType.PATCH_SCRIPT_DATA, |
| 124 | id: currentScript.id, |
| 125 | data: { results: [newResult, ...(currentScript.data.results ?? [])] }, |
| 126 | }); |
| 127 | if (forceSetScriptResult.current) { |
| 128 | forceSetScriptResult.current(newResult); |
| 129 | } |
| 130 | successToast('Run finished', toast); |
nothing calls this directly
no test coverage detected