Skip to content

feat: move proxy settings page to deployment options #8246

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 30 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
76fb28f
feat: Move workspace proxy page to deployment options
Emyrk Jun 27, 2023
117f1b8
WorkspaceProxy response extends region
Emyrk Jun 27, 2023
731e64d
chore: Bad UI, but this does show all warnings/errors for a proxy
Emyrk Jun 27, 2023
918b7d1
add comment
Emyrk Jun 27, 2023
ed2e564
Remove messages
Emyrk Jun 28, 2023
c351a22
add recursive inline for anon embedded structs
Emyrk Jun 28, 2023
2e1f196
Revert column to url
Emyrk Jun 28, 2023
08db88a
make fmt/gen/lint
Emyrk Jun 28, 2023
5cbcbae
Fix jest mock
Emyrk Jun 28, 2023
ee33895
workspace proxy mock
Emyrk Jun 28, 2023
b7605d7
Remove log
Emyrk Jun 28, 2023
0c05228
WIP: progress indicator on latency refresh, keep menu open
Emyrk Jun 28, 2023
356554e
Remove excess
Emyrk Jun 29, 2023
37ec7f6
Fix with server side loaded data
Emyrk Jun 29, 2023
ec7c755
Support generic slices in typesgenerated
Emyrk Jun 29, 2023
bd3609a
Uniform region and proxy responses
Emyrk Jun 29, 2023
6c99694
Fetch privledged data if the user can
Emyrk Jun 29, 2023
4aecfbf
Decide which response based on perms
Emyrk Jun 29, 2023
378344f
Merge remote-tracking branch 'origin/main' into stevenmasley/proxy_pa…
Emyrk Jun 29, 2023
fa9b6f5
Formatting
Emyrk Jun 29, 2023
bfd77c8
Fix tests
Emyrk Jun 29, 2023
b3ce0d9
fixup! Fix tests
Emyrk Jun 29, 2023
11163d2
Fix js mock rest endpoint
Emyrk Jun 29, 2023
86ac8b3
Formatting
Emyrk Jun 29, 2023
680e8ab
Fix JS mock rest response
Emyrk Jun 29, 2023
21aac1b
Navbar now needs auth
Emyrk Jun 29, 2023
0a8fbc1
Merge remote-tracking branch 'origin/main' into stevenmasley/proxy_pa…
Emyrk Jun 30, 2023
05ac587
Merge remote-tracking branch 'origin/main' into stevenmasley/proxy_pa…
Emyrk Jun 30, 2023
7d421b9
Reduce LOC, pr feedback
Emyrk Jun 30, 2023
f9786e3
Nil guard
Emyrk Jun 30, 2023
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
33 changes: 24 additions & 9 deletions cli/cliui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,39 @@ func DisplayTable(out any, sort string, filterColumns []string) (string, error)
// returned. If the table tag is malformed, an error is returned.
//
// The returned name is transformed from "snake_case" to "normal text".
func parseTableStructTag(field reflect.StructField) (name string, defaultSort, recursive bool, err error) {
func parseTableStructTag(field reflect.StructField) (name string, defaultSort, recursive bool, skipParentName bool, err error) {
tags, err := structtag.Parse(string(field.Tag))
if err != nil {
return "", false, false, xerrors.Errorf("parse struct field tag %q: %w", string(field.Tag), err)
return "", false, false, false, xerrors.Errorf("parse struct field tag %q: %w", string(field.Tag), err)
}

tag, err := tags.Get("table")
if err != nil || tag.Name == "-" {
// tags.Get only returns an error if the tag is not found.
return "", false, false, nil
return "", false, false, false, nil
}

defaultSortOpt := false
recursiveOpt := false
skipParentNameOpt := false
for _, opt := range tag.Options {
switch opt {
case "default_sort":
defaultSortOpt = true
case "recursive":
recursiveOpt = true
case "recursive_inline":
// recursive_inline is a helper to make recursive tables look nicer.
// It skips prefixing the parent name to the child name. If you do this,
// make sure the child name is unique across all nested structs in the parent.
recursiveOpt = true
skipParentNameOpt = true
Comment on lines +212 to +217
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 had to do this to make the table names nice. Otherwise it is like Proxy Region Url instead of just URL

default:
return "", false, false, xerrors.Errorf("unknown option %q in struct field tag", opt)
return "", false, false, false, xerrors.Errorf("unknown option %q in struct field tag", opt)
}
}

return strings.ReplaceAll(tag.Name, "_", " "), defaultSortOpt, recursiveOpt, nil
return strings.ReplaceAll(tag.Name, "_", " "), defaultSortOpt, recursiveOpt, skipParentNameOpt, nil
}

func isStructOrStructPointer(t reflect.Type) bool {
Expand All @@ -235,7 +242,7 @@ func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
defaultSortName := ""
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
name, defaultSort, recursive, err := parseTableStructTag(field)
name, defaultSort, recursive, skip, err := parseTableStructTag(field)
if err != nil {
return nil, "", xerrors.Errorf("parse struct tags for field %q in type %q: %w", field.Name, t.String(), err)
}
Expand All @@ -260,7 +267,11 @@ func typeToTableHeaders(t reflect.Type) ([]string, string, error) {
return nil, "", xerrors.Errorf("get child field header names for field %q in type %q: %w", field.Name, fieldType.String(), err)
}
for _, childName := range childNames {
headers = append(headers, fmt.Sprintf("%s %s", name, childName))
fullName := fmt.Sprintf("%s %s", name, childName)
if skip {
fullName = childName
}
headers = append(headers, fullName)
}
continue
}
Expand Down Expand Up @@ -296,7 +307,7 @@ func valueToTableMap(val reflect.Value) (map[string]any, error) {
for i := 0; i < val.NumField(); i++ {
field := val.Type().Field(i)
fieldVal := val.Field(i)
name, _, recursive, err := parseTableStructTag(field)
name, _, recursive, skip, err := parseTableStructTag(field)
if err != nil {
return nil, xerrors.Errorf("parse struct tags for field %q in type %T: %w", field.Name, val, err)
}
Expand All @@ -318,7 +329,11 @@ func valueToTableMap(val reflect.Value) (map[string]any, error) {
return nil, xerrors.Errorf("get child field values for field %q in type %q: %w", field.Name, fieldType.String(), err)
}
for childName, childValue := range childMap {
row[fmt.Sprintf("%s %s", name, childName)] = childValue
fullName := fmt.Sprintf("%s %s", name, childName)
if skip {
fullName = childName
}
row[fullName] = childValue
}
continue
}
Expand Down
30 changes: 30 additions & 0 deletions cli/cliui/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ type tableTest3 struct {
Sub tableTest2 `table:"inner,recursive,default_sort"`
}

type tableTest4 struct {
Inline tableTest2 `table:"ignored,recursive_inline"`
SortField string `table:"sort_field,default_sort"`
}

func Test_DisplayTable(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -188,6 +193,31 @@ foo foo1 foo3 2022-08-02T15:49:10Z
compareTables(t, expected, out)
})

t.Run("Inline", func(t *testing.T) {
t.Parallel()

expected := `
NAME AGE
Alice 25
`

inlineIn := []tableTest4{
{
Inline: tableTest2{
Name: stringWrapper{
str: "Alice",
},
Age: 25,
NotIncluded: "IgnoreMe",
},
},
}
out, err := cliui.DisplayTable(inlineIn, "", []string{"name", "age"})
log.Println("rendered table:\n" + out)
Copy link
Member

Choose a reason for hiding this comment

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

Is this log intentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's helpful to build the expected output. Test logs only log in the error case by default (unless you do go test -v)

require.NoError(t, err)
compareTables(t, expected, out)
})

// This test ensures that safeties against invalid use of `table` tags
// causes errors (even without data).
t.Run("Errors", func(t *testing.T) {
Expand Down
32 changes: 23 additions & 9 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 23 additions & 9 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions coderd/workspaceproxies.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (api *API) PrimaryWorkspaceProxy(ctx context.Context) (database.WorkspacePr
// @Security CoderSessionToken
// @Produce json
// @Tags WorkspaceProxies
// @Success 200 {object} codersdk.RegionsResponse
// @Success 200 {object} codersdk.RegionsResponse[codersdk.Region]
// @Router /regions [get]
func (api *API) regions(rw http.ResponseWriter, r *http.Request) {
ctx := r.Context()
Expand All @@ -87,7 +87,7 @@ func (api *API) regions(rw http.ResponseWriter, r *http.Request) {
return
}

httpapi.Write(ctx, rw, http.StatusOK, codersdk.RegionsResponse{
httpapi.Write(ctx, rw, http.StatusOK, codersdk.RegionsResponse[codersdk.Region]{
Regions: []codersdk.Region{region},
})
}
Loading