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

Skip to content

refactor: Migrate from Next.js to pure webpack config #360

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 72 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
f87c03e
Remove nextJS as dependency
bryphe-coder Feb 24, 2022
d767aa8
Next js config -> webpack config
bryphe-coder Feb 24, 2022
e1dbec2
Migrate next/link -> react-router-dom Link
bryphe-coder Feb 24, 2022
6f65f1b
Migrate routing to react-router-dom style; get webpack building
bryphe-coder Feb 24, 2022
69010f8
Hook up workspaces route
bryphe-coder Feb 25, 2022
7800a4e
First round of clean-up
bryphe-coder Feb 25, 2022
7158d75
Get SignInForm tests green
bryphe-coder Feb 25, 2022
a58a29d
Get additional tests green
bryphe-coder Feb 25, 2022
bc83df6
Get tests green again
bryphe-coder Feb 25, 2022
3c5895c
HMR / live reload updates from FE variety
bryphe-coder Feb 25, 2022
b657fe6
Remove export from Makefile temporarily
bryphe-coder Feb 25, 2022
75a38d9
Remove export command
bryphe-coder Feb 25, 2022
e4fe1ed
Convert webpack config to typescript
bryphe-coder Feb 25, 2022
d9e9d2d
Split out dev vs prod webpack configs
bryphe-coder Feb 25, 2022
02838a2
Remove nextrouter, port over some functionality to embed
bryphe-coder Feb 25, 2022
d8c983f
Implement content-addressable (and cache-friendly) bundle name
bryphe-coder Feb 26, 2022
396be38
Start setting up new post-nextrouter routing strategy
bryphe-coder Feb 26, 2022
87be7aa
Fix production webpack config
bryphe-coder Feb 26, 2022
3e1d008
Remove _document
bryphe-coder Feb 26, 2022
d1566d3
Remove nested GITKEEP
bryphe-coder Feb 26, 2022
bdd966b
Copy static files over
bryphe-coder Feb 26, 2022
ac064ca
Fix up dependencies
bryphe-coder Feb 26, 2022
c0ca05c
Clean-up
bryphe-coder Feb 26, 2022
b85dcf1
Merge main
bryphe-coder Mar 2, 2022
3a724e4
Merge main
bryphe-coder Mar 8, 2022
40a4e69
Use same entry point as v1
bryphe-coder Mar 8, 2022
7f10110
Initial lint fix
bryphe-coder Mar 8, 2022
a5a09d5
Move index.html -> html_templates
bryphe-coder Mar 8, 2022
5af2c20
Merge branch 'main' into bryphe/experiment/nextjs-to-webpack
bryphe-coder Mar 8, 2022
3898544
Implement 404 page
bryphe-coder Mar 8, 2022
cd07056
Add test case for caching
bryphe-coder Mar 9, 2022
78051ff
Remove now-unused function
bryphe-coder Mar 9, 2022
cf8b4e0
Add plumbing to make CSRF token testable
bryphe-coder Mar 9, 2022
8bd5804
Fix todos
bryphe-coder Mar 9, 2022
427672b
Additional test cases
bryphe-coder Mar 9, 2022
929a3b7
Remove now unnecessary test
bryphe-coder Mar 9, 2022
f822347
Add test + fix template parameters
bryphe-coder Mar 9, 2022
6c00822
Fix up go lint cases
bryphe-coder Mar 9, 2022
12b0e1d
Remove commented and now-unnecessary export step
bryphe-coder Mar 9, 2022
b348b70
Fix Handler -> DefaultHandler
bryphe-coder Mar 9, 2022
07f52d5
Fix remaining lint issues
bryphe-coder Mar 9, 2022
095bcfc
Add webpack-bundle-analyzer + command to run server
bryphe-coder Mar 9, 2022
7b5e982
Better document the webpack files to match the work Grey is doing in v1
bryphe-coder Mar 9, 2022
a3f31c9
Update webpack configs
bryphe-coder Mar 9, 2022
4134392
Port over fileoverview comments
bryphe-coder Mar 9, 2022
90f04ab
Remove accidental addition of test collateral
bryphe-coder Mar 10, 2022
6ffd38b
Use <Navigate> component from react-router-dom instead of custom <Red…
bryphe-coder Mar 10, 2022
7a50bc1
Merge main
bryphe-coder Mar 11, 2022
b4a18e0
Fix lint issues
bryphe-coder Mar 11, 2022
244e305
Remove build:dev to match v1 suite of webpack build commands
bryphe-coder Mar 11, 2022
e65f5af
Remove dev.ts and several references in jest/tsconfig
bryphe-coder Mar 11, 2022
19509bc
Fix copy-paste error with the NotFoundPage
bryphe-coder Mar 11, 2022
f4f7cb3
Add descriptive comment for SWR fetching
bryphe-coder Mar 11, 2022
37295ce
Remove unnecessary inline styles
bryphe-coder Mar 11, 2022
02a8718
Remove custom title in HTMLWebpackPlugin
bryphe-coder Mar 11, 2022
6e168a8
Use default settings for HtmlWebpackPlugin for script injection
bryphe-coder Mar 11, 2022
1a600d1
Remove 'noEmit' flag from tsconfig
bryphe-coder Mar 11, 2022
cab30cd
Remove dev.ts from tsconfig.test.json
bryphe-coder Mar 11, 2022
b725cf8
Format jest file
bryphe-coder Mar 11, 2022
71d076d
Use bundle name as-is for development
bryphe-coder Mar 11, 2022
818fc74
Factor to v1 strategy; get tests passing
bryphe-coder Mar 11, 2022
b61d39e
Fix go lint issues
bryphe-coder Mar 11, 2022
8b67328
Add missed meta tag
bryphe-coder Mar 11, 2022
2a183ce
Port over publicPath, needed for the v1 embed strategy
bryphe-coder Mar 11, 2022
037489f
Fix up formatting
bryphe-coder Mar 11, 2022
0b81ab8
Fix compilation error
bryphe-coder Mar 12, 2022
0839201
Update comment
bryphe-coder Mar 12, 2022
685b8f1
Add progress to build:analyze command
bryphe-coder Mar 12, 2022
807ac3b
Tweak comment
bryphe-coder Mar 12, 2022
2d47d8c
Add more logs to playwright
bryphe-coder Mar 12, 2022
861592a
Port over our playwright utilities for client-side nav
bryphe-coder Mar 12, 2022
c31f594
Merge branch 'main' into bryphe/experiment/nextjs-to-webpack
bryphe-coder Mar 12, 2022
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
Prev Previous commit
Next Next commit
Merge main
  • Loading branch information
