-
Notifications
You must be signed in to change notification settings - Fork 881
fix: Update routes for project page, workspace creation page, and workspace page #415
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
5 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
This file was deleted.
Oops, something went wrong.
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,78 @@ | ||
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 { unsafeSWRArgument } from "../../util" | ||
import * as API from "../../api" | ||
|
||
const WorkspacesPage: React.FC = () => { | ||
const styles = useStyles() | ||
const router = useRouter() | ||
const { me, signOut } = useUser(true) | ||
|
||
const { workspace: workspaceQueryParam } = router.query | ||
|
||
const { data: workspace, error: workspaceError } = useSWR<API.Workspace, Error>(() => { | ||
const workspaceParam = firstOrItem(workspaceQueryParam, null) | ||
|
||
return `/api/v2/workspaces/${workspaceParam}` | ||
}) | ||
|
||
// Fetch parent project | ||
const { data: project, error: projectError } = useSWR<API.Project, Error>(() => { | ||
return `/api/v2/projects/${unsafeSWRArgument(workspace).project_id}` | ||
}) | ||
|
||
const { data: organization, error: organizationError } = useSWR<API.Project, Error>(() => { | ||
return `/api/v2/organizations/${unsafeSWRArgument(project).organization_id}` | ||
}) | ||
|
||
if (workspaceError) { | ||
return <ErrorSummary error={workspaceError} /> | ||
} | ||
|
||
if (projectError) { | ||
return <ErrorSummary error={projectError} /> | ||
} | ||
|
||
if (organizationError) { | ||
return <ErrorSummary error={organizationError} /> | ||
} | ||
|
||
if (!me || !workspace || !project || !organization) { | ||
return <FullScreenLoader /> | ||
} | ||
|
||
return ( | ||
<div className={styles.root}> | ||
<Navbar user={me} onSignOut={signOut} /> | ||
|
||
<div className={styles.inner}> | ||
<Workspace organization={organization} project={project} workspace={workspace} /> | ||
</div> | ||
|
||
<Footer /> | ||
</div> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
root: { | ||
display: "flex", | ||
flexDirection: "column", | ||
}, | ||
inner: { | ||
maxWidth: "1380px", | ||
margin: "1em auto", | ||
width: "100%", | ||
}, | ||
})) | ||
|
||
export default WorkspacesPage |
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,2 @@ | ||
export * from "./array" | ||
export * from "./swr" |
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 @@ | ||
/** | ||
* unsafeSWRArgument | ||
* | ||
* Helper function for working with SWR / useSWR in the TypeScript world. | ||
* TypeScript is helpful in enforcing type-safety, but SWR is designed to | ||
* with the expectation that, if the argument is not available, an exception | ||
* will be thrown. | ||
* | ||
* This just helps in abiding by those rules, explicitly, and lets us suppress | ||
* the lint warning in a single place. | ||
*/ | ||
export const unsafeSWRArgument = <T>(arg: T | null | undefined): T => { | ||
if (typeof arg === "undefined" || arg === null) { | ||
throw "SWR: Expected exception because the argument is not available" | ||
} | ||
return arg | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious what this is, but I'm sure you have a good reason for using it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question @presleyp ! I'm open to ideas for better ways to handle this (and luckily, it's at least temporary - if we switch to XState and migrate from SWR, this utility isn't needed).
With SWR - when one call relies on another call - SWR expects the function to 'throw' until the data is available. So I ended up with a lot of casts to any + suppressions:
I ended up with a lot of these comments + any casts, so I figured if I extracted it out to a helper, it'd be a little clearer:
I'm happy to switch back to the more verbose comment + eslint disable + cast, or rename
unsafeSWRArgument
to something more understandable. (Implementation is here if it helps) IMO the most important criteria is that it is readable / understandable for you and @vapurrmaidAnd luckily, seems like this will be only temporary - if we remove SWR and use XState, this will no longer be an issue and this can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see where you defined! (Thought it was an SWR thing at first)