Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

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

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

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

5 changes: 4 additions & 1 deletion coderd/database/queries.sql.go

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

3 changes: 2 additions & 1 deletion coderd/database/queries/templateversions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ UPDATE
SET
template_id = $2,
updated_at = $3,
name = $4
name = $4,
message = $5
WHERE
id = $1 RETURNING *;

Expand Down
5 changes: 5 additions & 0 deletions coderd/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ func (api *API) patchTemplateVersion(rw http.ResponseWriter, r *http.Request) {
TemplateID: templateVersion.TemplateID,
UpdatedAt: database.Now(),
Name: templateVersion.Name,
Message: templateVersion.Message,
}

if params.Name != "" {
updateParams.Name = params.Name
}

if params.Message != "" {
updateParams.Message = params.Message
}

errTemplateVersionNameConflict := xerrors.New("template version name must be unique for a template")

var updatedTemplateVersion database.TemplateVersion
Expand Down
3 changes: 2 additions & 1 deletion codersdk/templateversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ type TemplateVersionVariable struct {
}

type PatchTemplateVersionRequest struct {
Name string `json:"name" validate:"omitempty,template_version_name"`
Name string `json:"name" validate:"omitempty,template_version_name"`
Message string `json:"message" validate:"omitempty"`
}

// TemplateVersion returns a template version by ID.
Expand Down
8 changes: 5 additions & 3 deletions docs/api/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -3222,15 +3222,17 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in

```json
{
"message": "string",
"name": "string"
}
```

### Properties

| Name | Type | Required | Restrictions | Description |
| ------ | ------ | -------- | ------------ | ----------- |
| `name` | string | false | | |
| Name | Type | Required | Restrictions | Description |
| --------- | ------ | -------- | ------------ | ----------- |
| `message` | string | false | | |
| `name` | string | false | | |

## codersdk.PatchWorkspaceProxy

Expand Down
1 change: 1 addition & 0 deletions docs/api/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,7 @@ curl -X PATCH http://coder-server:8080/api/v2/templateversions/{templateversion}

