Skip to content

feat: show template.display_name on Workspace pages #5082

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 6 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
29 changes: 15 additions & 14 deletions coderd/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,20 +1011,21 @@ func convertWorkspace(

ttlMillis := convertWorkspaceTTLMillis(workspace.Ttl)
return codersdk.Workspace{
ID: workspace.ID,
CreatedAt: workspace.CreatedAt,
UpdatedAt: workspace.UpdatedAt,
OwnerID: workspace.OwnerID,
OwnerName: owner.Username,
TemplateID: workspace.TemplateID,
LatestBuild: workspaceBuild,
TemplateName: template.Name,
TemplateIcon: template.Icon,
Outdated: workspaceBuild.TemplateVersionID.String() != template.ActiveVersionID.String(),
Name: workspace.Name,
AutostartSchedule: autostartSchedule,
TTLMillis: ttlMillis,
LastUsedAt: workspace.LastUsedAt,
ID: workspace.ID,
CreatedAt: workspace.CreatedAt,
UpdatedAt: workspace.UpdatedAt,
OwnerID: workspace.OwnerID,
OwnerName: owner.Username,
TemplateID: workspace.TemplateID,
LatestBuild: workspaceBuild,
TemplateName: template.Name,
TemplateIcon: template.Icon,
TemplateDisplayName: template.DisplayName,
Outdated: workspaceBuild.TemplateVersionID.String() != template.ActiveVersionID.String(),
Name: workspace.Name,
AutostartSchedule: autostartSchedule,
TTLMillis: ttlMillis,
LastUsedAt: workspace.LastUsedAt,
}
}

Expand Down
30 changes: 30 additions & 0 deletions coderd/workspaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,36 @@ func TestWorkspace(t *testing.T) {
})
require.Error(t, err, "workspace rename should have failed")
})

t.Run("TemplateProperties", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)

const templateIcon = "/img/icon.svg"
const templateDisplayName = "This is template"
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
ctr.Icon = templateIcon
ctr.DisplayName = templateDisplayName
})
require.NotEmpty(t, template.Name)
require.NotEmpty(t, template.DisplayName)
require.NotEmpty(t, template.Icon)
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

ws, err := client.Workspace(ctx, workspace.ID)
require.NoError(t, err)
assert.Equal(t, user.UserID, ws.LatestBuild.InitiatorID)
assert.Equal(t, codersdk.BuildReasonInitiator, ws.LatestBuild.Reason)
assert.Equal(t, template.Name, ws.TemplateName)
assert.Equal(t, templateIcon, ws.TemplateIcon)
assert.Equal(t, templateDisplayName, ws.TemplateDisplayName)
})
}

func TestAdminViewAllWorkspaces(t *testing.T) {
Expand Down
29 changes: 15 additions & 14 deletions codersdk/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ import (
// Workspace is a deployment of a template. It references a specific
// version and can be updated.
type Workspace struct {
ID uuid.UUID `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
OwnerID uuid.UUID `json:"owner_id"`
OwnerName string `json:"owner_name"`
TemplateID uuid.UUID `json:"template_id"`
TemplateName string `json:"template_name"`
TemplateIcon string `json:"template_icon"`
LatestBuild WorkspaceBuild `json:"latest_build"`
Outdated bool `json:"outdated"`
Name string `json:"name"`
AutostartSchedule *string `json:"autostart_schedule,omitempty"`
TTLMillis *int64 `json:"ttl_ms,omitempty"`
LastUsedAt time.Time `json:"last_used_at"`
ID uuid.UUID `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
OwnerID uuid.UUID `json:"owner_id"`
OwnerName string `json:"owner_name"`
TemplateID uuid.UUID `json:"template_id"`
TemplateName string `json:"template_name"`
TemplateDisplayName string `json:"template_display_name"`
TemplateIcon string `json:"template_icon"`
LatestBuild WorkspaceBuild `json:"latest_build"`
Outdated bool `json:"outdated"`
Name string `json:"name"`
AutostartSchedule *string `json:"autostart_schedule,omitempty"`
TTLMillis *int64 `json:"ttl_ms,omitempty"`
LastUsedAt time.Time `json:"last_used_at"`
}

type WorkspacesRequest struct {
Expand Down
1 change: 1 addition & 0 deletions site/src/api/typesGenerated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,7 @@ export interface Workspace {
readonly owner_name: string
readonly template_id: string
readonly template_name: string
readonly template_display_name: string
readonly template_icon: string
readonly latest_build: WorkspaceBuild
readonly outdated: boolean
Expand Down
4 changes: 3 additions & 1 deletion site/src/components/WorkspaceStats/WorkspaceStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export const WorkspaceStats: FC<WorkspaceStatsProps> = ({
to={`/templates/${workspace.template_name}`}
className={combineClasses([styles.statsValue, styles.link])}
>
{workspace.template_name}
{workspace.template_display_name.length > 0
? workspace.template_display_name
: workspace.template_name}
</Link>
</div>
<div className={styles.statItem}>
Expand Down
6 changes: 5 additions & 1 deletion site/src/components/WorkspacesTable/WorkspacesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export const WorkspacesRow: FC<
</TableCellLink>

<TableCellLink to={workspacePageLink}>
<TableCellDataPrimary>{workspace.template_name}</TableCellDataPrimary>
<TableCellDataPrimary>
{workspace.template_display_name.length > 0
? workspace.template_display_name
: workspace.template_name}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could have a util function on utils/workspace called getWorkspaceDisplayName(workspace: Workspace): string but it is your call.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a util function.

</TableCellDataPrimary>
</TableCellLink>
<TableCellLink to={workspacePageLink}>
<TableCellData>
Expand Down
4 changes: 4 additions & 0 deletions site/src/pages/WorkspacePage/WorkspacePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ describe("WorkspacePage", () => {
t("workspaceStatus.deleted", { ns: "common" }),
)
})
it("renders the template display name", async () => {
await renderWorkspacePage()
await screen.findByText(MockWorkspace.template_display_name)
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the FE, we use Storybook for visual tests and "integration tests"(the ones run by Jest) only for testing actions. So I think we can remove this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed, thanks for the suggestion!


describe("Timeline", () => {
it("shows the timeline build", async () => {
Expand Down
9 changes: 8 additions & 1 deletion site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { screen, waitFor } from "@testing-library/react"
import { rest } from "msw"
import * as CreateDayString from "util/createDayString"
import { MockWorkspace } from "../../testHelpers/entities"
import {
MockWorkspace,
MockWorkspacesResponse,
} from "../../testHelpers/entities"
import { history, render } from "../../testHelpers/renderHelpers"
import { server } from "../../testHelpers/server"
import WorkspacesPage from "./WorkspacesPage"
Expand Down Expand Up @@ -54,5 +57,9 @@ describe("WorkspacesPage", () => {
{ timeout: 2000 },
)
await screen.findByText(`${MockWorkspace.name}1`)
const templateDisplayNames = await screen.findAllByText(
`${MockWorkspace.template_display_name}`,
)
expect(templateDisplayNames).toHaveLength(MockWorkspacesResponse.count)
})
})
1 change: 1 addition & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export const MockWorkspace: TypesGen.Workspace = {
template_id: MockTemplate.id,
template_name: MockTemplate.name,
template_icon: MockTemplate.icon,
template_display_name: MockTemplate.display_name,
outdated: false,
owner_id: MockUser.id,
owner_name: MockUser.username,
Expand Down