-
Notifications
You must be signed in to change notification settings - Fork 889
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 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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d1e93c8
Add basic publish new version flow
BrunoQuaresma f222b1b
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma 3513404
Fix patch
BrunoQuaresma a2eec18
Add tests
BrunoQuaresma 5195c83
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma 0461806
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma 90dc55f
Fix duplicated name
BrunoQuaresma 05d3944
Merge branch 'main' into bq/ask-template-version-name
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
98 changes: 98 additions & 0 deletions
98
site/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 resolved
Hide resolved
|
||
<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.
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.
Uh oh!
There was an error while loading. Please reload this page.