Skip to content

feat: Adjust forms to include Rich Parameters #5856

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 48 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ed77ef7
XService: GetTemplateParameters
mtojek Jan 24, 2023
5d8330c
Rich parameter input shows up
mtojek Jan 24, 2023
25140eb
Render option icons
mtojek Jan 25, 2023
622eb4b
Icons
mtojek Jan 25, 2023
6a9fce9
WIP
mtojek Jan 25, 2023
d5f1afc
For testing purposes: template
mtojek Jan 25, 2023
2cbc5b0
Fix: useState
mtojek Jan 25, 2023
82d7710
WIP: dynamic validation
mtojek Jan 26, 2023
79dbb5d
Yup validation
mtojek Jan 26, 2023
17dece6
Translations
mtojek Jan 26, 2023
a886301
Remove temporary template
mtojek Jan 26, 2023
dc79db5
make fmt
mtojek Jan 26, 2023
e5aa5a9
WIP
mtojek Jan 26, 2023
a009555
Fix: tests
mtojek Jan 27, 2023
1311493
Fix: fmt
mtojek Jan 27, 2023
feeb10c
URL param
mtojek Jan 27, 2023
64d3016
Refactor
mtojek Jan 27, 2023
ac61aae
Test: rich param value
mtojek Jan 27, 2023
a1f22e9
Storybook
mtojek Jan 27, 2023
dfec8ca
Fix
mtojek Jan 27, 2023
2e321df
Refactor for testing purposes
mtojek Jan 27, 2023
f41de12
Typo
mtojek Jan 27, 2023
40fa739
test: string validation
mtojek Jan 27, 2023
2017a3a
Merge branch 'main' into 5574-site-1
mtojek Jan 30, 2023
d9f03b6
Button: build parameters
mtojek Jan 30, 2023
17bee41
Full screen page
mtojek Jan 30, 2023
b9da6e0
Fix: navigate
mtojek Jan 30, 2023
f372027
XState done
mtojek Jan 31, 2023
b7c0916
refactor: postWorkspaceBuild
mtojek Jan 31, 2023
d8f7cc3
RichParameterInput rendered
mtojek Jan 31, 2023
0dac060
Fix: bad initial value
mtojek Jan 31, 2023
4036caa
Validation works
mtojek Jan 31, 2023
608d713
Maybe
mtojek Jan 31, 2023
2edca1e
Fix
mtojek Jan 31, 2023
c771199
Go back button
mtojek Jan 31, 2023
35cf603
GoBack button
mtojek Jan 31, 2023
640ae42
Form
mtojek Jan 31, 2023
f31a7a0
Fix
mtojek Jan 31, 2023
5228e9c
Storybook
mtojek Feb 1, 2023
3b842f2
Fix: CreateWorkspacePage
mtojek Feb 1, 2023
c62d5a4
fmt
mtojek Feb 1, 2023
6cab87f
Test
mtojek Feb 1, 2023
491107a
Merge branch 'main' into 5574-site-1
mtojek Feb 1, 2023
097be54
ns
mtojek Feb 1, 2023
1210435
fmt
mtojek Feb 1, 2023
26a5e5d
All tests
mtojek Feb 1, 2023
8e2576e
feat: WorkspaceActions depend on template parameters
mtojek Feb 1, 2023
1873645
Fix
mtojek Feb 1, 2023
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
5 changes: 5 additions & 0 deletions site/src/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import GroupsPage from "pages/GroupsPage/GroupsPage"
import LoginPage from "pages/LoginPage/LoginPage"
import { SetupPage } from "pages/SetupPage/SetupPage"
import { TemplateSettingsPage } from "pages/TemplateSettingsPage/TemplateSettingsPage"
import { WorkspaceBuildParametersPage } from "pages/WorkspaceBuildParametersPage/WorkspaceBuildParametersPage"
import TemplatesPage from "pages/TemplatesPage/TemplatesPage"
import UsersPage from "pages/UsersPage/UsersPage"
import WorkspacesPage from "pages/WorkspacesPage/WorkspacesPage"
Expand Down Expand Up @@ -213,6 +214,10 @@ export const AppRouter: FC = () => {
path="change-version"
element={<WorkspaceChangeVersionPage />}
/>
<Route
path="build-parameters"
element={<WorkspaceBuildParametersPage />}
/>
</Route>
</Route>
</Route>
Expand Down
60 changes: 40 additions & 20 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import axios, { AxiosRequestHeaders } from "axios"
import dayjs from "dayjs"
import * as Types from "./types"
import { WorkspaceBuildTransition } from "./types"
import * as TypesGen from "./typesGenerated"

export const hardCodedCSRFCookie = (): string => {
Expand Down Expand Up @@ -288,6 +287,15 @@ export const getTemplateVersionParameters = async (
return response.data
}

export const getTemplateVersionRichParameters = async (
versionId: string,
): Promise<TypesGen.TemplateVersionParameter[]> => {
const response = await axios.get(
`/api/v2/templateversions/${versionId}/rich-parameters`,
)
return response.data
}

export const createTemplate = async (
organizationId: string,
data: TypesGen.CreateTemplateRequest,
Expand Down Expand Up @@ -390,26 +398,29 @@ export const getWorkspaceByOwnerAndName = async (
return response.data
}

const postWorkspaceBuild =
(transition: WorkspaceBuildTransition) =>
async (
workspaceId: string,
template_version_id?: string,
): Promise<TypesGen.WorkspaceBuild> => {
const payload = {
transition,
template_version_id,
}
const response = await axios.post(
`/api/v2/workspaces/${workspaceId}/builds`,
payload,
)
return response.data
}
export const postWorkspaceBuild = async (
workspaceId: string,
data: TypesGen.CreateWorkspaceBuildRequest,
): Promise<TypesGen.WorkspaceBuild> => {
const response = await axios.post(
`/api/v2/workspaces/${workspaceId}/builds`,
data,
)
return response.data
}

export const startWorkspace = postWorkspaceBuild("start")
export const stopWorkspace = postWorkspaceBuild("stop")
export const deleteWorkspace = postWorkspaceBuild("delete")
export const startWorkspace = (
workspaceId: string,
templateVersionID: string,
) =>
postWorkspaceBuild(workspaceId, {
transition: "start",
template_version_id: templateVersionID,
})
export const stopWorkspace = (workspaceId: string) =>
postWorkspaceBuild(workspaceId, { transition: "stop" })
export const deleteWorkspace = (workspaceId: string) =>
postWorkspaceBuild(workspaceId, { transition: "delete" })

export const cancelWorkspaceBuild = async (
workspaceBuildId: TypesGen.WorkspaceBuild["id"],
Expand Down Expand Up @@ -790,3 +801,12 @@ export const updateWorkspaceVersion = async (
const template = await getTemplate(workspace.template_id)
return startWorkspace(workspace.id, template.active_version_id)
}

export const getWorkspaceBuildParameters = async (
workspaceBuildId: TypesGen.WorkspaceBuild["id"],
): Promise<TypesGen.WorkspaceBuildParameter[]> => {
const response = await axios.get<TypesGen.WorkspaceBuildParameter[]>(
`/api/v2/workspacebuilds/${workspaceBuildId}/parameters`,
)
return response.data
}
18 changes: 18 additions & 0 deletions site/src/components/DropdownButton/ActionCtas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { makeStyles } from "@material-ui/core/styles"
import BlockIcon from "@material-ui/icons/Block"
import CloudQueueIcon from "@material-ui/icons/CloudQueue"
import UpdateOutlined from "@material-ui/icons/UpdateOutlined"
import SettingsOutlined from "@material-ui/icons/SettingsOutlined"
import CropSquareIcon from "@material-ui/icons/CropSquare"
import DeleteOutlineIcon from "@material-ui/icons/DeleteOutline"
import PlayCircleOutlineIcon from "@material-ui/icons/PlayCircleOutline"
Expand Down Expand Up @@ -51,6 +52,23 @@ export const ChangeVersionButton: FC<
)
}

export const BuildParametersButton: FC<
React.PropsWithChildren<WorkspaceAction>
> = ({ handleAction }) => {
const styles = useStyles()
const { t } = useTranslation("workspacePage")

return (
<Button
className={styles.actionButton}
startIcon={<SettingsOutlined />}
onClick={handleAction}
>
{t("actionButton.buildParameters")}
</Button>
)
}

export const StartButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
handleAction,
}) => {
Expand Down
19 changes: 19 additions & 0 deletions site/src/components/GoBackButton/GoBackButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Button from "@material-ui/core/Button"

interface GoBackButtonProps {
onClick: () => void
}

export const Language = {
ariaLabel: "Go back",
}

export const GoBackButton: React.FC<
React.PropsWithChildren<GoBackButtonProps>
> = ({ onClick }) => {
return (
<Button onClick={onClick} size="small" aria-label={Language.ariaLabel}>
Go back
</Button>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { Story } from "@storybook/react"
import { TemplateVersionParameter } from "api/typesGenerated"
import {
RichParameterInput,
RichParameterInputProps,
} from "./RichParameterInput"

export default {
title: "components/RichParameterInput",
component: RichParameterInput,
}

const Template: Story<RichParameterInputProps> = (
args: RichParameterInputProps,
) => <RichParameterInput {...args} />

const createTemplateVersionParameter = (
partial: Partial<TemplateVersionParameter>,
): TemplateVersionParameter => {
return {
name: "first_parameter",
description: "This is first parameter.",
type: "string",
mutable: false,
default_value: "default string",
icon: "/icon/folder.svg",
options: [],
validation_error: "",
validation_regex: "",
validation_min: 0,
validation_max: 0,

...partial,
}
}

export const Basic = Template.bind({})
Basic.args = {
initialValue: "initial-value",
parameter: createTemplateVersionParameter({
name: "project_name",
description:
"Customize the name of a Google Cloud project that will be created!",
}),
}

export const NumberType = Template.bind({})
NumberType.args = {
initialValue: "4",
parameter: createTemplateVersionParameter({
name: "number_parameter",
type: "number",
description: "Numeric parameter",
}),
}

export const BooleanType = Template.bind({})
BooleanType.args = {
initialValue: "false",
parameter: createTemplateVersionParameter({
name: "bool_parameter",
type: "bool",
description: "Boolean parameter",
}),
}

export const OptionsType = Template.bind({})
OptionsType.args = {
initialValue: "first_option",
parameter: createTemplateVersionParameter({
name: "options_parameter",
type: "string",
description: "Parameter with options",
options: [
{
name: "First option",
value: "first_option",
description: "This is option 1",
icon: "",
},
{
name: "Second option",
value: "second_option",
description: "This is option 2",
icon: "/icon/database.svg",
},
{
name: "Third option",
value: "third_option",
description: "This is option 3",
icon: "/icon/aws.png",
},
],
}),
}
Loading