Skip to content

feat(site): Promote template version #6929

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 8 commits into from
Apr 3, 2023
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
Display confirmation
  • Loading branch information
BrunoQuaresma committed Mar 31, 2023
commit 83cdf19406cac58853232d344eed8d45694b680b
23 changes: 16 additions & 7 deletions site/src/components/VersionsTable/VersionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { combineClasses } from "util/combineClasses"
export interface VersionRowProps {
version: TemplateVersion
isActive: boolean
onPromoteClick?: () => void
}

export const VersionRow: React.FC<VersionRowProps> = ({
version,
isActive,
onPromoteClick,
}) => {
const styles = useStyles()
const { t } = useTranslation("templatePage")
Expand Down Expand Up @@ -69,13 +71,20 @@ export const VersionRow: React.FC<VersionRowProps> = ({
{isActive ? (
<Pill text="Active version" type="success" />
) : (
<Button
size="small"
variant="outlined"
className={styles.promoteButton}
>
Promote version
</Button>
onPromoteClick && (
<Button
size="small"
variant="outlined"
className={styles.promoteButton}
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
onPromoteClick()
}}
>
Promote version
</Button>
)
)}
</Stack>
</TableCell>
Expand Down
3 changes: 3 additions & 0 deletions site/src/components/VersionsTable/VersionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ export const Language = {

export interface VersionsTableProps {
activeVersionId: string
onPromoteClick?: () => void
versions?: TypesGen.TemplateVersion[]
}

export const VersionsTable: FC<React.PropsWithChildren<VersionsTableProps>> = ({
versions,
onPromoteClick,
activeVersionId,
}) => {
return (
Expand All @@ -37,6 +39,7 @@ export const VersionsTable: FC<React.PropsWithChildren<VersionsTableProps>> = ({
getDate={(version) => new Date(version.created_at)}
row={(version) => (
<VersionRow
onPromoteClick={onPromoteClick}
version={version}
key={version.id}
isActive={activeVersionId === version.id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { useQuery } from "@tanstack/react-query"
import { getTemplateVersions } from "api/api"
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog"
import { useTemplateLayoutContext } from "components/TemplateLayout/TemplateLayout"
import { VersionsTable } from "components/VersionsTable/VersionsTable"
import { useState } from "react"
import { Helmet } from "react-helmet-async"
import { getTemplatePageTitle } from "../utils"

const TemplateVersionsPage = () => {
const { template } = useTemplateLayoutContext()
const { template, permissions } = useTemplateLayoutContext()
const { data } = useQuery({
queryKey: ["template", "versions", template.id],
queryFn: () => getTemplateVersions(template.id),
})
const [promoteState, setPromoteState] = useState<
"idle" | "confirming" | "promoting"
>("idle")

return (
<>
Expand All @@ -19,8 +24,24 @@ const TemplateVersionsPage = () => {
</Helmet>
<VersionsTable
versions={data}
onPromoteClick={
permissions.canUpdateTemplate
? () => setPromoteState("confirming")
: undefined
}
activeVersionId={template.active_version_id}
/>
<ConfirmDialog
type="info"
hideCancel={false}
open={promoteState !== "idle"}
onConfirm={() => {}}
onClose={() => setPromoteState("idle")}
title="Promote version"
confirmLoading={promoteState === "promoting"}
confirmText="Promote"
description="Are you sure you want to promote this version?"
/>
</>
)
}
Expand Down