8000 feat: Redesign workspaces page by kylecarbs · Pull Request #1450 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: Redesign workspaces page #1450

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 24 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
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
13 changes: 4 additions & 9 deletions site/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import CssBaseline from "@material-ui/core/CssBaseline"
import ThemeProvider from "@material-ui/styles/ThemeProvider"
import { withThemes } from "@react-theming/storybook-addon"
Copy link
Contributor
@greyscaled greyscaled May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question(if-minor): Are we able to remove this dependency now "@react-theming/storybook-addon": "1.1.5", ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

import { createMemoryHistory } from "history"
import { addDecorator } from "node_modules/@storybook/react"
import { unstable_HistoryRouter as HistoryRouter } from "react-router-dom"
import { dark, light } from "../src/theme"
import { dark } from "../src/theme"
import "../src/theme/globalFonts"

const providerFn = ({ children, theme }) => (
<ThemeProvider theme={theme}>
<CssBaseline />
{children}
</ThemeProvider>
addDecorator((story) =>
<ThemeProvider theme={dark}>
<CssBaseline />{story()}</ThemeProvider>
)

addDecorator(withThemes(null, [light, dark], { providerFn }))

const history = createMemoryHistory()

const routerDecorator = (Story) => {
Expand Down
3 changes: 2 additions & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"typegen": "xstate typegen 'src/**/*.ts'"
},
"dependencies": {
"@fontsource/fira-code": "4.5.9",
"@fontsource/ibm-plex-mono": "4.5.9",
"@fontsource/inter": "4.5.7",
"@material-ui/core": "4.9.4",
"@material-ui/icons": "4.5.1",
Expand All @@ -35,6 +35,7 @@
"@xstate/react": "3.0.0",
"axios": "0.26.1",
"cronstrue": "2.4.0",
"dayjs": "^1.11.2",
"formik": "2.2.9",
"history": "5.3.0",
"react": "17.0.2",
Expand Down
9 changes: 9 additions & 0 deletions site/src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { TemplatesPage } from "./pages/TemplatesPages/TemplatesPage"
import { CreateUserPage } from "./pages/UsersPage/CreateUserPage/CreateUserPage"
import { UsersPage } from "./pages/UsersPage/UsersPage"
import { WorkspacePage } from "./pages/WorkspacePage/WorkspacePage"
import { WorkspacesPage } from "./pages/WorkspacesPage/WorkspacesPage"

const TerminalPage = React.lazy(() => import("./pages/TerminalPage/TerminalPage"))

Expand Down Expand Up @@ -75,6 +76,14 @@ export const AppRouter: React.FC = () => (
</Route>

<Route path="workspaces">
<Route
index
element={
<AuthAndFrame>
<WorkspacesPage />
</AuthAndFrame>
}
/>
<Route
path=":workspace"
element={
Expand Down
5 changes: 5 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ export const getWorkspace = async (workspaceId: string): Promise<TypesGen.Worksp
return response.data
}

export const getWorkspaces = async (userID = "me"): Promise<TypesGen.Workspace[]> => {
const response = await axios.get<TypesGen.Workspace[]>(`/api/v2/users/${userID}/workspaces`)
return response.data
}

export const getWorkspaceByOwnerAndName = async (
organizationID: string,
username = "me",
Expand Down
4 changes: 2 additions & 2 deletions site/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BrowserRouter as Router } from "react-router-dom"
import { SWRConfig } from "swr"
import { AppRouter } from "./AppRouter"
import { GlobalSnackbar } from "./components/GlobalSnackbar/GlobalSnackbar"
import { light } from "./theme"
import { dark } from "./theme"
import "./theme/globalFonts"
import { XServiceProvider } from "./xServices/StateContext"

Expand All @@ -31,7 +31,7 @@ export const App: React.FC = () => {
}}
>
<XServiceProvider>
<ThemeProvider theme={light}>
<ThemeProvider theme={dark}>
<Cs 97AE sBaseline />
<AppRouter />
<GlobalSnackbar />
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/AdminDropdown/AdminDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const AdminDropdown: React.FC = () => {
<>
<div className={styles.link}>
<ListItem selected={Boolean(anchorEl)} button onClick={onOpenAdminMenu}>
<ListItemText className="no-brace" color="primary" primary={Language.menuTitle} />
<ListItemText className="no-brace" primary={Language.menuTitle} />
{anchorEl ? <CloseDropdown /> : <OpenDropdown />}
</ListItem>
</div>
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/CodeBlock/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useStyles = makeStyles((theme) => ({
root: {
minHeight: 156,
background: theme.palette.background.default,
color: theme.palette.codeBlock.contrastText,
color: theme.palette.text.primary,
fontFamily: MONOSPACE_FONT_FAMILY,
fontSize: 13,
wordBreak: "break-all",
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/CodeExample/CodeExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const useStyles = makeStyles((theme) => ({
justifyContent: "space-between",
alignItems: "center",
background: theme.palette.background.default,
color: theme.palette.codeBlock.contrastText,
color: theme.palette.primary.contrastText,
fontFamily: MONOSPACE_FONT_FAMILY,
fontSize: 13,
padding: theme.spacing(2),
Expand Down
7 changes: 3 additions & 4 deletions site/src/components/ConfirmDialog/ConfirmDialog.test.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import ThemeProvider from "@material-ui/styles/ThemeProvider"
import { fireEvent, render } from "@testing-library/react"
import React from "react"
import { act } from "react-dom/test-utils"
import { light } from "../../theme"
import { WrapperComponent } from "../../testHelpers/renderHelpers"
import { ConfirmDialog, ConfirmDialogProps } from "./ConfirmDialog"

namespace Helpers {
export const Component: React.FC<ConfirmDialogProps> = (props: ConfirmDialogProps) => {
return (
<ThemeProvider theme={light}>
<WrapperComponent>
<ConfirmDialog {...props} />
</ThemeProvider>
</WrapperComponent>
)
}
}
Expand Down
15 changes: 6 additions & 9 deletions site/src/components/ConfirmDialog/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,11 @@ interface StyleProps {
const useStyles = makeStyles((theme) => ({
dialogWrapper: (props: StyleProps) => ({
"& .MuiPaper-root": {
background:
props.type === "info"
? theme.palette.confirmDialog.info.background
: theme.palette.confirmDialog.error.background,
background: props.type === "info" ? theme.palette.primary.main : theme.palette.error.dark,
},
}),
dialogContent: (props: StyleProps) => ({
color: props.type === "info" ? theme.palette.confirmDialog.info.text : theme.palette.confirmDialog.error.text,
color: props.type === "info" ? theme.palette.primary.contrastText : theme.palette.error.contrastText,
padding: theme.spacing(6),
textAlign: "center",
}),
Expand All @@ -65,15 +62,15 @@ const useStyles = makeStyles((theme) => ({
description: (props: StyleProps) => ({
color:
props.type === "info"
? fade(theme.palette.confirmDialog.info.text, 0.75)
: fade(theme.palette.confirmDialog.error.text, 0.75),
? fade(theme.palette.primary.contrastText, 0.75)
: fade(theme.palette.error.contrastText, 0.75),
lineHeight: "160%",

"& strong": {
color:
props.type === "info"
? fade(theme.palette.confirmDialog.info.text, 0.95)
: fade(theme.palette.confirmDialog.error.text, 0.95),
? fade(theme.palette.primary.contrastText, 0.95)
: fade(theme.palette.error.contrastText, 0.95),
},
}),
}))
Expand Down
6 changes: 3 additions & 3 deletions site/src/components/CopyButton/CopyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ const useStyles = makeStyles((theme) => ({
},
copyButton: {
borderRadius: 7,
background: theme.palette.codeBlock.button.main,
color: theme.palette.codeBlock.button.contrastText,
background: theme.palette.background.default,
color: theme.palette.primary.contrastText,
padding: theme.spacing(0.85),
minWidth: 32,

"&:hover": {
background: theme.palette.codeBlock.button.hover,
background: theme.palette.background.paper,
},
},
fileCopyIcon: {
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ const useButtonStyles = makeStyles((theme) => ({
},
},
confirmDialogCancelButton: (props: StyleProps) => {
const color = props.type === "info" ? theme.palette.confirmDialog.info.text : theme.palette.confirmDialog.error.text
const color = props.type === "info" ? theme.palette.primary.contrastText : theme.palette.error.contrastText
return {
background: fade(color, 0.15),
color,
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const useStyles = makeStyles((theme) => ({
display: "flex",
alignItems: "center",
height: 126,
background: theme.palette.hero.main,
background: theme.palette.background.default,
boxShadow: theme.shadows[3],
},
topInner: {
Expand Down
6 changes: 2 additions & 4 deletions site/src/components/HeaderButton/HeaderButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Button from "@material-ui/core/Button"
import { lighten, makeStyles } from "@material-ui/core/styles"
import { makeStyles } from "@material-ui/core/styles"
import React from "react"

export interface HeaderButtonProps {
Expand Down Expand Up @@ -28,10 +28,8 @@ export const HeaderButton: React.FC<HeaderButtonProps> = (props) => {
)
}

const useStyles = makeStyles((theme) => ({
const useStyles = makeStyles(() => ({
pageButton: {
whiteSpace: "nowrap",
backgroundColor: lighten(theme.palette.hero.main, 0.1),
color: "#B5BFD2",
},
}))
7 changes: 2 additions & 5 deletions site/src/components/Margins/Margins.tsx
F41A
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ const useStyles = makeStyles(() => ({
maxWidth,
padding: `0 ${sidePadding}`,
flex: 1,
width: "100%",
},
}))

export const Margins: React.FC = ({ children }) => {
const styles = useStyles()
return (
<div>
<div className={styles.margins}>{children}</div>
</div>
)
return <div className={styles.margins}>{children}</div>
}
30 changes: 17 additions & 13 deletions site/src/components/NavbarView/NavbarView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ export const NavbarView: React.FC<NavbarViewProps> = ({ user, onSignOut, display
<nav className={styles.root}>
<List className={styles.fixed}>
<ListItem className={styles.item}>
<NavLink className={styles.logo} to="/">
<NavLink className={styles.logo} to="/workspaces">
<Logo fill="white" opacity={1} width={125} />
</NavLink>
</ListItem>
<ListItem button className={styles.item}>
<NavLink className={styles.link} to="/workspaces">
Workspaces
</NavLink>
</ListItem>
<ListItem button className={styles.item}>
<NavLink className={styles.link} to="/templates">
Templates
Expand All @@ -47,13 +52,13 @@ const useStyles = makeStyles((theme) => ({
justifyContent: "center",
alignItems: "center",
height: navHeight,
background: theme.palette.navbar.main,
background: theme.palette.background.paper,
marginTop: 0,
transition: "margin 150ms ease",
"@media (display-mode: standalone)": {
borderTop: `1px solid ${theme.palette.divider}`,
},
borderBottom: `1px solid #383838`,
borderBottom: `1px solid ${theme.palette.divider}`,
},
fixed: {
flex: 0,
Expand All @@ -68,9 +73,9 @@ const useStyles = makeStyles((theme) => ({
display: "flex",
height: navHeight,
paddingLeft: theme.spacing(4),
paddingRight: theme.spacing(2),
paddingRight: theme.spacing(4),
"& svg": {
width: 125,
width: 109,
},
},
title: {
Expand Down Expand Up @@ -98,17 +103,16 @@ const useStyles = makeStyles((theme) => ({
"&.active": {
position: "relative",
color: theme.palette.primary.contrastText,
fontWeight: "bold",

"&::before": {
content: `"{"`,
left: 10,
position: "absolute",
},

"&::after": {
content: `"}"`,
content: `" "`,
bottom: 0,
left: theme.spacing(3),
background: "#C16800",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good theme color that could go here in place of the hardcoded color? Like secondary or something maybe.

right: theme.spacing(3),
height: 2,
position: "absolute",
right: 10,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const AccountForm: React.FC<AccountFormProps> = ({
{error && <FormHelperText error>{error}</FormHelperText>}

<div>
<LoadingButton color="primary" loading={isLoading} type="submit" variant="contained">
<LoadingButton loading={isLoading} type="submit" variant="contained">
{isLoading ? "" : Language.updatePreferences}
</LoadingButton>
</div>
Expand Down
4 changes: 2 additions & 2 deletions site/src/components/SignInForm/SignInForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ export const SignInForm: React.FC<SignInFormProps> = ({
{authErrorMessage && <FormHelperText error>{Language.authErrorMessage}</FormHelperText>}
{methodsErrorMessage && <FormHelperText error>{Language.methodsErrorMessage}</FormHelperText>}
<div className={styles.submitBtn}>
<LoadingButton color="primary" loading={isLoading} fullWidth type="submit" variant="contained">
<LoadingButton loading={isLoading} fullWidth type="submit" variant="contained">
{isLoading ? "" : Language.passwordSignIn}
</LoadingButton>
</div>
</form>
{authMethods?.github && (
<div className={styles.submitBtn}>
<Link href={`/api/v2/users/oauth2/github/callback?redirect=${encodeURIComponent(redirectTo)}`}>
<Button color="primary" disabled={isLoading} fullWidth type="submit" variant="contained">
<Button disabled={isLoading} fullWidth type="submit" variant="contained">
{Language.githubSignIn}
</Button>
</Link>
Expand Down
16 changes: 15 additions & 1 deletion site/src/components/UserAvatar/UserAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Avatar from "@material-ui/core/Avatar"
import { makeStyles } from "@material-ui/core/styles"
import React from "react"
import { combineClasses } from "../../util/combineClasses"
import { firstLetter } from "../../util/firstLetter"

export interface UserAvatarProps {
Expand All @@ -8,5 +10,17 @@ export interface UserAvatarProps {
}

export const UserAvatar: React.FC<UserAvatarProps> = ({ username, className }) => {
return <Avatar className={className}>{firstLetter(username)}</Avatar>
const styles = useStyles()
return (
<Avatar variant="square" className={combineClasses([styles.avatar, className])}>
{firstLetter(username)}
</Avatar>
)
}

const useStyles = makeStyles((theme) => ({
avatar: {
borderRadius: 2,
border: `1px solid ${theme.palette.divider}`,
},
}))
21 changes: 21 additions & 0 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useMachine } from "@xstate/react"
import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
import React from "react"
import { workspacesMachine } from "../../xServices/workspaces/workspacesXService"
import { WorkspacesPageView } from "./WorkspacesPageView"

dayjs.extend(relativeTime)

export const WorkspacesPage: React.FC = () => {
const [workspacesState] = useMachine(workspacesMachine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me that now that I'm doing a bunch of polling on the workspace page, I can and should useMachine for that too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. I never thought of that, but I suppose it makes sense.


return (
<>
<WorkspacesPageView
workspaces={workspacesState.context.workspaces}
error={workspacesState.context.getWorkspacesError}
/>
</>
)
}
Loading
0