Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Region } from "@src/@types/Region";
import EndpointLogos from "@src/components/modules/EndpointModule/EndpointLogos";
import { ThemePalette, ThemeProps } from "@src/components/Theme";
import Button from "@src/components/ui/Button";
import LoadingButton from "@src/components/ui/LoadingButton";
import CopyMultilineValue from "@src/components/ui/CopyMultilineValue";
import CopyValue from "@src/components/ui/CopyValue";
import PasswordValue from "@src/components/ui/PasswordValue";
Expand Down Expand Up @@ -100,6 +101,7 @@ type Props = {
transfers: TransferItem[];
connectionInfoSchema: FieldType[];
supportsInventoryExport?: boolean;
exportingInventoryCsv?: boolean;
onDeleteClick: () => void;
onValidateClick: () => void;
onExportInventoryCsvClick?: () => void;
Expand Down Expand Up @@ -199,11 +201,14 @@ class EndpointDetailsContent extends React.Component<Props> {
Validate Endpoint
</Button>
</MainButtons>
{this.props.supportsInventoryExport && (
<Button onClick={this.props.onExportInventoryCsvClick}>
Export VM Inventory
</Button>
)}
{this.props.supportsInventoryExport &&
(this.props.exportingInventoryCsv ? (
<LoadingButton>Export VM Inventory</LoadingButton>
) : (
<Button onClick={this.props.onExportInventoryCsvClick}>
Export VM Inventory
</Button>
))}
<DeleteButton>
<Button hollow alert onClick={this.props.onDeleteClick}>
Delete Endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ class EndpointDetailsPage extends React.Component<Props, State> {
action: () => {
this.handleExportInventoryCsvClick();
},
loading: endpointStore.exportingInventoryCsv,
disabled: endpointStore.exportingInventoryCsv,
},
]
: []),
Expand Down Expand Up @@ -347,6 +349,7 @@ class EndpointDetailsPage extends React.Component<Props, State> {
connectionInfo={endpointStore.connectionInfo}
connectionInfoSchema={providerStore.connectionInfoSchema}
supportsInventoryExport={this.supportsInventoryExport}
exportingInventoryCsv={endpointStore.exportingInventoryCsv}
onDeleteClick={() => {
this.handleDeleteEndpointClick();
}}
Expand Down
25 changes: 17 additions & 8 deletions src/stores/EndpointStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class EndpointStore {

@observable multiValidation: MultiValidationItem[] = [];

@observable exportingInventoryCsv = false;

@action async getEndpoints(options?: {
showLoading?: boolean;
skipLog?: boolean;
Expand Down Expand Up @@ -199,14 +201,21 @@ class EndpointStore {
}

@action async exportInventoryCsv(endpoint: Endpoint): Promise<void> {
const csvContent = await EndpointSource.exportInventoryCsv(endpoint.id);
const now = new Date();
const pad = (n: number) => String(n).padStart(2, "0");
const d =
`${now.getFullYear()}-${pad(now.getMonth() + 1)}` +
`-${pad(now.getDate())}_${pad(now.getHours())}` +
`:${pad(now.getMinutes())}`;
DomUtils.download(csvContent, `vm_inventory_${endpoint.name}_${d}.csv`);
this.exportingInventoryCsv = true;
try {
const csvContent = await EndpointSource.exportInventoryCsv(endpoint.id);
const now = new Date();
const pad = (n: number) => String(n).padStart(2, "0");
const d =
`${now.getFullYear()}-${pad(now.getMonth() + 1)}` +
`-${pad(now.getDate())}_${pad(now.getHours())}` +
`:${pad(now.getMinutes())}`;
DomUtils.download(csvContent, `vm_inventory_${endpoint.name}_${d}.csv`);
} finally {
runInAction(() => {
this.exportingInventoryCsv = false;
});
}
}

@action async exportToJson(endpoint: Endpoint): Promise<void> {
Expand Down
Loading