-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [WD-16007] Replace storage list with device list on profile det…
…ail page. Work done: - Separate Devices section into Networks and Other devices (Currently storage) - Created a generic NetworkListTable file to generate a network list for instance and profile overview pages. - Note, the file ProfilNetworkList still exists for the ProfileDetailPanelContent component. Signed-off-by: Nkeiruka <[email protected]>
- Loading branch information
Showing
12 changed files
with
201 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { FC } from "react"; | ||
import { MainTable } from "@canonical/react-components"; | ||
import { isRootDisk } from "util/instanceValidation"; | ||
import { FormDevice } from "util/formDevices"; | ||
import ResourceLink from "components/ResourceLink"; | ||
import { isOtherDevice } from "util/devices"; | ||
import DeviceDetails from "./DeviceDetails"; | ||
import { useParams } from "react-router-dom"; | ||
import { LxdDeviceValue, LxdDevices } from "types/device"; | ||
|
||
interface Props { | ||
configBaseURL: string; | ||
devices: LxdDevices; | ||
} | ||
|
||
const DeviceListTable: FC<Props> = ({ configBaseURL, devices }) => { | ||
const { project } = useParams<{ project: string }>(); | ||
|
||
const byTypeAndName = ( | ||
a: [string, LxdDeviceValue], | ||
b: [string, LxdDeviceValue], | ||
) => { | ||
const nameA = a[0].toLowerCase(); | ||
const nameB = b[0].toLowerCase(); | ||
const typeA = a[1].type; | ||
const typeB = b[1].type; | ||
if (typeA === typeB) { | ||
return nameA.localeCompare(nameB); | ||
} | ||
|
||
return typeA.localeCompare(typeB); | ||
}; | ||
|
||
// Identify non-NIC devices | ||
const overviewDevices = Object.entries(devices ?? {}) | ||
.filter(([_key, device]) => { | ||
return device.type !== "nic" && device.type !== "none"; | ||
}) | ||
.sort(byTypeAndName); | ||
|
||
const hasDevices = overviewDevices.length > 0; | ||
|
||
const deviceHeaders = [ | ||
{ content: "Name", sortKey: "name", className: "u-text--muted" }, | ||
{ content: "Type", sortKey: "type", className: "u-text--muted" }, | ||
{ content: "Details", className: "u-text--muted" }, | ||
]; | ||
|
||
const deviceRows = overviewDevices.map(([devicename, device]) => { | ||
return { | ||
columns: [ | ||
{ | ||
content: ( | ||
<ResourceLink | ||
type="device" | ||
value={devicename} | ||
to={`${configBaseURL}/${isOtherDevice(device) ? "other" : device.type}`} | ||
/> | ||
), | ||
role: "cell", | ||
"aria-label": "Name", | ||
}, | ||
{ | ||
content: `${device.type} ${isRootDisk(device as FormDevice) ? "(root)" : ""}`, | ||
|
||
role: "cell", | ||
"aria-label": "Type", | ||
}, | ||
{ | ||
content: ( | ||
<DeviceDetails device={device} project={project as string} /> | ||
), | ||
role: "cell", | ||
"aria-label": "Details", | ||
}, | ||
], | ||
sortData: { | ||
name: devicename.toLowerCase(), | ||
type: device.type, | ||
}, | ||
}; | ||
}); | ||
|
||
return ( | ||
<> | ||
{hasDevices && ( | ||
<MainTable | ||
headers={deviceHeaders} | ||
rows={deviceRows} | ||
className={"device-table"} | ||
sortable | ||
/> | ||
)} | ||
{!hasDevices && <>-</>} | ||
</> | ||
); | ||
}; | ||
|
||
export default DeviceListTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.device-table { | ||
th:nth-child(1) { | ||
width: 30%; | ||
} | ||
|
||
th:first-of-type, | ||
td:first-of-type { | ||
padding-left: 0; | ||
} | ||
|
||
th:nth-child(2), | ||
td:nth-child(2) { | ||
width: 12rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.