Skip to content

Commit bdd1f16

Browse files
mihaelabalutoiuDany9966
authored andcommitted
Add loading state to Export VM Inventory button
Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
1 parent da6fbce commit bdd1f16

3 files changed

Lines changed: 30 additions & 13 deletions

File tree

src/components/modules/EndpointModule/EndpointDetailsContent/EndpointDetailsContent.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { Region } from "@src/@types/Region";
2323
import EndpointLogos from "@src/components/modules/EndpointModule/EndpointLogos";
2424
import { ThemePalette, ThemeProps } from "@src/components/Theme";
2525
import Button from "@src/components/ui/Button";
26+
import LoadingButton from "@src/components/ui/LoadingButton";
2627
import CopyMultilineValue from "@src/components/ui/CopyMultilineValue";
2728
import CopyValue from "@src/components/ui/CopyValue";
2829
import PasswordValue from "@src/components/ui/PasswordValue";
@@ -100,6 +101,7 @@ type Props = {
100101
transfers: TransferItem[];
101102
connectionInfoSchema: FieldType[];
102103
supportsInventoryExport?: boolean;
104+
exportingInventoryCsv?: boolean;
103105
onDeleteClick: () => void;
104106
onValidateClick: () => void;
105107
onExportInventoryCsvClick?: () => void;
@@ -199,11 +201,14 @@ class EndpointDetailsContent extends React.Component<Props> {
199201
Validate Endpoint
200202
</Button>
201203
</MainButtons>
202-
{this.props.supportsInventoryExport && (
203-
<Button onClick={this.props.onExportInventoryCsvClick}>
204-
Export VM Inventory
205-
</Button>
206-
)}
204+
{this.props.supportsInventoryExport &&
205+
(this.props.exportingInventoryCsv ? (
206+
<LoadingButton>Export VM Inventory</LoadingButton>
207+
) : (
208+
<Button onClick={this.props.onExportInventoryCsvClick}>
209+
Export VM Inventory
210+
</Button>
211+
))}
207212
<DeleteButton>
208213
<Button hollow alert onClick={this.props.onDeleteClick}>
209214
Delete Endpoint

src/components/smart/EndpointDetailsPage/EndpointDetailsPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ class EndpointDetailsPage extends React.Component<Props, State> {
302302
action: () => {
303303
this.handleExportInventoryCsvClick();
304304
},
305+
loading: endpointStore.exportingInventoryCsv,
306+
disabled: endpointStore.exportingInventoryCsv,
305307
},
306308
]
307309
: []),
@@ -347,6 +349,7 @@ class EndpointDetailsPage extends React.Component<Props, State> {
347349
connectionInfo={endpointStore.connectionInfo}
348350
connectionInfoSchema={providerStore.connectionInfoSchema}
349351
supportsInventoryExport={this.supportsInventoryExport}
352+
exportingInventoryCsv={endpointStore.exportingInventoryCsv}
350353
onDeleteClick={() => {
351354
this.handleDeleteEndpointClick();
352355
}}

src/stores/EndpointStore.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class EndpointStore {
6666

6767
@observable multiValidation: MultiValidationItem[] = [];
6868

69+
@observable exportingInventoryCsv = false;
70+
6971
@action async getEndpoints(options?: {
7072
showLoading?: boolean;
7173
skipLog?: boolean;
@@ -199,14 +201,21 @@ class EndpointStore {
199201
}
200202

201203
@action async exportInventoryCsv(endpoint: Endpoint): Promise<void> {
202-
const csvContent = await EndpointSource.exportInventoryCsv(endpoint.id);
203-
const now = new Date();
204-
const pad = (n: number) => String(n).padStart(2, "0");
205-
const d =
206-
`${now.getFullYear()}-${pad(now.getMonth() + 1)}` +
207-
`-${pad(now.getDate())}_${pad(now.getHours())}` +
208-
`:${pad(now.getMinutes())}`;
209-
DomUtils.download(csvContent, `vm_inventory_${endpoint.name}_${d}.csv`);
204+
this.exportingInventoryCsv = true;
205+
try {
206+
const csvContent = await EndpointSource.exportInventoryCsv(endpoint.id);
207+
const now = new Date();
208+
const pad = (n: number) => String(n).padStart(2, "0");
209+
const d =
210+
`${now.getFullYear()}-${pad(now.getMonth() + 1)}` +
211+
`-${pad(now.getDate())}_${pad(now.getHours())}` +
212+
`:${pad(now.getMinutes())}`;
213+
DomUtils.download(csvContent, `vm_inventory_${endpoint.name}_${d}.csv`);
214+
} finally {
215+
runInAction(() => {
216+
this.exportingInventoryCsv = false;
217+
});
218+
}
210219
}
211220

212221
@action async exportToJson(endpoint: Endpoint): Promise<void> {

0 commit comments

Comments
 (0)