1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Drop waiting state on network or other error

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-08-02 10:45:46 +03:00
parent a7d7fa9c9a
commit c0d254a71e

View File

@ -6,13 +6,12 @@
import styles from "./download-logs-dropdown.module.scss"; import styles from "./download-logs-dropdown.module.scss";
import React, { useState } from "react"; import React, { useState } from "react";
import { cssNames } from "../../../utils";
import { Icon } from "../../icon"; import { Icon } from "../../icon";
import { Menu, MenuItem } from "../../menu"; import { Menu, MenuItem } from "../../menu";
interface DownloadLogsDropdownProps { interface DownloadLogsDropdownProps {
downloadVisibleLogs: () => Promise<boolean> downloadVisibleLogs: () => Promise<any>
downloadAllLogs: () => Promise<boolean> downloadAllLogs: () => Promise<any>
} }
export function DownloadLogsDropdown({ downloadAllLogs, downloadVisibleLogs }: DownloadLogsDropdownProps) { export function DownloadLogsDropdown({ downloadAllLogs, downloadVisibleLogs }: DownloadLogsDropdownProps) {
@ -23,18 +22,22 @@ export function DownloadLogsDropdown({ downloadAllLogs, downloadVisibleLogs }: D
setOpened(!opened); setOpened(!opened);
}; };
const downloadLogs = async (download: () => Promise<boolean>) => { const downloadLogs = async (download: () => Promise<void>) => {
setWaiting(true); setWaiting(true);
try {
await download(); await download();
} finally {
setWaiting(false); setWaiting(false);
} }
}
return ( return (
<> <>
<button <button
data-testid="download-logs-dropdown" data-testid="download-logs-dropdown"
id="download-logs-dropdown" id="download-logs-dropdown"
className={cssNames(styles.dropdown, { [styles.waiting]: waiting })} className={styles.dropdown}
disabled={waiting}
> >
Download Download
<Icon material="arrow_drop_down" smallest/> <Icon material="arrow_drop_down" smallest/>