From e7f7ba34252098788e2ff60e7d97068620876b35 Mon Sep 17 00:00:00 2001 From: TRIGUBF Date: Fri, 25 Aug 2023 12:05:02 +0200 Subject: [PATCH] track async download state, disable button while downloading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../DryRunResults/DryRunResultsList.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsList.tsx b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsList.tsx index 0d9fcbc350..2d7f78ac54 100644 --- a/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsList.tsx +++ b/plugins/scaffolder/src/components/TemplateEditorPage/DryRunResults/DryRunResultsList.tsx @@ -55,6 +55,14 @@ export function DryRunResultsList() { {dryRun.results.map(result => { const failed = result.log.some(l => l.body.status === 'failed'); + let isLoading = false; + + async function downloadResult() { + isLoading = true; + await downloadDirectoryContents(result.directoryContents, `dry-run-result-${result.id}.zip`) + isLoading = false; + } + return ( downloadResult(result)} + disabled={isLoading} + onClick={() => downloadResult()} > @@ -94,12 +103,8 @@ export function DryRunResultsList() { } -async function downloadResult(result: DryRunResult) { - await createZipDownload(result.directoryContents, `dry-run-result-${result.id}.zip`) -} - -async function createZipDownload(directoryContents: { path: string; base64Content: string; executable: boolean; }[], name: string) { +async function downloadDirectoryContents(directoryContents: { path: string; base64Content: string; executable: boolean; }[], name: string) { const {default: JSZip} = await import('jszip'); const zip = new JSZip();