- Notifications
You must be signed in to change notification settings - Fork928
feat(site): Ask for version name and if it is active when publishing a new version on editor#6756
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
d1e93c8
Add basic publish new version flow
BrunoQuaresmaf222b1b
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma3513404
Fix patch
BrunoQuaresmaa2eec18
Add tests
BrunoQuaresma5195c83
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma0461806
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma90dc55f
Fix duplicated name
BrunoQuaresma05d3944
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresmaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletionscoderd/templateversions.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletionssite/src/api/api.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -373,6 +373,17 @@ export const updateActiveTemplateVersion = async ( | ||
return response.data | ||
} | ||
export const patchTemplateVersion = async ( | ||
templateVersionId: string, | ||
data: TypesGen.PatchTemplateVersionRequest, | ||
) => { | ||
const response = await axios.patch<TypesGen.TemplateVersion>( | ||
`/api/v2/templateversions/${templateVersionId}`, | ||
data, | ||
) | ||
return response.data | ||
} | ||
export const updateTemplateMeta = async ( | ||
templateId: string, | ||
data: TypesGen.UpdateTemplateMeta, | ||
@@ -1020,3 +1031,26 @@ const getMissingParameters = ( | ||
return missingParameters | ||
} | ||
export const watchBuildLogs = ( | ||
versionId: string, | ||
onMessage: (log: TypesGen.ProvisionerJobLog) => void, | ||
) => { | ||
return new Promise<void>((resolve, reject) => { | ||
const proto = location.protocol === "https:" ? "wss:" : "ws:" | ||
const socket = new WebSocket( | ||
`${proto}//${location.host}/api/v2/templateversions/${versionId}/logs?follow=true`, | ||
) | ||
socket.binaryType = "blob" | ||
socket.addEventListener("message", (event) => | ||
onMessage(JSON.parse(event.data) as TypesGen.ProvisionerJobLog), | ||
) | ||
socket.addEventListener("error", () => { | ||
reject(new Error("Connection for logs failed.")) | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
}) | ||
socket.addEventListener("close", () => { | ||
// When the socket closes, logs have finished streaming! | ||
resolve() | ||
}) | ||
}) | ||
} |
98 changes: 98 additions & 0 deletionssite/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { DialogProps } from "components/Dialogs/Dialog" | ||
import { FC } from "react" | ||
import { getFormHelpers } from "util/formUtils" | ||
import { FormFields } from "components/Form/Form" | ||
import { useFormik } from "formik" | ||
import * as Yup from "yup" | ||
import { PublishVersionData } from "pages/TemplateVersionPage/TemplateVersionEditorPage/types" | ||
import TextField from "@material-ui/core/TextField" | ||
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog" | ||
import Checkbox from "@material-ui/core/Checkbox" | ||
import FormControlLabel from "@material-ui/core/FormControlLabel" | ||
import { Stack } from "components/Stack/Stack" | ||
export type PublishTemplateVersionDialogProps = DialogProps & { | ||
defaultName: string | ||
isPublishing: boolean | ||
publishingError?: unknown | ||
onClose: () => void | ||
onConfirm: (data: PublishVersionData) => void | ||
} | ||
export const PublishTemplateVersionDialog: FC< | ||
PublishTemplateVersionDialogProps | ||
> = ({ | ||
onConfirm, | ||
isPublishing, | ||
onClose, | ||
defaultName, | ||
publishingError, | ||
...dialogProps | ||
}) => { | ||
const form = useFormik({ | ||
initialValues: { | ||
name: defaultName, | ||
isActiveVersion: false, | ||
}, | ||
validationSchema: Yup.object({ | ||
name: Yup.string().required(), | ||
isActiveVersion: Yup.boolean(), | ||
}), | ||
onSubmit: onConfirm, | ||
}) | ||
const getFieldHelpers = getFormHelpers(form, publishingError) | ||
const handleClose = () => { | ||
form.resetForm() | ||
onClose() | ||
} | ||
return ( | ||
<ConfirmDialog | ||
{...dialogProps} | ||
confirmLoading={isPublishing} | ||
onClose={handleClose} | ||
onConfirm={async () => { | ||
await form.submitForm() | ||
}} | ||
hideCancel={false} | ||
type="success" | ||
cancelText="Cancel" | ||
confirmText="Publish" | ||
title="Publish new version" | ||
description={ | ||
<Stack> | ||
<p>You are about to publish a new version of this template.</p> | ||
BrunoQuaresma marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
<FormFields> | ||
<TextField | ||
{...getFieldHelpers("name")} | ||
label="Version name" | ||
autoFocus | ||
disabled={isPublishing} | ||
InputLabelProps={{ | ||
shrink: true, | ||
}} | ||
/> | ||
<FormControlLabel | ||
label="Promote to default version" | ||
control={ | ||
<Checkbox | ||
size="small" | ||
checked={form.values.isActiveVersion} | ||
onChange={async (e) => { | ||
await form.setFieldValue( | ||
"isActiveVersion", | ||
e.target.checked, | ||
) | ||
}} | ||
name="isActiveVersion" | ||
color="primary" | ||
/> | ||
} | ||
/> | ||
</FormFields> | ||
</Stack> | ||
} | ||
/> | ||
) | ||
} |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.