Skip to content

feat(site): Read users into basic UsersTable #981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 14, 2022
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 UsersPageView
  • Loading branch information
presleyp committed Apr 12, 2022
commit ca729e90a6dbd9cbe7edb471d7fa119b8647cee9
38 changes: 8 additions & 30 deletions site/src/components/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { makeStyles } from "@material-ui/styles"
import React from "react"
import { Pager, UserResponse } from "../../api/types"
import { UserResponse } from "../../api/types"
import { Column, Table } from "../../components/Table"
import { EmptyState } from "../EmptyState"
import { Header } from "../Header"
import { UserCell } from "../Table/Cells/UserCell"

const Language = {
pageTitle: "Users",
usersTitle: "All users",
emptyMessage: "No users found",
usernameLabel: "User",
siteRoleLabel: "Site Role"
}

const emptyState = (
Expand All @@ -28,38 +25,19 @@ const columns: Column<UserResponse>[] = [
return <UserCell Avatar={{ username: data.email }} primaryText={data.email} />
},
},
{
key: "siteRole",
name: Language.siteRoleLabel
}
]

export interface UsersTableProps {
users: UserResponse[]
pager?: Pager
}

export const UsersTable: React.FC<UsersTableProps> = ({ users, pager }) => {
const styles = useStyles()
export const UsersTable: React.FC<UsersTableProps> = ({ users }) => {
return (
<div className={styles.flexColumn}>
<Header
title={Language.pageTitle}
subTitle={`${pager?.total} total`}
/>
<Table
columns={columns}
data={users}
title={Language.usersTitle}
emptyState={emptyState}
/>
</div>
<Table
columns={columns}
data={users}
title={Language.usersTitle}
emptyState={emptyState}
/>
)
}

const useStyles = makeStyles(() => ({
flexColumn: {
display: "flex",
flexDirection: "column"
}
}))
3 changes: 2 additions & 1 deletion site/src/pages/UsersPage/UsersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useContext } from "react"
import { ErrorSummary } from "../../components/ErrorSummary"
import { UsersTable } from "../../components/UsersTable/UsersTable"
import { XServiceContext } from "../../xServices/StateContext"
import { UsersPageView } from "./UsersPageView"

export const UsersPage: React.FC = () => {
const xServices = useContext(XServiceContext)
Expand All @@ -12,6 +13,6 @@ export const UsersPage: React.FC = () => {
if (usersState.matches("error")) {
return <ErrorSummary error={getUsersError} />
} else {
return <UsersTable users={users} pager={pager} />
return <UsersPageView users={users} pager={pager} />
}
}
30 changes: 30 additions & 0 deletions site/src/pages/UsersPage/UsersPageView.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ComponentMeta, Story } from "@storybook/react"
import React from "react"
import { MockUser, MockUser2 } from "../../test_helpers"
import { UsersPageView, UsersPageViewProps } from "./UsersPageView"

export default {
title: "pages/UsersPageView",
component: UsersPageView,
} as ComponentMeta<typeof UsersPageView>

const Template: Story<UsersPageViewProps> = (args) => <UsersPageView {...args} />

export const Ready = Template.bind({})
Ready.args = {
users: [
MockUser,
MockUser2
],
pager: {
total: 2,
after: "123",
before: "456",
limit: 10
}
}
export const Loading = Template.bind({})
Loading.args = {
users: [
]
}
34 changes: 34 additions & 0 deletions site/src/pages/UsersPage/UsersPageView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { makeStyles } from "@material-ui/styles"
import React from "react"
import { UserResponse, Pager } from "../../api/types"
import { Header } from "../../components/Header"
import { UsersTable } from "../../components/UsersTable/UsersTable"

const Language = {
pageTitle: "Users",
}

export interface UsersPageViewProps {
users: UserResponse[]
pager?: Pager
}

export const UsersPageView: React.FC<UsersPageViewProps> = ({ users, pager }) => {
const styles = useStyles()
return (
<div className={styles.flexColumn}>
<Header
title={Language.pageTitle}
subTitle={pager ? `${pager.total} total`: ''}
/>
<UsersTable users={users} />
</div>
)
}

const useStyles = makeStyles(() => ({
flexColumn: {
display: "flex",
flexDirection: "column"
}
}))