Skip to content

feat: UX - Initial create form flow #33

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

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
18dd18f
Add several dependencies needed for API routes
bryphe-coder Jan 19, 2022
7329cca
Add placeholder API and projectService
bryphe-coder Jan 19, 2022
6726f40
Create initial workspaces API
bryphe-coder Jan 19, 2022
3f932c2
Port over SafeHydrate component
bryphe-coder Jan 19, 2022
6fdb43f
Stub pages for workspace creation
bryphe-coder Jan 19, 2022
97b2383
Add missed favicons
bryphe-coder Jan 19, 2022
086d533
Formatting
bryphe-coder Jan 19, 2022
82989d3
Merge branch 'bryphe/fix/css-hydration-errors' into bryphe/feat/initi…
bryphe-coder Jan 19, 2022
c305c8d
Initial select page
bryphe-coder Jan 19, 2022
cc411d0
Flip to light theme
bryphe-coder Jan 19, 2022
907a523
Start pulling out AppPage/FormPage
bryphe-coder Jan 19, 2022
56f7515
Start stubbing out API
bryphe-coder Jan 19, 2022
0a5c48a
Start scaffolding project selection
bryphe-coder Jan 19, 2022
aea58ae
Add placeholder icon if none available
bryphe-coder Jan 19, 2022
c92e454
Revert prototyping changes
bryphe-coder Jan 19, 2022
be4c90f
Revert sum changes
bryphe-coder Jan 19, 2022
308de2b
Initial create form
bryphe-coder Jan 19, 2022
d0b0ef1
Rename project function
bryphe-coder Jan 19, 2022
797c82b
Add formik
bryphe-coder Jan 19, 2022
5016b9a
Stub create workspace API
bryphe-coder Jan 19, 2022
8da382b
Hook up formik to create form
bryphe-coder Jan 20, 2022
6fc0a54
Initial shared loading logic
bryphe-coder Jan 20, 2022
e57d1b6
Set up dynamic form components
bryphe-coder Jan 20, 2022
08010c3
Remove leftover buildmode pkg
bryphe-coder Jan 20, 2022
8800445
Add note in api that this is temporary
bryphe-coder Jan 20, 2022
496b42e
Factor ProjectName to separate file
bryphe-coder Jan 20, 2022
646206e
Fix useStyles naming
bryphe-coder Jan 20, 2022
4b6f1c5
Remove accidentally duplicated SafeHydrate
bryphe-coder Jan 20, 2022
961a44b
Remove addition of srverr package
bryphe-coder Jan 20, 2022
eb46f4c
Fix usage of render prop pattern
bryphe-coder Jan 20, 2022
840a796
Fix some compilation issues
bryphe-coder Jan 20, 2022
f20171f
Clean up imports
bryphe-coder Jan 20, 2022
03236df
Add some initial form tests
bryphe-coder Jan 20, 2022
61cd37f
Add smoke test for ProjectIcon
bryphe-coder Jan 20, 2022
99d0a95
Add AppPage smoke test
bryphe-coder Jan 20, 2022
d52bd38
Fix up formatting
bryphe-coder Jan 20, 2022
76d11d4
Remove api from collection metrics since it is temporary
bryphe-coder Jan 20, 2022
ffac475
Clean up unused import
bryphe-coder Jan 20, 2022
e95d75f
Remove and consolidate form ty pes
bryphe-coder Jan 22, 2022
3e8069b
Formatting
bryphe-coder Jan 22, 2022
9492e8e
Merge master
bryphe-coder Jan 22, 2022
e5e02f9
Clean-up utilities
bryphe-coder Jan 22, 2022
5e4a44f
Revert "Remove and consolidate form ty pes"
bryphe-coder Jan 22, 2022
6fe7141
Merge branch 'main' into bryphe/feat/initial-create-form
bryphe-coder Jan 22, 2022
8343ef0
First round of lint failures
bryphe-coder Jan 22, 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
Create initial workspaces API
  • Loading branch information
bryphe-coder committed Jan 19, 2022
commit 6726f40cf0ddfa7e4ec6bcf876a95d5768343d9c
10 changes: 5 additions & 5 deletions coderd/api.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package coderd

import "context"

// API offers an HTTP API. Routes are located in routes.go.
type API struct {
// Services.
projectService *projectService
projectService *projectService
workspaceService *workspaceService
}

// New returns an instantiated API.
func NewAPI(ctx context.Context) *API {
func NewAPI() *API {
api := &API{
projectService: newProjectService(),
projectService: newProjectService(),
workspaceService: newWorkspaceService(),
}
return api
}
14 changes: 12 additions & 2 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package coderd

import (
"context"
"net/http"

"cdr.dev/slog"
Expand All @@ -24,7 +23,7 @@ const (

// New constructs the Coder API into an HTTP handler.
func New(options *Options) http.Handler {
api := NewAPI(context.Background())
api := NewAPI()
r := chi.NewRouter()
r.Route("/api/v2", func(r chi.Router) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -43,6 +42,17 @@ func New(options *Options) http.Handler {
// TODO: Extract organization and add to context
r.Get("/", api.projectService.getProjects)
r.Post("/", api.projectService.createProject)

r.Get("/{projectId}", api.projectService.getProjectById)
// TODO: Get project by id
})
})

// Workspaces endpoint
r.Route("/workspaces", func(r chi.Router) {
r.Route("/{organization}", func(r chi.Router) {
r.Get("/", api.workspaceService.getWorkspaces)
r.Get("/{projectId}", api.workspaceService.getWorkspaceById)
})
})

Expand Down
7 changes: 5 additions & 2 deletions coderd/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func newProjectService() *projectService {
}

func (ps *projectService) getProjects(w http.ResponseWriter, r *http.Request) {

// Construct a couple hard-coded projects to return the UI

terraformProject := Project{
Id: "test_terraform_project_id",
Name: "Terraform",
Expand Down Expand Up @@ -81,6 +79,11 @@ func (ps *projectService) getProjects(w http.ResponseWriter, r *http.Request) {
xjson.Write(w, http.StatusOK, projects)
}

func (ps *projectService) getProjectById(w http.ResponseWriter, r *http.Request) {
// TODO: Get a project by id
xjson.Write(w, http.StatusNotFound, nil)
}

func (ps *projectService) createProject(w http.ResponseWriter, r *http.Request) {
// TODO: Validate arguments
// Organization context
Expand Down
48 changes: 48 additions & 0 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package coderd

import (
"net/http"

"github.com/coder/coder/xjson"
)

type Workspace struct {
Id string `json:"id" validate:"required"`
Name string `json:"name" validate:"required"`
ProjectId string `json:"project_id" validate:"required"`
}

// Placeholder type of workspaceService
type workspaceService struct {
}

func newWorkspaceService() *workspaceService {
workspaceService := &workspaceService{}
return workspaceService
}

func (ws *workspaceService) getWorkspaces(w http.ResponseWriter, r *http.Request) {
// Dummy workspace to return
workspace := Workspace{
Id: "test-workspace",
Name: "Test Workspace",
ProjectId: "test-project-id",
}

workspaces := []Workspace{
workspace,
}

xjson.Write(w, http.StatusOK, workspaces)
}

func (ws *workspaceService) getWorkspaceById(w http.ResponseWriter, r *http.Request) {
// TODO: Read workspace off context
// Dummy workspace to return
workspace := Workspace{
Id: "test-workspace",
Name: "Test Workspace",
ProjectId: "test-project-id",
}
xjson.Write(w, http.StatusOK, workspace)
}