-
Notifications
You must be signed in to change notification settings - Fork 894
feat(site): Ask for missing template variables in the template editor #7108
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 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b446a79
Improve build error message
BrunoQuaresma 5d150ee
Add bases
BrunoQuaresma 06014f5
Fix
BrunoQuaresma 9cd893f
Fix dirty
BrunoQuaresma 5af343d
Merge branch 'main' into bq/prompt-template-variables
BrunoQuaresma fdf0896
Fix default variable values
BrunoQuaresma 8d83af3
Disable autocoomplete for variable input
BrunoQuaresma e25b59c
Merge branch 'main' into bq/prompt-template-variables
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
138 changes: 138 additions & 0 deletions
138
site/src/components/TemplateVersionEditor/MissingTemplateVariablesDialog.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,138 @@ | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import Dialog from "@material-ui/core/Dialog" | ||
import DialogContent from "@material-ui/core/DialogContent" | ||
import DialogContentText from "@material-ui/core/DialogContentText" | ||
import DialogTitle from "@material-ui/core/DialogTitle" | ||
import { DialogProps } from "components/Dialogs/Dialog" | ||
import { FC, useState } from "react" | ||
import { FormFields, VerticalForm } from "components/Form/Form" | ||
import { TemplateVersionVariable, VariableValue } from "api/typesGenerated" | ||
import DialogActions from "@material-ui/core/DialogActions" | ||
import Button from "@material-ui/core/Button" | ||
import { VariableInput } from "pages/CreateTemplatePage/VariableInput" | ||
import { Loader } from "components/Loader/Loader" | ||
|
||
export type MissingTemplateVariablesDialogProps = Omit< | ||
DialogProps, | ||
"onSubmit" | ||
> & { | ||
onClose: () => void | ||
onSubmit: (values: VariableValue[]) => void | ||
missingVariables?: TemplateVersionVariable[] | ||
} | ||
|
||
export const MissingTemplateVariablesDialog: FC< | ||
MissingTemplateVariablesDialogProps | ||
> = ({ missingVariables, onSubmit, ...dialogProps }) => { | ||
const styles = useStyles() | ||
const [variableValues, setVariableValues] = useState<VariableValue[]>([]) | ||
|
||
return ( | ||
<Dialog | ||
{...dialogProps} | ||
scroll="body" | ||
aria-labelledby="update-build-parameters-title" | ||
maxWidth="xs" | ||
data-testid="dialog" | ||
> | ||
<DialogTitle | ||
id="update-build-parameters-title" | ||
classes={{ root: styles.title }} | ||
> | ||
Template variables | ||
</DialogTitle> | ||
<DialogContent className={styles.content}> | ||
<DialogContentText className={styles.info}> | ||
There are a few missing template variable values. Please fill them in. | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</DialogContentText> | ||
<VerticalForm | ||
className={styles.form} | ||
id="updateVariables" | ||
onSubmit={(e) => { | ||
e.preventDefault() | ||
onSubmit(variableValues) | ||
}} | ||
> | ||
{missingVariables ? ( | ||
<FormFields> | ||
{missingVariables.map((variable, index) => { | ||
return ( | ||
<VariableInput | ||
mtojek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaultValue={variable.value} | ||
variable={variable} | ||
key={variable.name} | ||
onChange={async (value) => { | ||
setVariableValues((prev) => { | ||
prev[index] = { | ||
name: variable.name, | ||
value, | ||
} | ||
return [...prev] | ||
}) | ||
}} | ||
/> | ||
) | ||
})} | ||
</FormFields> | ||
) : ( | ||
<Loader /> | ||
)} | ||
</VerticalForm> | ||
</DialogContent> | ||
<DialogActions disableSpacing className={styles.dialogActions}> | ||
<Button color="primary" fullWidth type="submit" form="updateVariables"> | ||
Submit | ||
</Button> | ||
<Button | ||
fullWidth | ||
type="button" | ||
variant="outlined" | ||
onClick={dialogProps.onClose} | ||
> | ||
Cancel | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
title: { | ||
padding: theme.spacing(3, 5), | ||
|
||
"& h2": { | ||
fontSize: theme.spacing(2.5), | ||
fontWeight: 400, | ||
}, | ||
}, | ||
|
||
content: { | ||
padding: theme.spacing(0, 5, 0, 5), | ||
}, | ||
|
||
info: { | ||
margin: 0, | ||
}, | ||
|
||
form: { | ||
paddingTop: theme.spacing(4), | ||
}, | ||
|
||
infoTitle: { | ||
fontSize: theme.spacing(2), | ||
fontWeight: 600, | ||
display: "flex", | ||
alignItems: "center", | ||
gap: theme.spacing(1), | ||
}, | ||
|
||
formFooter: { | ||
flexDirection: "column", | ||
}, | ||
|
||
dialogActions: { | ||
padding: theme.spacing(5), | ||
flexDirection: "column", | ||
gap: theme.spacing(1), | ||
}, | ||
})) |
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
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
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.