Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb3bdc36

Browse files
committed
Add workspaces table
1 parent6b37868 commitb3bdc36

File tree

4 files changed

+109
-61
lines changed

4 files changed

+109
-61
lines changed

‎site/src/components/NavbarView/NavbarView.stories.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import{Story}from"@storybook/react"
22
importReactfrom"react"
3+
import{MockUser,MockUser2}from"../../testHelpers/entities"
34
import{NavbarView,NavbarViewProps}from"./NavbarView"
45

56
exportdefault{
@@ -14,15 +15,15 @@ const Template: Story<NavbarViewProps> = (args: NavbarViewProps) => <NavbarView
1415

1516
exportconstForAdmin=Template.bind({})
1617
ForAdmin.args={
17-
user:{id:"1",username:"Administrator",email:"admin@coder.com",created_at:"dawn"},
18+
user:MockUser,
1819
onSignOut:()=>{
1920
returnPromise.resolve()
2021
},
2122
}
2223

2324
exportconstForMember=Template.bind({})
2425
ForMember.args={
25-
user:{id:"1",username:"CathyCoder",email:"cathy@coder.com",created_at:"dawn"},
26+
user:MockUser2,
2627
onSignOut:()=>{
2728
returnPromise.resolve()
2829
},
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import{ComponentMeta,Story}from"@storybook/react"
2+
importReactfrom"react"
3+
import{MockTemplate,MockWorkspace}from"../../testHelpers/entities"
4+
import{WorkspacesTable,WorkspacesTableProps}from"./WorkspacesTable"
5+
6+
exportdefault{
7+
title:"components/WorkspacesTable",
8+
component:WorkspacesTable,
9+
}asComponentMeta<typeofWorkspacesTable>
10+
11+
constTemplate:Story<WorkspacesTableProps>=(args)=><WorkspacesTable{...args}/>
12+
13+
exportconstExample=Template.bind({})
14+
Example.args={
15+
templateInfo:MockTemplate,
16+
workspaces:[MockWorkspace],
17+
onCreateWorkspace:()=>{
18+
console.info("Create workspace")
19+
},
20+
}
21+
22+
exportconstEmpty=Template.bind({})
23+
Empty.args={
24+
templateInfo:MockTemplate,
25+
workspaces:[],
26+
onCreateWorkspace:()=>{
27+
console.info("Create workspace")
28+
},
29+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
importBoxfrom"@material-ui/core/Box"
2+
importButtonfrom"@material-ui/core/Button"
3+
importTablefrom"@material-ui/core/Table"
4+
importTableBodyfrom"@material-ui/core/TableBody"
5+
importTableCellfrom"@material-ui/core/TableCell"
6+
importTableHeadfrom"@material-ui/core/TableHead"
7+
importTableRowfrom"@material-ui/core/TableRow"
8+
importReactfrom"react"
9+
import{Link}from"react-router-dom"
10+
import*asTypesGenfrom"../../api/typesGenerated"
11+
import{EmptyState}from"../EmptyState/EmptyState"
12+
import{TableHeaderRow}from"../TableHeaders/TableHeaders"
13+
import{TableLoader}from"../TableLoader/TableLoader"
14+
import{TableTitle}from"../TableTitle/TableTitle"
15+
16+
exportconstLanguage={
17+
title:"Workspaces",
18+
nameLabel:"Name",
19+
emptyMessage:"No workspaces have been created yet",
20+
emptyDescription:"Create a workspace to get started",
21+
ctaAction:"Create workspace",
22+
}
23+
24+
exportinterfaceWorkspacesTableProps{
25+
templateInfo?:TypesGen.Template
26+
workspaces?:TypesGen.Workspace[]
27+
onCreateWorkspace:()=>void
28+
}
29+
30+
exportconstWorkspacesTable:React.FC<WorkspacesTableProps>=({ templateInfo, workspaces, onCreateWorkspace})=>{
31+
constisLoading=!templateInfo||!workspaces
32+
33+
return(
34+
<Table>
35+
<TableHead>
36+
<TableTitletitle={Language.title}/>
37+
<TableHeaderRow>
38+
<TableCellsize="small">{Language.nameLabel}</TableCell>
39+
</TableHeaderRow>
40+
</TableHead>
41+
<TableBody>
42+
{isLoading&&<TableLoader/>}
43+
{workspaces&&
44+
workspaces.map((w)=>(
45+
<TableRowkey={w.id}>
46+
<TableCell>
47+
<Linkto={`/workspaces/${w.id}`}>{w.name}</Link>
48+
</TableCell>
49+
</TableRow>
50+
))}
51+
52+
{workspaces&&workspaces.length===0&&(
53+
<TableRow>
54+
<TableCellcolSpan={999}>
55+
<Boxp={4}>
56+
<EmptyState
57+
message={Language.emptyMessage}
58+
description={Language.emptyDescription}
59+
cta={
60+
<Buttonvariant="contained"color="primary"onClick={onCreateWorkspace}>
61+
{Language.ctaAction}
62+
</Button>
63+
}
64+
/>
65+
</Box>
66+
</TableCell>
67+
</TableRow>
68+
)}
69+
</TableBody>
70+
</Table>
71+
)
72+
}

‎site/src/pages/TemplatesPages/OrganizationPage/TemplatePage/TemplatePage.tsx

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
1-
importBoxfrom"@material-ui/core/Box"
2-
importButtonfrom"@material-ui/core/Button"
3-
importTablefrom"@material-ui/core/Table"
4-
importTableBodyfrom"@material-ui/core/TableBody"
5-
importTableCellfrom"@material-ui/core/TableCell"
6-
importTableHeadfrom"@material-ui/core/TableHead"
7-
importTableRowfrom"@material-ui/core/TableRow"
81
importReactfrom"react"
9-
import{Link,useNavigate,useParams}from"react-router-dom"
2+
import{useNavigate,useParams}from"react-router-dom"
103
importuseSWRfrom"swr"
114
import*asTypesGenfrom"../../../../api/typesGenerated"
12-
import{EmptyState}from"../../../../components/EmptyState/EmptyState"
135
import{ErrorSummary}from"../../../../components/ErrorSummary/ErrorSummary"
146
import{Header}from"../../../../components/Header/Header"
157
import{Margins}from"../../../../components/Margins/Margins"
168
import{Stack}from"../../../../components/Stack/Stack"
17-
import{TableHeaderRow}from"../../../../components/TableHeaders/TableHeaders"
18-
import{TableLoader}from"../../../../components/TableLoader/TableLoader"
19-
import{TableTitle}from"../../../../components/TableTitle/TableTitle"
9+
import{WorkspacesTable}from"../../../../components/WorkspacesTable/WorkspacesTable"
2010
import{unsafeSWRArgument}from"../../../../util"
2111
import{firstOrItem}from"../../../../util/array"
2212

2313
exportconstLanguage={
24-
tableTitle:"Workspaces",
25-
nameLabel:"Name",
26-
emptyMessage:"No workspaces have been created yet",
27-
emptyDescription:"Create a workspace to get started",
28-
totalLabel:"total",
29-
ctaAction:"Create workspace",
30-
subtitlePosfix:"workspaces",
14+
subtitle:"workspaces",
3115
}
3216

3317
exportconstTemplatePage:React.FC=()=>{
@@ -44,13 +28,11 @@ export const TemplatePage: React.FC = () => {
4428

4529
// This just grabs all workspaces... and then later filters them to match the
4630
// current template.
47-
4831
const{data:workspaces,error:workspacesError}=useSWR<TypesGen.Workspace[],Error>(
4932
()=>`/api/v2/organizations/${unsafeSWRArgument(organizationInfo).id}/workspaces`,
5033
)
5134

5235
consthasError=organizationError||templateError||workspacesError
53-
constisLoading=!templateInfo||!workspaces
5436

5537
constcreateWorkspace=()=>{
5638
navigate(`/templates/${organizationName}/${templateName}/create`)
@@ -68,7 +50,7 @@ export const TemplatePage: React.FC = () => {
6850
<Header
6951
title={firstOrItem(templateName,"")}
7052
description={firstOrItem(organizationName,"")}
71-
subTitle={perTemplateWorkspaces ?`${perTemplateWorkspaces.length}${Language.subtitlePosfix}` :""}
53+
subTitle={perTemplateWorkspaces ?`${perTemplateWorkspaces.length}${Language.subtitle}` :""}
7254
action={{
7355
text:"Create Workspace",
7456
onClick:createWorkspace,
@@ -80,43 +62,7 @@ export const TemplatePage: React.FC = () => {
8062
{templateError&&<ErrorSummaryerror={templateError}/>}
8163
{workspacesError&&<ErrorSummaryerror={workspacesError}/>}
8264
{!hasError&&(
83-
<Table>
84-
<TableHead>
85-
<TableTitletitle={Language.tableTitle}/>
86-
<TableHeaderRow>
87-
<TableCellsize="small">{Language.nameLabel}</TableCell>
88-
</TableHeaderRow>
89-
</TableHead>
90-
<TableBody>
91-
{isLoading&&<TableLoader/>}
92-
{workspaces&&
93-
workspaces.map((w)=>(
94-
<TableRowkey={w.id}>
95-
<TableCell>
96-
<Linkto={`/workspaces/${w.id}`}>{w.name}</Link>
97-
</TableCell>
98-
</TableRow>
99-
))}
100-
101-
{workspaces&&workspaces.length===0&&(
102-
<TableRow>
103-
<TableCellcolSpan={999}>
104-
<Boxp={4}>
105-
<EmptyState
106-
message={Language.emptyMessage}
107-
description={Language.emptyDescription}
108-
cta={
109-
<Buttonvariant="contained"color="primary"onClick={createWorkspace}>
110-
{Language.ctaAction}
111-
</Button>
112-
}
113-
/>
114-
</Box>
115-
</TableCell>
116-
</TableRow>
117-
)}
118-
</TableBody>
119-
</Table>
65+
<WorkspacesTabletemplateInfo={templateInfo}workspaces={workspaces}onCreateWorkspace={createWorkspace}/>
12066
)}
12167
</Margins>
12268
</Stack>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp