Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Add form to modify managed Template variables #6257

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 26 commits into from
Mar 2, 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
unusedVariablesNotice
  • Loading branch information
mtojek committed Mar 2, 2023
commit 96a813cb8dc7374f4ae280ab8f3d38940f99ecda
6 changes: 1 addition & 5 deletions site/src/components/TemplateLayout/TemplatePageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import DeleteOutlined from "@material-ui/icons/DeleteOutlined"
import AddCircleOutline from "@material-ui/icons/AddCircleOutline"
import SettingsOutlined from "@material-ui/icons/SettingsOutlined"
import CodeOutlined from "@material-ui/icons/CodeOutlined"
import {
AuthorizationResponse,
Template,
TemplateVersionVariable,
} from "api/typesGenerated"
import { AuthorizationResponse, Template } from "api/typesGenerated"
import { Avatar } from "components/Avatar/Avatar"
import { Maybe } from "components/Conditionals/Maybe"
import { DeleteDialog } from "components/Dialogs/DeleteDialog/DeleteDialog"
Expand Down
3 changes: 2 additions & 1 deletion site/src/i18n/en/templateVariablesPage.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"title": "Template variables",
"sensitiveVariableHelperText": "This variable is sensitive. The previous value will be used if empty.",
"validationRequiredVariable": "Variable is required."
"validationRequiredVariable": "Variable is required.",
"unusedVariablesNotice": "This template does not use managed variables."
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,20 @@ describe("TemplateVariablesPage", () => {
const validationError = await screen.findByText(validationRequiredField)
expect(validationError).toBeDefined()
})

it("no managed variables", async () => {
jest.spyOn(API, "getTemplateByName").mockResolvedValueOnce(MockTemplate)
jest
.spyOn(API, "getTemplateVersion")
.mockResolvedValueOnce(MockTemplateVersion)
jest.spyOn(API, "getTemplateVersionVariables").mockResolvedValueOnce([])

renderTemplateVariablesPage()

const element = await screen.findByText(pageTitleText)
expect(element).toBeDefined()

const goBackButton = await screen.findByText("Go back")
expect(goBackButton).toBeDefined()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Stack } from "components/Stack/Stack"
import { makeStyles } from "@material-ui/core/styles"
import { useTranslation } from "react-i18next"
import { FullPageHorizontalForm } from "components/FullPageForm/FullPageHorizontalForm"
import { GoBackButton } from "components/GoBackButton/GoBackButton"

export interface TemplateVariablesPageViewProps {
templateVersion?: TemplateVersion
Expand Down Expand Up @@ -57,7 +58,7 @@ export const TemplateVariablesPageView: FC<TemplateVariablesPageViewProps> = ({
</Stack>
)}
{isLoading && <Loader />}
{templateVersion && templateVariables && (
{templateVersion && templateVariables && templateVariables.length > 0 && (
<TemplateVariablesForm
initialTouched={initialTouched}
isSubmitting={isSubmitting}
Expand All @@ -68,6 +69,14 @@ export const TemplateVariablesPageView: FC<TemplateVariablesPageViewProps> = ({
error={errors.updateTemplateError}
/>
)}
{templateVariables && templateVariables.length === 0 && (
<div>
<AlertBanner severity="info" text={t("unusedVariablesNotice")} />
<div className={classes.goBackSection}>
<GoBackButton onClick={onCancel} />
</div>
</div>
)}
</FullPageHorizontalForm>
)
}
Expand All @@ -76,4 +85,9 @@ const useStyles = makeStyles((theme) => ({
errorContainer: {
marginBottom: theme.spacing(2),
},
goBackSection: {
display: "flex",
width: "100%",
marginTop: 32,
},
}))