-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathstoragePoolOverviewTab.tsx
More file actions
116 lines (96 loc) · 5.56 KB
/
Copy pathstoragePoolOverviewTab.tsx
File metadata and controls
116 lines (96 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* Copyright (C) 2018 Red Hat, Inc.
*/
import React, { useEffect, useState } from 'react';
import type { StoragePool } from '../../types';
import { DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm } from "@patternfly/react-core/dist/esm/components/DescriptionList";
import { Switch } from "@patternfly/react-core/dist/esm/components/Switch";
import { storagePoolId } from '../../helpers.js';
import { getInstallMediaPools, setInstallMediaPool } from '../../libvirtApi/installMediaPools.js';
import cockpit from 'cockpit';
const _ = cockpit.gettext;
// Pool types whose target is a plain host directory that can hold ISO images.
const INSTALL_MEDIA_POOL_TYPES = ['dir', 'netfs'];
const InstallMediaSwitch = ({ storagePool, idPrefix } : { storagePool: StoragePool, idPrefix: string }) => {
// null while the on-disk config is still loading, so the Switch stays disabled
const [enabled, setEnabled] = useState<boolean | null>(null);
const { connectionName, uuid } = storagePool;
useEffect(() => {
let active = true;
getInstallMediaPools(connectionName).then(pools => {
if (active)
setEnabled(!!uuid && pools.includes(uuid));
});
return () => { active = false };
}, [connectionName, uuid]);
const onChange = (_event: React.FormEvent, checked: boolean) => {
if (!uuid)
return;
// optimistic update; revert if the write fails
setEnabled(checked);
setInstallMediaPool(connectionName, uuid, checked).catch(ex => {
console.warn("Could not update installation-media pool config:", String(ex));
setEnabled(!checked);
});
};
return (
<Switch id={`${idPrefix}-install-media-switch`}
label={_("Use for installation media")}
isChecked={!!enabled}
isDisabled={enabled === null || !uuid}
onChange={onChange} />
);
};
export const StoragePoolOverviewTab = ({ storagePool } : { storagePool: StoragePool }) => {
const idPrefix = `${storagePoolId(storagePool.name, storagePool.connectionName)}`;
return (
<DescriptionList isHorizontal>
{ storagePool.source && storagePool.source.host && <DescriptionListGroup>
<DescriptionListTerm> {_("Host")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-host`}>
{storagePool.source.host.name}
</DescriptionListDescription>
</DescriptionListGroup> }
{ storagePool.source && storagePool.source.device && <DescriptionListGroup>
<DescriptionListTerm> {_("Source path")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-source-path`}> {storagePool.source.device.path} </DescriptionListDescription>
</DescriptionListGroup> }
{ storagePool.source && storagePool.source.dir && <DescriptionListGroup>
<DescriptionListTerm> {_("Source path")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-source-path`}> {storagePool.source.dir.path} </DescriptionListDescription>
</DescriptionListGroup> }
{ storagePool.source && storagePool.source.name && <DescriptionListGroup>
<DescriptionListTerm> {_("Source")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-source-path`}> {storagePool.source.name} </DescriptionListDescription>
</DescriptionListGroup> }
{ storagePool.source && storagePool.source.format && <DescriptionListGroup>
<DescriptionListTerm> {_("Source format")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-source-format`}> {storagePool.source.format.type} </DescriptionListDescription>
</DescriptionListGroup> }
{ storagePool.target && storagePool.target.path && <DescriptionListGroup>
<DescriptionListTerm> {_("Target path")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-target-path`}> {storagePool.target.path} </DescriptionListDescription>
</DescriptionListGroup> }
<DescriptionListGroup>
<DescriptionListTerm> {_("Persistent")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-persistent`}> {storagePool.persistent ? _("yes") : _("no")} </DescriptionListDescription>
</DescriptionListGroup>
{storagePool.persistent && <DescriptionListGroup>
<DescriptionListTerm> {_("Autostart")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-autostart`}> {storagePool.autostart ? _("yes") : _("no")} </DescriptionListDescription>
</DescriptionListGroup>}
<DescriptionListGroup>
<DescriptionListTerm> {_("Type")} </DescriptionListTerm>
<DescriptionListDescription id={`${idPrefix}-type`}> {storagePool.type} </DescriptionListDescription>
</DescriptionListGroup>
{INSTALL_MEDIA_POOL_TYPES.includes(storagePool.type) && storagePool.uuid && <DescriptionListGroup>
<DescriptionListTerm> {_("Installation media")} </DescriptionListTerm>
<DescriptionListDescription>
<InstallMediaSwitch storagePool={storagePool} idPrefix={idPrefix} />
</DescriptionListDescription>
</DescriptionListGroup>}
</DescriptionList>
);
};