-
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.
Signed-off-by: David Edler <[email protected]>
- Loading branch information
Showing
19 changed files
with
904 additions
and
215 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
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,97 @@ | ||
import { FC, ReactNode, useState } from "react"; | ||
import { Button, Icon, MainTable, Select } from "@canonical/react-components"; | ||
import ResourceLabel from "components/ResourceLabel"; | ||
|
||
export type ClusterSpecificSelectField = Record<string, string>; | ||
|
||
interface Props { | ||
readOnly: boolean; | ||
options: { | ||
memberName: string; | ||
values: string[]; | ||
}[]; | ||
valueSuffix?: ReactNode; | ||
values?: ClusterSpecificSelectField; | ||
onChange: (value: ClusterSpecificSelectField) => void; | ||
} | ||
|
||
const ClusterSpecificSelect: FC<Props> = ({ | ||
readOnly, | ||
options, | ||
valueSuffix, | ||
values, | ||
onChange, | ||
}) => { | ||
const [isExpanded, setExpanded] = useState(false); | ||
|
||
return isExpanded ? ( | ||
<> | ||
<Button onClick={() => setExpanded(false)} hasIcon appearance="base"> | ||
<Icon name="collapse" /> | ||
</Button>{" "} | ||
<MainTable | ||
style={{ width: "auto", display: "inline" }} | ||
headers={[{ content: "Cluster member" }, { content: "Value" }]} | ||
rows={options.map((item) => { | ||
const activeValue = values?.[item.memberName]; | ||
const options = item.values.map((value) => { | ||
return { | ||
label: value, | ||
value: value, | ||
}; | ||
}); | ||
options.unshift({ | ||
label: options.length === 0 ? "None available" : "Select option", | ||
value: "", | ||
}); | ||
|
||
return { | ||
columns: [ | ||
{ | ||
content: ( | ||
<ResourceLabel | ||
type="cluster-member" | ||
value={item.memberName} | ||
/> | ||
), | ||
role: "cell", | ||
"aria-label": "Cluster member", | ||
}, | ||
{ | ||
content: readOnly ? ( | ||
<> | ||
{activeValue} | ||
{valueSuffix} | ||
</> | ||
) : ( | ||
<Select | ||
className="u-no-margin--bottom" | ||
options={options} | ||
onChange={(e) => { | ||
onChange({ | ||
...values, | ||
[item.memberName]: e.target.value, | ||
}); | ||
}} | ||
value={activeValue} | ||
/> | ||
), | ||
role: "cell", | ||
"aria-label": "Value", | ||
}, | ||
], | ||
}; | ||
})} | ||
/> | ||
</> | ||
) : ( | ||
<div> | ||
<Button onClick={() => setExpanded(true)} hasIcon appearance="base"> | ||
<Icon name="expand" /> | ||
<span>specific values per cluster member</span> | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ClusterSpecificSelect; |
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.