Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4f70f84

Browse files
authored
feat: WorkspaceSection action, styles (#1623)
This PR is a squash of refactors and improvements in our Workspace and WorkspaceSection components. An action prop is added to WorkspaceSection and along the way, I refactored things that were not meeting conventions or were hard to read. With this addition, I am further unblocked in making auto-start/off editable in the UI, as I intend to use the Action prop to trigger a modal (or routed page view) with the form. Squashed commits: * refactor: spaces for readability It's hard to read HTMl markup without spaces on adjacent nodes * refactor: props Our components had unused props and arbitrary ordering.
1 parent 0effb71 commit 4f70f84

File tree

3 files changed

+43
-8
lines changed

3 files changed

+43
-8
lines changed

site/src/components/Workspace/Workspace.tsx

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ import { WorkspaceSection } from "../WorkspaceSection/WorkspaceSection"
99
import { WorkspaceStatusBar } from "../WorkspaceStatusBar/WorkspaceStatusBar"
1010

1111
export interface WorkspaceProps {
12-
organization?: TypesGen.Organization
13-
workspace: TypesGen.Workspace
14-
template?: TypesGen.Template
1512
handleStart: () => void
1613
handleStop: () => void
1714
handleRetry: () => void
1815
handleUpdate: () => void
16+
workspace: TypesGen.Workspace
1917
workspaceStatus: WorkspaceStatus
2018
builds?: TypesGen.WorkspaceBuild[]
2119
}
@@ -24,11 +22,11 @@ export interface WorkspaceProps {
2422
* Workspace is the top-level component for viewing an individual workspace
2523
*/
2624
export const Workspace: React.FC<WorkspaceProps> = ({
27-
workspace,
2825
handleStart,
2926
handleStop,
3027
handleRetry,
3128
handleUpdate,
29+
workspace,
3230
workspaceStatus,
3331
builds,
3432
}) => {
@@ -45,19 +43,23 @@ export const Workspace: React.FC<WorkspaceProps> = ({
4543
handleUpdate={handleUpdate}
4644
workspaceStatus={workspaceStatus}
4745
/>
46+
4847
<div className={styles.horizontal}>
4948
<div className={styles.sidebarContainer}>
5049
<WorkspaceSection title="Applications">
5150
<Placeholder />
5251
</WorkspaceSection>
5352
<WorkspaceSchedule workspace={workspace} />
53+
5454
<WorkspaceSection title="Dev URLs">
5555
<Placeholder />
5656
</WorkspaceSection>
57+
5758
<WorkspaceSection title="Resources">
5859
<Placeholder />
5960
</WorkspaceSection>
6061
</div>
62+
6163
<div className={styles.timelineContainer}>
6264
<WorkspaceSection title="Timeline" contentsProps={{ className: styles.timelineContents }}>
6365
<BuildsTable builds={builds} className={styles.timelineTable} />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import IconButton from "@material-ui/core/IconButton"
2+
import EditIcon from "@material-ui/icons/Edit"
3+
import { action } from "@storybook/addon-actions"
4+
import { Story } from "@storybook/react"
5+
import React from "react"
6+
import { WorkspaceSection, WorkspaceSectionProps } from "./WorkspaceSection"
7+
8+
export default {
9+
title: "components/WorkspaceSection",
10+
component: WorkspaceSection,
11+
}
12+
13+
const Template: Story<WorkspaceSectionProps> = (args) => <WorkspaceSection {...args}>Content</WorkspaceSection>
14+
15+
export const NoAction = Template.bind({})
16+
NoAction.args = {
17+
title: "A Workspace Section",
18+
}
19+
20+
export const Action = Template.bind({})
21+
Action.args = {
22+
action: (
23+
<IconButton onClick={action("edit")}>
24+
<EditIcon />
25+
</IconButton>
26+
),
27+
title: "Action Section",
28+
}

site/src/components/WorkspaceSection/WorkspaceSection.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ import { CardPadding, CardRadius } from "../../theme/constants"
66
import { combineClasses } from "../../util/combineClasses"
77

88
export interface WorkspaceSectionProps {
9-
title?: string
9+
/**
10+
* action appears in the top right of the section card
11+
*/
12+
action?: React.ReactNode
1013
contentsProps?: HTMLProps<HTMLDivElement>
14+
title?: string
1115
}
1216

13-
export const WorkspaceSection: React.FC<WorkspaceSectionProps> = ({ title, children, contentsProps }) => {
17+
export const WorkspaceSection: React.FC<WorkspaceSectionProps> = ({ action, children, contentsProps, title }) => {
1418
const styles = useStyles()
1519

1620
return (
17-
<Paper elevation={0} className={styles.root}>
21+
<Paper className={styles.root} elevation={0}>
1822
{title && (
1923
<div className={styles.headerContainer}>
2024
<div className={styles.header}>
2125
<Typography variant="h6">{title}</Typography>
26+
{action && <div>{action}</div>}
2227
</div>
2328
</div>
2429
)}
@@ -45,7 +50,7 @@ const useStyles = makeStyles((theme) => ({
4550
header: {
4651
alignItems: "center",
4752
display: "flex",
48-
flexDirection: "row",
53+
justifyContent: "space-between",
4954
marginBottom: theme.spacing(1),
5055
marginTop: theme.spacing(1),
5156
paddingLeft: CardPadding + theme.spacing(1),

0 commit comments

Comments
 (0)