bryphe-coder committed Mar 11, 2022
commit 7a50bc18b761fd7da10ff65d6ceb4363edfc1f44
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/powersj/whatsthis v1.3.0
github.com/quasilyte/go-ruleguard/dsl v0.3.17
github.com/spf13/cobra v1.3.0
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.0
github.com/tabbed/pqtype v0.1.1
github.com/unrolled/secure v1.10.0
Expand Down
91 changes: 4 additions & 87 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion site/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export interface Workspace {

export namespace Workspace {
export const create = async (request: CreateWorkspaceRequest): Promise<Workspace> => {
const response = await fetch(`/api/v2/workspaces/me`, {
const response = await fetch(`/api/v2/users/me/workspaces`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
6 changes: 2 additions & 4 deletions site/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import LoginPage from "./pages/login"
import ProjectsPage from "./pages/projects"
import ProjectPage from "./pages/projects/[organization]/[project]"
import CreateWorkspacePage from "./pages/projects/[organization]/[project]/create"
import WorkspacePage from "./pages/workspaces/[user]/[workspace]"
import WorkspacePage from "./pages/workspaces/[workspace]"

export const App: React.FC = () => {
return (
Expand Down Expand Up @@ -50,9 +50,7 @@ export const App: React.FC = () => {
</Route>

<Route path="workspaces">
<Route path=":user">
<Route path=":workspace" element={<WorkspacePage />} />
</Route>
<Route path=":workspace" element={<WorkspacePage />} />
</Route>

{/* Using path="*"" means "match anything", so this route
Expand Down
4 changes: 2 additions & 2 deletions site/components/Workspace/Workspace.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { screen } from "@testing-library/react"
import React from "react"
import { Workspace } from "./Workspace"
import { MockWorkspace, render } from "../../test_helpers"
import { MockOrganization, MockProject, MockWorkspace, render } from "../../test_helpers"

describe("Workspace", () => {
it("renders", async () => {
// When
render(<Workspace workspace={MockWorkspace} />)
render(<Workspace organization={MockOrganization} project={MockProject} workspace={MockWorkspace} />)

// Then
const element = await screen.findByText(MockWorkspace.name)
Expand Down
12 changes: 8 additions & 4 deletions site/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ import * as API from "../../api"
import { WorkspaceSection } from "./WorkspaceSection"

export interface WorkspaceProps {
organization: API.Organization
workspace: API.Workspace
project: API.Project
}

/**
* Workspace is the top-level component for viewing an individual workspace
*/
export const Workspace: React.FC<WorkspaceProps> = ({ workspace }) => {
export const Workspace: React.FC<WorkspaceProps> = ({ organization, project, workspace }) => {
const styles = useStyles()

return (
<div className={styles.root}>
<div className={styles.vertical}>
<WorkspaceHeader workspace={workspace} />
<WorkspaceHeader organization={organization} project={project} workspace={workspace} />
<div className={styles.horizontal}>
<div className={styles.sidebarContainer}>
<WorkspaceSection title="Applications">
Expand Down Expand Up @@ -54,17 +56,19 @@ export const Workspace: React.FC<WorkspaceProps> = ({ workspace }) => {
/**
* Component for the header at the top of the workspace page
*/
export const WorkspaceHeader: React.FC<WorkspaceProps> = ({ workspace }) => {
export const WorkspaceHeader: React.FC<WorkspaceProps> = ({ organization, project, workspace }) => {
const styles = useStyles()

const projectLink = `/projects/${organization.name}/${project.name}`

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 to="javascript:;">{workspace.project_id}</Link>
<Link to={projectLink}>{project.name}</Link>
</Typography>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion site/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./Button"
export * from "./EmptyState"
export * from "./Page"
export * from "./Redirect"
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@types/express": "4.17.13",
"@types/jest": "27.4.1",
"@types/node": "14.18.12",
"@types/react": "17.0.39",
"@types/react": "17.0.40",
"@types/react-dom": "17.0.13",
"@types/superagent": "4.1.15",
"@typescript-eslint/eslint-plugin": "4.33.0",
Expand Down
22 changes: 16 additions & 6 deletions site/pages/projects/[organization]/[project]/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,36 @@ import { useUser } from "../../../../contexts/UserContext"
import { ErrorSummary } from "../../../../components/ErrorSummary"
import { FullScreenLoader } from "../../../../components/Loader/FullScreenLoader"
import { CreateWorkspaceForm } from "../../../../forms/CreateWorkspaceForm"
import { unsafeSWRArgument } from "../../../../util"

const CreateWorkspacePage: React.FC = () => {
const { organization, project: projectName } = useParams()
const { organization: organizationName, project: projectName } = useParams()
const navigate = useNavigate()
const styles = useStyles()
const { me } = useUser(/* redirectOnError */ true)
const { data: project, error: projectError } = useSWR<API.Project, Error>(
`/api/v2/projects/${organization}/${projectName}`,

const { data: organizationInfo, error: organizationError } = useSWR<API.Organization, Error>(
() => `/api/v2/users/me/organizations/${organizationName}`,
)

const { data: project, error: projectError } = useSWR<API.Project, Error>(() => {
return `/api/v2/organizations/${unsafeSWRArgument(organizationInfo).id}/projects/${projectName}`
})

const onCancel = useCallback(async () => {
navigate(`/projects/${organization}/${projectName}`)
}, [navigate, organization, projectName])
navigate(`/projects/${organizationName}/${projectName}`)
}, [navigate, organizationName, projectName])

const onSubmit = async (req: API.CreateWorkspaceRequest) => {
const workspace = await API.Workspace.create(req)
navigate(`/workspaces/me/${workspace.name}`)
navigate(`/workspaces/${workspace.id}`)
return workspace
}

if (organizationError) {
return <ErrorSummary error={organizationError} />
}

if (projectError) {
return <ErrorSummary error={projectError} />
}
Expand Down
42 changes: 29 additions & 13 deletions site/pages/projects/[organization]/[project]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Paper from "@material-ui/core/Paper"
import { Link, useNavigate, useParams } from "react-router-dom"
import useSWR from "swr"

import { Project, Workspace } from "../../../../api"
import { Organization, Project, Workspace } from "../../../../api"
import { Header } from "../../../../components/Header"
import { FullScreenLoader } from "../../../../components/Loader/FullScreenLoader"
import { Navbar } from "../../../../components/Navbar"
Expand All @@ -14,20 +14,31 @@ import { useUser } from "../../../../contexts/UserContext"
import { ErrorSummary } from "../../../../components/ErrorSummary"
import { firstOrItem } from "../../../../util/array"
import { EmptyState } from "../../../../components/EmptyState"
import { unsafeSWRArgument } from "../../../../util"

const ProjectPage: React.FC = () => {
const styles = useStyles()
const { me, signOut } = useUser(true)
const navigate = useNavigate()
const { project, organization } = useParams()
const { project: projectName, organization: organizationName } = useParams()

const { data: projectInfo, error: projectError } = useSWR<Project, Error>(
() => `/api/v2/projects/${organization}/${project}`,
const { data: organizationInfo, error: organizationError } = useSWR<Organization, Error>(
() => `/api/v2/users/me/organizations/${organizationName}`,
)
const { data: workspaces, error: workspacesError } = useSWR<Workspace[], Error>(
() => `/api/v2/projects/${organization}/${project}/workspaces`,

const { data: projectInfo, error: projectError } = useSWR<Project, Error>(
() => `/api/v2/organizations/${unsafeSWRArgument(organizationInfo).id}/projects/${projectName}`,
)

// TODO: The workspaces endpoint was recently changed, so that we can't get
// workspaces per-project. This just grabs all workspaces... and then
// later filters them to match the current project.
const { data: workspaces, error: workspacesError } = useSWR<Workspace[], Error>(() => `/api/v2/users/me/workspaces`)

if (organizationError) {
return <ErrorSummary error={organizationError} />
}

if (projectError) {
return <ErrorSummary error={projectError} />
}
Expand All @@ -41,7 +52,7 @@ const ProjectPage: React.FC = () => {
}

const createWorkspace = () => {
navigate(`/projects/${organization}/${project}/create`)
navigate(`/projects/${organizationName}/${projectName}/create`)
}

const emptyState = (
Expand All @@ -59,26 +70,31 @@ const ProjectPage: React.FC = () => {
{
key: "name",
name: "Name",
renderer: (nameField: string) => {
return <Link to={`/workspaces/me/${nameField}`}>{nameField}</Link>
renderer: (nameField: string, workspace: Workspace) => {
return <Link to={`/workspaces/${workspace.id}`}>{nameField}</Link>

},
},
]

const perProjectWorkspaces = workspaces.filter((workspace) => {
return workspace.project_id === projectInfo.id
})

const tableProps = {
title: "Workspaces",
columns,
data: workspaces,
data: perProjectWorkspaces,
emptyState: emptyState,
}

return (
<div className={styles.root}>
<Navbar user={me} onSignOut={signOut} />
<Header
title={firstOrItem(project, "")}
description={firstOrItem(organization, "")}
subTitle={`${workspaces.length} workspaces`}
title={firstOrItem(projectName, "")}
description={firstOrItem(organizationName, "")}
subTitle={`${perProjectWorkspaces.length} workspaces`}
action={{
text: "Create Workspace",
onClick: createWorkspace,
Expand Down
69 changes: 0 additions & 69 deletions site/pages/workspaces/[user]/[workspace].tsx

This file was deleted.

76 changes: 76 additions & 0 deletions site/pages/workspaces/[workspace].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React from "react"
import useSWR from "swr"
import { makeStyles } from "@material-ui/core/styles"
import { useParams } from "react-router-dom"
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 { workspace: workspaceQueryParam } = useParams()
const { me, signOut } = useUser(true)

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
2 changes: 2 additions & 0 deletions site/util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./array"
export * from "./swr"
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.