-
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… (
#968) …ail page. Work done (So far): - 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 ProfileNetworkList still exists for the ProfileDetailPanelContent component. - Create a generic DeviceListTable file to generate a device list for instance and profile overview pages. Fixes [list issues/bugs if needed] ## QA 1. Run the LXD-UI: - On the demo server via the link posted by @webteam-app below. This is only available for PRs created by collaborators of the repo. Ask @mas-who or @edlerd for access. - With a local copy of this branch, [build and run as described in the docs](../CONTRIBUTING.md#setting-up-for-development). 2. Perform the following QA steps: - [List the steps to QA the new feature(s) or prove that a bug has been resolved] ## Screenshots ![image](https://github.com/user-attachments/assets/bf25d3a4-01bd-46d8-ad2c-533d3df7948a) ![image](https://github.com/user-attachments/assets/44f52f71-cff7-4531-843f-a0c4cfc80cf0)
- 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.