```json
{
"message": "string",
"name": "string"
}
```
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 @@ -644,6 +644,7 @@ export interface PatchGroupRequest {
// From codersdk/templateversions.go
export interface PatchTemplateVersionRequest {
readonly name: string
readonly message: string
}

// From codersdk/workspaceproxy.go
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export const PublishTemplateVersionDialog: FC<
const form = useFormik({
initialValues: {
name: defaultName,
message: "",
isActiveVersion: false,
},
validationSchema: Yup.object({
name: Yup.string().required(),
message: Yup.string(),
isActiveVersion: Yup.boolean(),
}),
onSubmit: onConfirm,
Expand Down Expand Up @@ -70,6 +72,16 @@ export const PublishTemplateVersionDialog: FC<
disabled={isPublishing}
/>

<TextField
{...getFieldHelpers("message")}
label="Message"
placeholder="Write a short message about the changes you made..."
autoFocus
disabled={isPublishing}
multiline
rows={5}
/>

<FormControlLabel
label="Promote to default version"
control={
Expand Down
66 changes: 0 additions & 66 deletions site/src/components/Tooltips/OutdatedHelpTooltip.tsx

This file was deleted.

138 changes: 138 additions & 0 deletions site/src/components/Tooltips/WorkspaceOutdatedTooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import RefreshIcon from "@mui/icons-material/Refresh"
import { FC } from "react"
import {
HelpTooltip,
HelpTooltipAction,
HelpTooltipLinksGroup,
HelpTooltipText,
HelpTooltipTitle,
} from "./HelpTooltip"
import InfoIcon from "@mui/icons-material/InfoOutlined"
import { makeStyles } from "@mui/styles"
import { colors } from "theme/colors"
import { useQuery } from "@tanstack/react-query"
import { getTemplate, getTemplateVersion } from "api/api"
import Box from "@mui/material/Box"
import Skeleton from "@mui/material/Skeleton"
import Link from "@mui/material/Link"

export const Language = {
outdatedLabel: "Outdated",
versionTooltipText:
"This workspace version is outdated and a newer version is available.",
updateVersionLabel: "Update version",
}

interface TooltipProps {
onUpdateVersion: () => void
templateId: string
ariaLabel?: string
}

export const WorkspaceOutdatedTooltip: FC<TooltipProps> = ({
onUpdateVersion,
ariaLabel,
templateId,
}) => {
const styles = useStyles()
const { data: activeVersion } = useQuery({
queryFn: async () => {
const template = await getTemplate(templateId)
const activeVersion = await getTemplateVersion(template.active_version_id)
return activeVersion
},
queryKey: ["templates", templateId, "activeVersion"],
})

return (
<HelpTooltip
size="small"
icon={InfoIcon}
iconClassName={styles.icon}
buttonClassName={styles.button}
>
<HelpTooltipTitle>{Language.outdatedLabel}</HelpTooltipTitle>
<HelpTooltipText>{Language.versionTooltipText}</HelpTooltipText>

<Box
sx={{
display: "flex",
flexDirection: "column",
gap: 1,
py: 1,
fontSize: 13,
}}
>
<Box>
<Box
sx={{
color: (theme) => theme.palette.text.primary,
fontWeight: 600,
}}
>
New version
</Box>
<Box>
{activeVersion ? (
<Link
href={`/templates/docker/versions/${activeVersion.name}`}
target="_blank"
sx={{ color: (theme) => theme.palette.primary.light }}
>
{activeVersion.name}
</Link>
) : (
<Skeleton variant="text" height={20} width={100} />
)}
</Box>
</Box>

<Box>
<Box
sx={{
color: (theme) => theme.palette.text.primary,
fontWeight: 600,
}}
>
Message
</Box>
<Box>
{activeVersion ? (
activeVersion.message === "" ? (
"No message"
) : (
activeVersion.message
)
) : (
<Skeleton variant="text" height={20} width={150} />
)}
</Box>
</Box>
</Box>

<HelpTooltipLinksGroup>
<HelpTooltipAction
icon={RefreshIcon}
onClick={onUpdateVersion}
ariaLabel={ariaLabel}
>
{Language.updateVersionLabel}
</HelpTooltipAction>
</HelpTooltipLinksGroup>
</HelpTooltip>
)
}

const useStyles = makeStyles(() => ({
icon: {
color: colors.yellow[5],
},

button: {
opacity: 1,

"&:hover": {
opacity: 1,
},
},
}))
2 changes: 1 addition & 1 deletion site/src/components/Tooltips/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { AuditHelpTooltip } from "./AuditHelpTooltip"
export { OutdatedHelpTooltip } from "./OutdatedHelpTooltip"
export { WorkspaceOutdatedTooltip } from "./WorkspaceOutdatedTooltip"
export { UserRoleHelpTooltip } from "./UserRoleHelpTooltip"
export { WorkspaceHelpTooltip } from "./WorkspaceHelpTooltip"
5 changes: 3 additions & 2 deletions site/src/components/WorkspaceStats/WorkspaceStats.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link from "@mui/material/Link"
import { OutdatedHelpTooltip } from "components/Tooltips"
import { WorkspaceOutdatedTooltip } from "components/Tooltips"
import { FC, useRef, useState } from "react"
import { Link as RouterLink } from "react-router-dom"
import { createDayString } from "utils/createDayString"
Expand Down Expand Up @@ -101,7 +101,8 @@ export const WorkspaceStats: FC<WorkspaceStatsProps> = ({
</Link>

{workspace.outdated && (
<OutdatedHelpTooltip
<WorkspaceOutdatedTooltip
templateId={workspace.template_id}
onUpdateVersion={handleUpdate}
ariaLabel="update version"
/>
Expand Down
5 changes: 3 additions & 2 deletions site/src/components/WorkspacesTable/WorkspacesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useNavigate } from "react-router-dom"
import { getDisplayWorkspaceTemplateName } from "utils/workspace"
import { LastUsed } from "../LastUsed/LastUsed"
import { Workspace } from "api/typesGenerated"
import { OutdatedHelpTooltip } from "components/Tooltips/OutdatedHelpTooltip"
import { WorkspaceOutdatedTooltip } from "components/Tooltips/WorkspaceOutdatedTooltip"
import { Avatar } from "components/Avatar/Avatar"
import { Stack } from "components/Stack/Stack"
import { useClickableTableRow } from "hooks/useClickableTableRow"
Expand All @@ -34,7 +34,8 @@ export const WorkspacesRow: FC<{
<Stack direction="row" spacing={0} alignItems="center">
{workspace.name}
{workspace.outdated && (
<OutdatedHelpTooltip
<WorkspaceOutdatedTooltip
templateId={workspace.template_id}
onUpdateVersion={() => {
onUpdateWorkspace(workspace)
}}
Expand Down
Loading