-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add resource link and label components [WD-15623] (#952)
## Done - Added `ResourceLink` component for displaying lxd resources that have valid UI link - Added `ResourceLabel` component for displaying lxd resources that does not have valid UI link
- Loading branch information
Showing
5 changed files
with
133 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Icon } from "@canonical/react-components"; | ||
import { FC } from "react"; | ||
|
||
export type ResourceIconType = | ||
| "container" | ||
| "virtual-machine" | ||
| "snapshot" | ||
| "profile" | ||
| "project" | ||
| "cluster-member" | ||
| "network" | ||
| "pool" | ||
| "volume" | ||
| "iso-volume" | ||
| "image" | ||
| "oidc-identity" | ||
| "certificate" | ||
| "auth-group" | ||
| "device"; | ||
|
||
const resourceIcons: Record<ResourceIconType, string> = { | ||
container: "pods", | ||
"virtual-machine": "pods", | ||
snapshot: "snapshot", | ||
profile: "repository", | ||
project: "folder", | ||
"cluster-member": "single-host", | ||
network: "exposed", | ||
pool: "status-queued-small", | ||
volume: "status-queued-small", | ||
"iso-volume": "iso", | ||
image: "image", | ||
"oidc-identity": "user", | ||
certificate: "certificate", | ||
"auth-group": "user-group", | ||
device: "units", | ||
}; | ||
|
||
interface Props { | ||
type: ResourceIconType; | ||
} | ||
|
||
const ResourceIcon: FC<Props> = ({ type }) => { | ||
return <Icon name={resourceIcons[type]} />; | ||
}; | ||
|
||
export default ResourceIcon; |
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,20 @@ | ||
import { FC } from "react"; | ||
import ResourceIcon, { ResourceIconType } from "./ResourceIcon"; | ||
|
||
interface Props { | ||
type: ResourceIconType; | ||
value: string; | ||
bold?: boolean; | ||
} | ||
|
||
const ResourceLabel: FC<Props> = ({ type, value, bold }) => { | ||
const ValueWrapper = bold ? "strong" : "span"; | ||
return ( | ||
<span className="resource-label u-truncate"> | ||
<ResourceIcon type={type} /> | ||
<ValueWrapper>{value}</ValueWrapper> | ||
</span> | ||
); | ||
}; | ||
|
||
export default ResourceLabel; |
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,26 @@ | ||
import { FC } from "react"; | ||
import { Link } from "react-router-dom"; | ||
import ResourceIcon, { ResourceIconType } from "./ResourceIcon"; | ||
|
||
interface Props { | ||
type: ResourceIconType; | ||
value: string; | ||
to: string; | ||
} | ||
|
||
const ResourceLink: FC<Props> = ({ type, value, to }) => { | ||
return ( | ||
<Link | ||
className="p-chip is-inline is-dense resource-link" | ||
to={to} | ||
title={value} | ||
> | ||
<span className="p-chip__value"> | ||
<ResourceIcon type={type} /> | ||
{value} | ||
</span> | ||
</Link> | ||
); | ||
}; | ||
|
||
export default ResourceLink; |
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,25 @@ | ||
.resource-link { | ||
i { | ||
margin-right: $sph--x-small; | ||
} | ||
|
||
&.p-chip { | ||
// background-color is set to white by vanilla if p-chip is applied to a link and not button | ||
background-color: $colors--theme--background-neutral-default; | ||
border: none; | ||
} | ||
|
||
.p-chip__value { | ||
max-width: 8rem; | ||
} | ||
} | ||
|
||
.resource-label { | ||
// align font size with chip component | ||
font-size: #{map-get($font-sizes, small)}rem; | ||
line-height: #{map-get($line-heights, small)}rem; | ||
|
||
i { | ||
margin-right: $sph--x-small; | ||
} | ||
} |
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