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 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'main' into workspacepage
  • Loading branch information
kylecarbs committed May 16, 2022
commit f606a5143da8bd9f43c5a21c5d475aed7688faf7
2 changes: 1 addition & 1 deletion .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
with:
go-version: "~1.18"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.1.0
uses: golangci/golangci-lint-action@v3.2.0
with:
version: v1.46.0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Docker Login
uses: docker/login-action@v1
Expand Down
10 changes: 9 additions & 1 deletion cli/autostart.go
Original file line number Diff line number Diff line change
10000 Expand Up @@ -63,7 +63,15 @@ func autostartShow() *cobra.Command {
return nil
}

_, _ = fmt.Fprintf(cmd.OutOrStdout(), "schedule: %s\nnext: %s\n", workspace.AutostartSchedule, validSchedule.Next(time.Now()))
next := validSchedule.Next(time.Now())
loc, _ := time.LoadLocation(validSchedule.Timezone())

_, _ = fmt.Fprintf(cmd.OutOrStdout(),
"schedule: %s\ntimezone: %s\nnext: %s\n",
validSchedule.Cron(),
validSchedule.Timezone(),
next.In(loc),
)

return nil
},
Expand Down
3 changes: 2 additions & 1 deletion cli/autostart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func TestAutostart(t *testing.T) {

err = cmd.Execute()
require.NoError(t, err, "unexpected error")
require.Contains(t, stdoutBuf.String(), "schedule: "+sched)
// CRON_TZ gets stripped
require.Contains(t, stdoutBuf.String(), "schedule: 30 17 * * 1-5")
})

t.Run("EnableDisableOK", func(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion cli/autostop.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ func autostopShow() *cobra.Command {
return nil
}

_, _ = fmt.Fprintf(cmd.OutOrStdout(), "schedule: %s\nnext: %s\n", workspace.AutostopSchedule, validSchedule.Next(time.Now()))
next := validSchedule.Next(time.Now())
loc, _ := time.LoadLocation(validSchedule.Timezone())

_, _ = fmt.Fprintf(cmd.OutOrStdout(),
"schedule: %s\ntimezone: %s\nnext: %s\n",
validSchedule.Cron(),
validSchedule.Timezone(),
next.In(loc),
)

return nil
},
Expand Down
3 changes: 2 additions & 1 deletion cli/autostop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func TestAutostop(t *testing.T) {

err = cmd.Execute()
require.NoError(t, err, "unexpected error")
require.Contains(t, stdoutBuf.String(), "schedule: "+sched)
// CRON_TZ gets stripped
require.Contains(t, stdoutBuf.String(), "schedule: 30 17 * * 1-5")
})

t.Run("EnableDisableOK", func(t *testing.T) {
Expand Down
13 changes: 9 additions & 4 deletions cli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"

"github.com/coder/coder/cli/cliui"
"github.com/coder/coder/coderd/autobuild/schedule"
"github.com/coder/coder/coderd/database"
"github.com/coder/coder/codersdk"
)
Expand Down Expand Up @@ -108,14 +109,18 @@ func list() *cobra.Command {
durationDisplay = durationDisplay[:len(durationDisplay)-2]
}

autostartDisplay := "not enabled"
autostartDisplay := "-"
if workspace.AutostartSchedule != "" {
autostartDisplay = workspace.AutostartSchedule
if sched, err := schedule.Weekly(workspace.AutostartSchedule); err == nil {
autostartDisplay = sched.Cron()
}
}

autostopDisplay := "not enabled"
autostopDisplay := "-"
if workspace.AutostopSchedule != "" {
autostopDisplay = workspace.AutostopSchedule
if sched, err := schedule.Weekly(workspace.AutostopSchedule); err == nil {
autostopDisplay = sched.Cron()
}
}

user := usersByID[workspace.OwnerID]
Expand Down
38 changes: 38 additions & 0 deletions coderd/audit/diff.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package audit

import (
"database/sql"
"fmt"
"reflect"

"github.com/google/uuid"
)

// TODO: this might need to be in the database package.
Expand Down Expand Up @@ -64,6 +67,11 @@ func diffValues[T any](left, right T, table Table) Map {
continue
}

// coerce struct types that would produce bad diffs.
if leftI, rightI, ok = convertDiffType(leftI, rightI); ok {
leftF, rightF = reflect.ValueOf(leftI), reflect.ValueOf(rightI)
}

// If the field is a pointer, dereference it. Nil pointers are coerced
// to the zero value of their underlying type.
if leftF.Kind() == reflect.Ptr && rightF.Kind() == reflect.Ptr {
Expand All @@ -90,6 +98,36 @@ func diffValues[T any](left, right T, table Table) Map {
return baseDiff
}

// convertDiffType converts external struct types to primitive types.
//nolint:forcetypeassert
func convertDiffType(left, right any) (newLeft, newRight any, changed bool) {
switch typed := left.(type) {
case uuid.UUID:
return typed.String(), right.(uuid.UUID).String(), true

case uuid.NullUUID:
leftStr, _ := typed.MarshalText()
rightStr, _ := right.(uuid.NullUUID).MarshalText()
return string(leftStr), string(rightStr), true

case sql.NullString:
leftStr := typed.String
if !typed.Valid {
leftStr = "null"
}

rightStr := right.(sql.NullString).String
if !right.(sql.NullString).Valid {
rightStr = "null"
}

return leftStr, rightStr, true

default:
return left, right, false
}
}

// derefPointer deferences a reflect.Value that is a pointer to its underlying
// value. It dereferences recursively until it finds a non-pointer value. If the
// pointer is nil, it will be coerced to the zero value of the underlying type.
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.
0