-
Notifications
You must be signed in to change notification settings - Fork 890
feat: Initial workspaces page route + skeleton #220
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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4aa738c
Add initial route
bryphe-coder 57143da
Initial scaffolding for workspaces page
bryphe-coder 07c7f70
More routing
bryphe-coder 4e0e64c
Set up initial data population
bryphe-coder fddfda1
Formatting
bryphe-coder d139d7b
Add a workspaces component to iterate
bryphe-coder 764acb8
Add initial story for workspace dashboard
bryphe-coder f63270e
Add initial test case
bryphe-coder 1e3eece
Add scaffolding for workspace page
bryphe-coder 8cbd09d
First round of clean-up
bryphe-coder 73c9f6c
Add my name on a TODO
bryphe-coder 1cd5cf3
Fix lint issues
bryphe-coder a8c650a
Merge branch 'main' into bryphe/feat/workspaces-page-skeleton
bryphe-coder 35318a4
Merge branch 'main' into bryphe/feat/workspaces-page-skeleton
bryphe-coder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,17 @@ | ||
import { Story } from "@storybook/react" | ||
import React from "react" | ||
import { Workspace, WorkspaceProps } from "./Workspace" | ||
import { MockWorkspace } from "../../test_helpers" | ||
|
||
export default { | ||
title: "Workspace", | ||
component: Workspace, | ||
argTypes: {}, | ||
} | ||
|
||
const Template: Story<WorkspaceProps> = (args) => <Workspace {...args} /> | ||
|
||
export const Example = Template.bind({}) | ||
Example.args = { | ||
workspace: MockWorkspace, | ||
} |
This file contains hidden or 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,15 @@ | ||
import { render, screen } from "@testing-library/react" | ||
import React from "react" | ||
import { Workspace } from "./Workspace" | ||
import { MockWorkspace } from "../../test_helpers" | ||
|
||
describe("Workspace", () => { | ||
it("renders", async () => { | ||
// When | ||
render(<Workspace workspace={MockWorkspace} />) | ||
|
||
// Then | ||
const element = await screen.findByText(MockWorkspace.name) | ||
expect(element).toBeDefined() | ||
}) | ||
}) |
This file contains hidden or 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,90 @@ | ||
import Box from "@material-ui/core/Box" | ||
import Paper from "@material-ui/core/Paper" | ||
import Typography from "@material-ui/core/Typography" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import CloudCircleIcon from "@material-ui/icons/CloudCircle" | ||
import Link from "next/link" | ||
import React from "react" | ||
|
||
import * as API from "../../api" | ||
|
||
export interface WorkspaceProps { | ||
workspace: API.Workspace | ||
} | ||
|
||
namespace Constants { | ||
export const TitleIconSize = 48 | ||
export const CardRadius = 8 | ||
export const CardPadding = 20 | ||
} | ||
|
||
/** | ||
* Workspace is the top-level component for viewing an individual workspace | ||
*/ | ||
export const Workspace: React.FC<WorkspaceProps> = ({ workspace }) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<WorkspaceHeader workspace={workspace} /> | ||
</div> | ||
) | ||
} | ||
|
||
/** | ||
* Component for the header at the top of the workspace page | ||
*/ | ||
export const WorkspaceHeader: React.FC<WorkspaceProps> = ({ workspace }) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<Paper elevation={0} className={styles.section}> | ||
<div className={styles.horizontal}> | ||
<WorkspaceHeroIcon /> | ||
<div className={styles.vertical}> | ||
<Typography variant="h4">{workspace.name}</Typography> | ||
<Typography variant="body2" color="textSecondary"> | ||
<Link href="javascript:;">{workspace.project_id}</Link> | ||
</Typography> | ||
</div> | ||
</div> | ||
</Paper> | ||
) | ||
} | ||
|
||
/** | ||
* Component to render the 'Hero Icon' in the header of a workspace | ||
*/ | ||
export const WorkspaceHeroIcon: React.FC = () => { | ||
return ( | ||
<Box mr="1em"> | ||
<CloudCircleIcon width={Constants.TitleIconSize} height={Constants.TitleIconSize} /> | ||
</Box> | ||
) | ||
} | ||
|
||
export const useStyles = makeStyles((theme) => { | ||
return { | ||
root: { | ||
display: "flex", | ||
flexDirection: "column", | ||
}, | ||
horizontal: { | ||
display: "flex", | ||
flexDirection: "row", | ||
}, | ||
vertical: { | ||
display: "flex", | ||
flexDirection: "column", | ||
}, | ||
section: { | ||
border: `1px solid ${theme.palette.divider}`, | ||
borderRadius: Constants.CardRadius, | ||
padding: Constants.CardPadding, | ||
}, | ||
icon: { | ||
width: Constants.TitleIconSize, | ||
height: Constants.TitleIconSize, | ||
}, | ||
} | ||
}) |
This file contains hidden or 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 @@ | ||
export * from "./Workspace" |
This file contains hidden or 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,68 @@ | ||
import React from "react" | ||
import useSWR from "swr" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import { useRouter } from "next/router" | ||
import { Navbar } from "../../../components/Navbar" | ||
import { Footer } from "../../../components/Page" | ||
import { useUser } from "../../../contexts/UserContext" | ||
import { firstOrItem } from "../../../util/array" | ||
import { ErrorSummary } from "../../../components/ErrorSummary" | ||
import { FullScreenLoader } from "../../../components/Loader/FullScreenLoader" | ||
import { Workspace } from "../../../components/Workspace" | ||
|
||
import * as API from "../../../api" | ||
|
||
const WorkspacesPage: React.FC = () => { | ||
const styles = useStyles() | ||
const router = useRouter() | ||
const { me, signOut } = useUser(true) | ||
|
||
const { user: userQueryParam, workspace: workspaceQueryParam } = router.query | ||
|
||
const { data: workspace, error: workspaceError } = useSWR<API.Workspace, Error>(() => { | ||
const userParam = firstOrItem(userQueryParam, null) | ||
const workspaceParam = firstOrItem(workspaceQueryParam, null) | ||
|
||
// TODO(Bryan): Getting non-personal users isn't supported yet in the backend. | ||
// So if the user is the same as 'me', use 'me' as the parameter | ||
const normalizedUserParam = me && userParam === me.id ? "me" : userParam | ||
|
||
// The SWR API expects us to 'throw' if the query isn't ready yet, so these casts to `any` are OK | ||
// because the API expects exceptions. | ||
return `/api/v2/workspaces/${(normalizedUserParam as any).toString()}/${(workspaceParam as any).toString()}` | ||
}) | ||
|
||
if (workspaceError) { | ||
return <ErrorSummary error={workspaceError} /> | ||
} | ||
|
||
if (!me || !workspace) { | ||
return <FullScreenLoader /> | ||
} | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<Navbar user={me} onSignOut={signOut} /> | ||
|
||
<div className={styles.inner}> | ||
<Workspace workspace={workspace} /> | ||
</div> | ||
|
||
<Footer /> | ||
</div> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
root: { | ||
display: "flex", | ||
flexDirection: "column", | ||
}, | ||
inner: { | ||
maxWidth: "1380px", | ||
margin: "1em auto", | ||
width: "100%", | ||
}, | ||
})) | ||
|
||
export default WorkspacesPage |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.