Skip to content

fix(site): Fix template icon field validation #7394

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 10 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
4 changes: 2 additions & 2 deletions site/src/components/AlertBanner/AlertBanner.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Story } from "@storybook/react"
import { AlertBanner } from "./AlertBanner"
import Button from "@material-ui/core/Button"
import { makeMockApiError } from "testHelpers/entities"
import { makeMockValidationApiError } from "testHelpers/entities"
import { AlertBannerProps } from "./alertTypes"
import Link from "@material-ui/core/Link"

Expand All @@ -16,7 +16,7 @@ const ExampleAction = (
</Button>
)

const mockError = makeMockApiError({
const mockError = makeMockValidationApiError({
message: "Email or password was invalid",
detail: "Password is invalid",
})
Expand Down
4 changes: 2 additions & 2 deletions site/src/components/SignInForm/SignInForm.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Story } from "@storybook/react"
import { makeMockApiError } from "testHelpers/entities"
import { makeMockValidationApiError } from "testHelpers/entities"
import { SignInForm, SignInFormProps } from "./SignInForm"

export default {
Expand Down Expand Up @@ -37,7 +37,7 @@ SigningIn.args = {
export const WithError = Template.bind({})
WithError.args = {
...SignedOut.args,
error: makeMockApiError({
error: makeMockValidationApiError({
message: "Email or password was invalid",
validations: [
{
Expand Down
6 changes: 3 additions & 3 deletions site/src/components/Workspace/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Failed.args = {
...Running.args,
workspace: Mocks.MockFailedWorkspace,
workspaceErrors: {
[WorkspaceErrors.BUILD_ERROR]: Mocks.makeMockApiError({
[WorkspaceErrors.BUILD_ERROR]: Mocks.makeMockValidationApiError({
message: "A workspace build is already active.",
}),
},
Expand Down Expand Up @@ -152,7 +152,7 @@ export const GetBuildsError = Template.bind({})
GetBuildsError.args = {
...Running.args,
workspaceErrors: {
[WorkspaceErrors.GET_BUILDS_ERROR]: Mocks.makeMockApiError({
[WorkspaceErrors.GET_BUILDS_ERROR]: Mocks.makeMockValidationApiError({
message: "There is a problem fetching builds.",
}),
},
Expand All @@ -162,7 +162,7 @@ export const CancellationError = Template.bind({})
CancellationError.args = {
...Failed.args,
workspaceErrors: {
[WorkspaceErrors.CANCELLATION_ERROR]: Mocks.makeMockApiError({
[WorkspaceErrors.CANCELLATION_ERROR]: Mocks.makeMockValidationApiError({
message: "Job could not be canceled.",
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
emptySchedule,
} from "pages/WorkspaceSettingsPage/WorkspaceSchedulePage/schedule"
import { emptyTTL } from "pages/WorkspaceSettingsPage/WorkspaceSchedulePage/ttl"
import { makeMockApiError } from "testHelpers/entities"
import { makeMockValidationApiError } from "testHelpers/entities"
import {
WorkspaceScheduleForm,
WorkspaceScheduleFormProps,
Expand Down Expand Up @@ -81,7 +81,7 @@ export const WithError = Template.bind({})
WithError.args = {
initialValues: { ...defaultInitialValues, ttl: 100 },
initialTouched: { ttl: true },
submitScheduleError: makeMockApiError({
submitScheduleError: makeMockValidationApiError({
message: "Something went wrong.",
validations: [{ field: "ttl_ms", detail: "Invalid time until shutdown." }],
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentMeta, Story } from "@storybook/react"
import {
makeMockApiError,
makeMockValidationApiError,
mockParameterSchema,
MockParameterSchemas,
MockTemplate,
Expand Down Expand Up @@ -85,7 +85,7 @@ export const GetTemplatesError = Template.bind({})
GetTemplatesError.args = {
...Parameters.args,
createWorkspaceErrors: {
[CreateWorkspaceErrors.GET_TEMPLATES_ERROR]: makeMockApiError({
[CreateWorkspaceErrors.GET_TEMPLATES_ERROR]: makeMockValidationApiError({
message: "Failed to fetch templates.",
detail: "You do not have permission to access this resource.",
}),
Expand All @@ -97,10 +97,11 @@ export const GetTemplateSchemaError = Template.bind({})
GetTemplateSchemaError.args = {
...Parameters.args,
createWorkspaceErrors: {
[CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR]: makeMockApiError({
message: 'Failed to fetch template schema for "docker-amd64".',
detail: "You do not have permission to access this resource.",
}),
[CreateWorkspaceErrors.GET_TEMPLATE_SCHEMA_ERROR]:
makeMockValidationApiError({
message: 'Failed to fetch template schema for "docker-amd64".',
detail: "You do not have permission to access this resource.",
}),
},
hasTemplateErrors: true,
}
Expand All @@ -109,7 +110,7 @@ export const CreateWorkspaceError = Template.bind({})
CreateWorkspaceError.args = {
...Parameters.args,
createWorkspaceErrors: {
[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR]: makeMockApiError({
[CreateWorkspaceErrors.CREATE_WORKSPACE_ERROR]: makeMockValidationApiError({
message:
'Workspace "test" already exists in the "docker-amd64" template.',
validations: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentMeta, Story } from "@storybook/react"
import {
makeMockApiError,
makeMockValidationApiError,
MockDeploymentDAUResponse,
} from "testHelpers/entities"
import {
Expand Down Expand Up @@ -43,5 +43,7 @@ NoDAUs.args = {
export const DAUError = Template.bind({})
DAUError.args = {
deploymentDAUs: undefined,
getDeploymentDAUsError: makeMockApiError({ message: "Error fetching DAUs." }),
getDeploymentDAUsError: makeMockValidationApiError({
message: "Error fetching DAUs.",
}),
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Story } from "@storybook/react"
import {
makeMockApiError,
makeMockValidationApiError,
MockOrganization,
MockTemplateExample,
} from "testHelpers/entities"
Expand Down Expand Up @@ -33,7 +33,7 @@ Error.args = {
context: {
exampleId: MockTemplateExample.id,
organizationId: MockOrganization.id,
error: makeMockApiError({
error: makeMockValidationApiError({
message: `Example ${MockTemplateExample.id} not found.`,
}),
starterTemplate: undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Story } from "@storybook/react"
import {
makeMockApiError,
makeMockValidationApiError,
MockOrganization,
MockTemplateExample,
MockTemplateExample2,
Expand Down Expand Up @@ -36,7 +36,7 @@ export const Error = Template.bind({})
Error.args = {
context: {
organizationId: MockOrganization.id,
error: makeMockApiError({
error: makeMockValidationApiError({
message: "Error on loading the template examples",
}),
starterTemplatesByTag: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
nameValidator,
templateDisplayNameValidator,
onChangeTrimmed,
iconValidator,
} from "utils/formUtils"
import * as Yup from "yup"
import i18next from "i18next"
Expand Down Expand Up @@ -37,8 +38,8 @@ export const getValidationSchema = (): Yup.AnyObjectSchema =>
MAX_DESCRIPTION_CHAR_LIMIT,
i18next.t("descriptionMaxError", { ns: "templateSettingsPage" }),
),

allow_user_cancel_workspace_jobs: Yup.boolean(),
icon: iconValidator,
})

export interface TemplateSettingsForm {
Expand Down Expand Up @@ -74,7 +75,7 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
onSubmit,
initialTouched,
})
const getFieldHelpers = getFormHelpers<UpdateTemplateMeta>(form, error)
const getFieldHelpers = getFormHelpers(form, error)
const { t } = useTranslation("templateSettingsPage")
const styles = useStyles()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { action } from "@storybook/addon-actions"
import { Story } from "@storybook/react"
import { makeMockApiError, MockTemplate } from "testHelpers/entities"
import { makeMockValidationApiError, MockTemplate } from "testHelpers/entities"
import {
TemplateSettingsPageView,
TemplateSettingsPageViewProps,
Expand All @@ -25,7 +25,7 @@ Example.args = {}

export const SaveTemplateSettingsError = Template.bind({})
SaveTemplateSettingsError.args = {
submitError: makeMockApiError({
submitError: makeMockValidationApiError({
message: 'Template "test" already exists.',
validations: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { action } from "@storybook/addon-actions"
import { Story } from "@storybook/react"
import {
makeMockApiError,
makeMockValidationApiError,
MockTemplateVersion,
MockTemplateVersionVariable1,
MockTemplateVersionVariable2,
Expand Down Expand Up @@ -69,7 +69,7 @@ WithUpdateTemplateError.args = {
MockTemplateVersionVariable4,
],
errors: {
updateTemplateError: makeMockApiError({
updateTemplateError: makeMockValidationApiError({
message: "Something went wrong.",
}),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { action } from "@storybook/addon-actions"
import { Story } from "@storybook/react"
import { UseTabResult } from "hooks/useTab"
import {
makeMockApiError,
makeMockValidationApiError,
MockOrganization,
MockTemplate,
MockTemplateVersion,
Expand Down Expand Up @@ -64,7 +64,7 @@ Error.args = {
...defaultArgs.context,
currentVersion: undefined,
currentFiles: undefined,
error: makeMockApiError({
error: makeMockValidationApiError({
message: "Error on loading the template version",
}),
},
Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/TemplatesPage/TemplatesPageView.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentMeta, Story } from "@storybook/react"
import {
makeMockApiError,
makeMockValidationApiError,
MockOrganization,
MockPermissions,
MockTemplate,
Expand Down Expand Up @@ -89,7 +89,7 @@ Error.args = {
...MockPermissions,
createTemplates: false,
},
error: makeMockApiError({
error: makeMockValidationApiError({
message: "Something went wrong fetching templates.",
}),
templates: undefined,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Story } from "@storybook/react"
import { makeMockApiError } from "testHelpers/entities"
import { makeMockValidationApiError } from "testHelpers/entities"
import { SSHKeysPageView, SSHKeysPageViewProps } from "./SSHKeysPageView"

export default {
Expand Down Expand Up @@ -39,15 +39,15 @@ export const WithGetSSHKeyError = Template.bind({})
WithGetSSHKeyError.args = {
...Example.args,
hasLoaded: false,
getSSHKeyError: makeMockApiError({
getSSHKeyError: makeMockValidationApiError({
message: "Failed to get SSH key",
}),
}

export const WithRegenerateSSHKeyError = Template.bind({})
WithRegenerateSSHKeyError.args = {
...Example.args,
regenerateSSHKeyError: makeMockApiError({
regenerateSSHKeyError: makeMockValidationApiError({
message: "Failed to regenerate SSH key",
}),
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Story } from "@storybook/react"
import { makeMockApiError, MockTokens } from "testHelpers/entities"
import { makeMockValidationApiError, MockTokens } from "testHelpers/entities"
import { TokensPageView, TokensPageViewProps } from "./TokensPageView"

export default {
Expand Down Expand Up @@ -41,7 +41,7 @@ export const WithGetTokensError = Template.bind({})
WithGetTokensError.args = {
...Example.args,
hasLoaded: false,
getTokensError: makeMockApiError({
getTokensError: makeMockValidationApiError({
message: "Failed to get tokens.",
}),
}
Expand All @@ -50,7 +50,7 @@ export const WithDeleteTokenError = Template.bind({})
WithDeleteTokenError.args = {
...Example.args,
hasLoaded: false,
deleteTokenError: makeMockApiError({
deleteTokenError: makeMockValidationApiError({
message: "Failed to delete token.",
}),
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Story } from "@storybook/react"
import {
makeMockApiError,
makeMockValidationApiError,
MockWorkspaceProxies,
MockPrimaryWorkspaceProxy,
MockHealthyWildWorkspaceProxy,
Expand Down Expand Up @@ -61,7 +61,7 @@ export const WithProxiesError = Template.bind({})
WithProxiesError.args = {
...Example.args,
hasLoaded: false,
getWorkspaceProxiesError: makeMockApiError({
getWorkspaceProxiesError: makeMockValidationApiError({
message: "Failed to get proxies.",
}),
}
Expand All @@ -70,7 +70,7 @@ export const WithSelectProxyError = Template.bind({})
WithSelectProxyError.args = {
...Example.args,
hasLoaded: false,
selectProxyError: makeMockApiError({
selectProxyError: makeMockValidationApiError({
message: "Failed to select proxy.",
}),
}
8 changes: 4 additions & 4 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ export const MockTemplate: TypesGen.Template = {
created_by_name: "test_creator",
icon: "/icon/code.svg",
allow_user_cancel_workspace_jobs: true,
allow_user_autostart: false,
allow_user_autostop: false,
}

export const MockTemplateVersionFiles: TemplateVersionFiles = {
Expand Down Expand Up @@ -1261,13 +1263,11 @@ type MockAPIOutput = {
isAxiosError: boolean
}

type MakeMockApiErrorFunction = (input: MockAPIInput) => MockAPIOutput

export const makeMockApiError: MakeMockApiErrorFunction = ({
export const makeMockValidationApiError = ({
message,
detail,
validations,
}) => ({
}: MockAPIInput): MockAPIOutput => ({
response: {
data: {
message: message ?? "Something went wrong.",
Expand Down
Loading