Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add role select storybook
  • Loading branch information
BrunoQuaresma committed May 10, 2022
commit 82a60f81575b1326391a835a6a4a7c0f0b51f5ff
67 changes: 67 additions & 0 deletions site/src/components/UsersTable/RoleSelect.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { ComponentMeta, Story } from "@storybook/react"
import React from "react"
import { RoleSelect, RoleSelectProps } from "./RoleSelect"

export default {
title: "components/RoleSelect",
component: RoleSelect,
} as ComponentMeta<typeof RoleSelect>

const Template: Story<RoleSelectProps> = (args) => <RoleSelect {...args} />

export const Close = Template.bind({})
Close.args = {
roles: [
{
name: "admin",
display_name: "Admin",
},
{
name: "auditor",
display_name: "Auditor",
},
{
name: "member",
display_name: "Member",
},
],
selectedRoles: [
{
name: "admin",
display_name: "Admin",
},
{
name: "member",
display_name: "Member",
},
],
}

export const Open = Template.bind({})
Open.args = {
open: true,
roles: [
{
name: "admin",
display_name: "Admin",
},
{
name: "auditor",
display_name: "Auditor",
},
{
name: "member",
display_name: "Member",
},
],
selectedRoles: [
{
name: "admin",
display_name: "Admin",
},
{
name: "member",
display_name: "Member",
},
],
}
4 changes: 3 additions & 1 deletion site/src/components/UsersTable/RoleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ export interface RoleSelectProps {
selectedRoles: Role[]
onChange: (roles: Role["name"][]) => void
loading?: boolean
open?: boolean
}

export const RoleSelect: React.FC<RoleSelectProps> = ({ roles, selectedRoles, loading, onChange }) => {
export const RoleSelect: React.FC<RoleSelectProps> = ({ roles, selectedRoles, loading, onChange, open }) => {
const styles = useStyles()
const value = selectedRoles.map((r) => r.name)
const renderValue = () => selectedRoles.map((r) => r.display_name).join(", ")
const sortedRoles = roles.sort((a, b) => a.display_name.localeCompare(b.display_name))

return (
<Select
open={open}
multiple
value={value}
renderValue={renderValue}
Expand Down