Skip to content

Commit c56d735

Browse files
Wire VM inventory CSV export into endpoint details UI
Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
1 parent bbe7320 commit c56d735

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ type Props = {
9999
loading: boolean;
100100
transfers: TransferItem[];
101101
connectionInfoSchema: FieldType[];
102+
supportsInventoryExport?: boolean;
102103
onDeleteClick: () => void;
103104
onValidateClick: () => void;
105+
onExportInventoryCsvClick?: () => void;
104106
};
105107
@observer
106108
class EndpointDetailsContent extends React.Component<Props> {
@@ -197,6 +199,11 @@ class EndpointDetailsContent extends React.Component<Props> {
197199
Validate Endpoint
198200
</Button>
199201
</MainButtons>
202+
{this.props.supportsInventoryExport && (
203+
<Button onClick={this.props.onExportInventoryCsvClick}>
204+
Export VM Inventory
205+
</Button>
206+
)}
200207
<DeleteButton>
201208
<Button hollow alert onClick={this.props.onDeleteClick}>
202209
Delete Endpoint

src/components/smart/EndpointDetailsPage/EndpointDetailsPage.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import projectStore from "@src/stores/ProjectStore";
3636
import type { Endpoint as EndpointType } from "@src/@types/Endpoint";
3737

3838
import { ThemePalette } from "@src/components/Theme";
39+
import { providerTypes } from "@src/constants";
3940

4041
import regionStore from "@src/stores/RegionStore";
4142
import { DeploymentItem, TransferItem } from "@src/@types/MainItem";
@@ -227,12 +228,32 @@ class EndpointDetailsPage extends React.Component<Props, State> {
227228
this.setState({ endpointUsage: this.getEndpointUsage() });
228229
}
229230

231+
handleExportInventoryCsvClick() {
232+
if (!this.endpoint) {
233+
return;
234+
}
235+
endpointStore.exportInventoryCsv(this.endpoint);
236+
}
237+
238+
get supportsInventoryExport(): boolean {
239+
const endpoint = this.endpoint;
240+
if (!endpoint || !providerStore.providers) {
241+
return false;
242+
}
243+
return Boolean(
244+
providerStore.providers[endpoint.type]?.types.includes(
245+
providerTypes.INVENTORY_EXPORT,
246+
),
247+
);
248+
}
249+
230250
async loadEndpoints() {
231251
await endpointStore.getEndpoints();
232252
const endpoint = this.endpoint;
233253

234254
if (endpoint?.type) {
235255
providerStore.getConnectionInfoSchema(endpoint.type);
256+
providerStore.loadProviders();
236257
}
237258

238259
if (endpoint?.connection_info?.secret_ref) {
@@ -274,6 +295,16 @@ class EndpointDetailsPage extends React.Component<Props, State> {
274295
this.handleExportToJsonClick();
275296
},
276297
},
298+
...(this.supportsInventoryExport
299+
? [
300+
{
301+
label: "Export VM Inventory",
302+
action: () => {
303+
this.handleExportInventoryCsvClick();
304+
},
305+
},
306+
]
307+
: []),
277308
{
278309
label: "Delete Endpoint",
279310
color: ThemePalette.alert,
@@ -315,12 +346,16 @@ class EndpointDetailsPage extends React.Component<Props, State> {
315346
}
316347
connectionInfo={endpointStore.connectionInfo}
317348
connectionInfoSchema={providerStore.connectionInfoSchema}
349+
supportsInventoryExport={this.supportsInventoryExport}
318350
onDeleteClick={() => {
319351
this.handleDeleteEndpointClick();
320352
}}
321353
onValidateClick={() => {
322354
this.handleValidateClick();
323355
}}
356+
onExportInventoryCsvClick={() => {
357+
this.handleExportInventoryCsvClick();
358+
}}
324359
/>
325360
}
326361
/>

0 commit comments

Comments
 (0)