From f9e8ef6642c06d5d86ccb66cb7f2e4ce1711a286 Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 25 Aug 2023 19:35:36 +0000 Subject: [PATCH 1/4] phase 1 --- site/src/components/Alert/Alert.stories.tsx | 8 ++++++++ .../TemplateVersionEditor.stories.tsx | 18 +++++++++--------- .../TemplateVersionEditor.tsx | 10 +++++++++- .../TemplateVersionEditorPage.tsx | 3 ++- .../templateVersionEditorXService.ts | 13 +++++++++++-- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/site/src/components/Alert/Alert.stories.tsx b/site/src/components/Alert/Alert.stories.tsx index ada32cd994ec9..c5139f7c1c1a1 100644 --- a/site/src/components/Alert/Alert.stories.tsx +++ b/site/src/components/Alert/Alert.stories.tsx @@ -17,6 +17,14 @@ const ExampleAction = ( ) +export const Success: Story = { + args: { + children: "You're doing great!", + severity: "success", + onRetry: undefined, + }, +} + export const Warning: Story = { args: { children: "This is a warning", diff --git a/site/src/components/TemplateVersionEditor/TemplateVersionEditor.stories.tsx b/site/src/components/TemplateVersionEditor/TemplateVersionEditor.stories.tsx index 24a40ad4d4fae..285df1950d4a2 100644 --- a/site/src/components/TemplateVersionEditor/TemplateVersionEditor.stories.tsx +++ b/site/src/components/TemplateVersionEditor/TemplateVersionEditor.stories.tsx @@ -27,26 +27,20 @@ const Template: Story = ( export const Example = Template.bind({}) Example.args = { + defaultFileTree: MockTemplateVersionFileTree, template: MockTemplate, templateVersion: MockTemplateVersion, - defaultFileTree: MockTemplateVersionFileTree, } export const Logs = Template.bind({}) - Logs.args = { - template: MockTemplate, - templateVersion: MockTemplateVersion, - defaultFileTree: MockTemplateVersionFileTree, + ...Example.args, buildLogs: MockWorkspaceBuildLogs, } export const Resources = Template.bind({}) - Resources.args = { - template: MockTemplate, - templateVersion: MockTemplateVersion, - defaultFileTree: MockTemplateVersionFileTree, + ...Example.args, buildLogs: MockWorkspaceBuildLogs, resources: [ MockWorkspaceResource, @@ -54,3 +48,9 @@ Resources.args = { MockWorkspaceResource3, ], } + +export const SuccessfulPublish = Template.bind({}) +SuccessfulPublish.args = { + ...Example.args, + publishedVersion: MockTemplateVersion, +} diff --git a/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx b/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx index 9ffe7e0e41b4c..257baedbfaa68 100644 --- a/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx +++ b/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx @@ -64,6 +64,7 @@ export interface TemplateVersionEditorProps { onConfirmPublish: (data: PublishVersionData) => void onCancelPublish: () => void publishingError: unknown + publishedVersion?: TemplateVersion isAskingPublishParameters: boolean isPromptingMissingVariables: boolean isPublishing: boolean @@ -97,9 +98,10 @@ export const TemplateVersionEditor: FC = ({ onPublish, onConfirmPublish, onCancelPublish, - publishingError, isAskingPublishParameters, isPublishing, + publishingError, + publishedVersion, buildLogs, resources, isPromptingMissingVariables, @@ -204,6 +206,12 @@ export const TemplateVersionEditor: FC = ({ + {publishedVersion && ( + + Successfully published! + + )} +
{/* Only start to show the build when a new template version is building */} {templateVersion.id !== firstTemplateVersionOnEditor.current.id && ( diff --git a/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx b/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx index 36bad25e7ef83..dedb82fb217ae 100644 --- a/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx +++ b/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx @@ -72,8 +72,9 @@ export const TemplateVersionEditorPage: FC = () => { isAskingPublishParameters={editorState.matches( "askPublishParameters", )} - publishingError={editorState.context.publishingError} isPublishing={editorState.matches("publishingVersion")} + publishingError={editorState.context.publishingError} + publishedVersion={editorState.context.lastSuccessfulPublishedVersion} disablePreview={editorState.hasTag("loading")} disableUpdate={ editorState.hasTag("loading") || diff --git a/site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts b/site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts index 4c4623f5bc374..2af0f78bce68b 100644 --- a/site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts +++ b/site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts @@ -24,13 +24,14 @@ export interface TemplateVersionEditorMachineContext { buildLogs?: ProvisionerJobLog[] tarReader?: TarReader publishingError?: unknown + lastSuccessfulPublishedVersion?: TemplateVersion missingVariables?: TemplateVersionVariable[] missingVariableValues?: VariableValue[] } export const templateVersionEditorMachine = createMachine( { - /** @xstate-layout N4IgpgJg5mDOIC5QBcwFsAOAbAhqgamAE6wCWA9gHYCiEpy5RAdKZfaTlqQF6tQDEASQByggCqCAggBlBALWoBtAAwBdRKAzkyyCpQ0gAHogC0AVgCMAJiZWAnBYDMZu3eVXHdq1YA0IAJ6IFhYAbDZWIe4AHI4hYcoA7BYJAL4pfqiYuATEZFS09IwsEFhg-ADCAErUkmLUAPr41JUAyoIA8sIq6kggWjp6BsYIJrFmTI5WFmZm7iHTACwhZn6BCBYLM0xmCVEhk4sLCQkLaRno2HhghCR6BQzMpCVlAAoAqgBCsi0AEt0G-XYVCGpgi42UjgWViiUQsUW8EWWqyCVmUCyYbjMjmUUQSHlxIVS6RAmUuOVu+ToDyYOFgAGsXgBXABGXFgAAsXjgiDg0GBUCQKpJhOVqNJ6u8voJfv9eoDdMDesMTMEEhM7AsFjETq49lDketoWrjvs4cp5lCTmcSRdstdcncqUVaQyWWzOdzefzchVOgAxQSVACyEs+3z+agB2iB+iVQWSTA2UQWk0cUSxe2UdgNwVcTF2sLMHiS0Ki1tJdpueRoTuYGDdpA5fCren4ECoYBYlAAbuQ6Z366zG+zmw6qLLNNGFbHQMMFsplExlFi7GY4l5IumVgEUVE7BNQmZYQsNk4wuXbVcW5TCnWG03KFBr5R+MQiEUyQAzRhoJiD92jhSlATn0U6DHG6wWPuRzJFm7hYkc0I5mi+54p486OAk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Om4VWir3QJoY819q0wioo6mjLY2JFg4MVHg6Y4FZzbn7d6goUSYlxISQhicHiEJxCVCMewiotSrwKbYXYwQPAoTxCkFIQA */ predictableActionArguments: true, id: "templateVersionEditor", schema: { @@ -108,7 +109,7 @@ export const templateVersionEditorMachine = createMachine( publishingVersion: { tags: "loading", - entry: ["clearPublishingError"], + entry: ["clearPublishingError", "clearLastSuccessfulPublishedVersion"], invoke: { id: "publishingVersion", src: "publishingVersion", @@ -119,6 +120,7 @@ export const templateVersionEditorMachine = createMachine( }, onDone: { + actions: ["assignLastSuccessfulPublishedVersion"], target: ["idle"], }, }, @@ -256,6 +258,10 @@ export const templateVersionEditorMachine = createMachine( assignBuild: assign({ version: (_, event) => event.data, }), + assignLastSuccessfulPublishedVersion: assign({ + lastSuccessfulPublishedVersion: (ctx) => ctx.version, + version: () => undefined, + }), addBuildLog: assign({ buildLogs: (context, event) => { const previousLogs = context.buildLogs ?? [] @@ -285,6 +291,9 @@ export const templateVersionEditorMachine = createMachine( publishingError: (_, event) => event.data, }), clearPublishingError: assign({ publishingError: (_) => undefined }), + clearLastSuccessfulPublishedVersion: assign({ + lastSuccessfulPublishedVersion: (_) => undefined, + }), assignMissingVariables: assign({ missingVariables: (_, event) => event.data, }), From 4af144456e0c5b9f9e80eb191282d7af45a29f0f Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Fri, 25 Aug 2023 20:59:51 +0000 Subject: [PATCH 2/4] phase 2 --- .../PublishTemplateVersionDialog.tsx | 2 +- .../TemplateVersionEditor.tsx | 14 ++++++++++++-- .../TemplateVersionEditorPage.tsx | 6 +++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/site/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx b/site/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx index 8fcd96bcce157..4fc70c38e386a 100644 --- a/site/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx +++ b/site/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx @@ -33,7 +33,7 @@ export const PublishTemplateVersionDialog: FC< initialValues: { name: defaultName, message: "", - isActiveVersion: false, + isActiveVersion: true, }, validationSchema: Yup.object({ name: Yup.string().required(), diff --git a/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx b/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx index 80db260a261fb..8e3479e33aec7 100644 --- a/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx +++ b/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx @@ -65,6 +65,7 @@ export interface TemplateVersionEditorProps { onCancelPublish: () => void publishingError: unknown publishedVersion?: TemplateVersion + onCreateWorkspace: () => void isAskingPublishParameters: boolean isPromptingMissingVariables: boolean isPublishing: boolean @@ -102,6 +103,7 @@ export const TemplateVersionEditor: FC = ({ isPublishing, publishingError, publishedVersion, + onCreateWorkspace, buildLogs, resources, isPromptingMissingVariables, @@ -207,8 +209,16 @@ export const TemplateVersionEditor: FC = ({
{publishedVersion && ( - - Successfully published! + + Create a new workspace + + } + > + Successfully published {publishedVersion.name}! )} diff --git a/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx b/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx index dedb82fb217ae..342028b1f306a 100644 --- a/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx +++ b/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx @@ -4,7 +4,7 @@ import { useOrganizationId } from "hooks/useOrganizationId" import { usePermissions } from "hooks/usePermissions" import { FC } from "react" import { Helmet } from "react-helmet-async" -import { useParams } from "react-router-dom" +import { useNavigate, useParams } from "react-router-dom" import { pageTitle } from "utils/page" import { templateVersionEditorMachine } from "xServices/templateVersionEditor/templateVersionEditorXService" import { useTemplateVersionData } from "./data" @@ -15,6 +15,7 @@ type Params = { } export const TemplateVersionEditorPage: FC = () => { + const navigate = useNavigate() const { version: versionName, template: templateName } = useParams() as Params const orgId = useOrganizationId() const [editorState, sendEvent] = useMachine(templateVersionEditorMachine, { @@ -75,6 +76,9 @@ export const TemplateVersionEditorPage: FC = () => { isPublishing={editorState.matches("publishingVersion")} publishingError={editorState.context.publishingError} publishedVersion={editorState.context.lastSuccessfulPublishedVersion} + onCreateWorkspace={() => { + navigate(`/templates/${templateName}/workspace`) + }} disablePreview={editorState.hasTag("loading")} disableUpdate={ editorState.hasTag("loading") || From 36864648554172b4bae4001dd6f0b3c820870eac Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Mon, 28 Aug 2023 17:01:35 +0000 Subject: [PATCH 3/4] only show new workspace button when relevant --- .../TemplateVersionEditor.tsx | 25 +++++++++++++------ .../TemplateVersionEditorPage.tsx | 3 +++ .../templateVersionEditorXService.ts | 7 +++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx b/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx index 8e3479e33aec7..aca932c29180a 100644 --- a/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx +++ b/site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx @@ -65,6 +65,7 @@ export interface TemplateVersionEditorProps { onCancelPublish: () => void publishingError: unknown publishedVersion?: TemplateVersion + publishedVersionIsDefault?: boolean onCreateWorkspace: () => void isAskingPublishParameters: boolean isPromptingMissingVariables: boolean @@ -103,6 +104,7 @@ export const TemplateVersionEditor: FC = ({ isPublishing, publishingError, publishedVersion, + publishedVersionIsDefault, onCreateWorkspace, buildLogs, resources, @@ -111,11 +113,9 @@ export const TemplateVersionEditor: FC = ({ onSubmitMissingVariableValues, onCancelSubmitMissingVariableValues, }) => { - const [selectedTab, setSelectedTab] = useState(() => { - // If resources are provided, show them by default! - // This is for Storybook! - return resources ? 1 : 0 - }) + // If resources are provided, show them by default! + // This is for Storybook! + const [selectedTab, setSelectedTab] = useState(() => (resources ? 1 : 0)) const [fileTree, setFileTree] = useState(defaultFileTree) const [createFileOpen, setCreateFileOpen] = useState(false) const [deleteFileOpen, setDeleteFileOpen] = useState() @@ -213,9 +213,18 @@ export const TemplateVersionEditor: FC = ({ severity="success" dismissible actions={ - + // TODO: Only show this button when the version we just published is the + // new primary version. We should remove this condition soon, when we can + // create workspaces using any version, not just the primary. + publishedVersionIsDefault && ( + + ) } > Successfully published {publishedVersion.name}! diff --git a/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx b/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx index 342028b1f306a..078e14e406cec 100644 --- a/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx +++ b/site/src/pages/TemplateVersionPage/TemplateVersionEditorPage/TemplateVersionEditorPage.tsx @@ -76,6 +76,9 @@ export const TemplateVersionEditorPage: FC = () => { isPublishing={editorState.matches("publishingVersion")} publishingError={editorState.context.publishingError} publishedVersion={editorState.context.lastSuccessfulPublishedVersion} + publishedVersionIsDefault={ + editorState.context.lastSuccessfulPublishIsDefault + } onCreateWorkspace={() => { navigate(`/templates/${templateName}/workspace`) }} diff --git a/site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts b/site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts index 2af0f78bce68b..990479b9c2475 100644 --- a/site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts +++ b/site/src/xServices/templateVersionEditor/templateVersionEditorXService.ts @@ -25,6 +25,7 @@ export interface TemplateVersionEditorMachineContext { tarReader?: TarReader publishingError?: unknown lastSuccessfulPublishedVersion?: TemplateVersion + lastSuccessfulPublishIsDefault?: boolean missingVariables?: TemplateVersionVariable[] missingVariableValues?: VariableValue[] } @@ -69,7 +70,7 @@ export const templateVersionEditorMachine = createMachine( data: WorkspaceResource[] } publishingVersion: { - data: void + data: { isActiveVersion: boolean } } loadMissingVariables: { data: TemplateVersionVariable[] @@ -260,6 +261,8 @@ export const templateVersionEditorMachine = createMachine( }), assignLastSuccessfulPublishedVersion: assign({ lastSuccessfulPublishedVersion: (ctx) => ctx.version, + lastSuccessfulPublishIsDefault: (_, event) => + event.data.isActiveVersion, version: () => undefined, }), addBuildLog: assign({ @@ -429,6 +432,8 @@ export const templateVersionEditorMachine = createMachine( }) : Promise.resolve(), ]) + + return { isActiveVersion } }, loadMissingVariables: ({ version }) => { if (!version) { From e7d64442675fa8770e5eaed89a72afce6232910e Mon Sep 17 00:00:00 2001 From: McKayla Washburn Date: Mon, 28 Aug 2023 17:12:01 +0000 Subject: [PATCH 4/4] fix tests --- .../PublishTemplateVersionDialog.tsx | 12 +++++++++--- .../TemplateVersionEditorPage.test.tsx | 7 ++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/site/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx b/site/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx index 4fc70c38e386a..a834f4446abd2 100644 --- a/site/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx +++ b/site/src/components/TemplateVersionEditor/PublishTemplateVersionDialog.tsx @@ -11,6 +11,12 @@ import Checkbox from "@mui/material/Checkbox" import FormControlLabel from "@mui/material/FormControlLabel" import { Stack } from "components/Stack/Stack" +export const Language = { + versionNameLabel: "Version name", + messagePlaceholder: "Write a short message about the changes you made...", + defaultCheckboxLabel: "Promote to default version", +} + export type PublishTemplateVersionDialogProps = DialogProps & { defaultName: string isPublishing: boolean @@ -67,7 +73,7 @@ export const PublishTemplateVersionDialog: FC< @@ -75,7 +81,7 @@ export const PublishTemplateVersionDialog: FC< { const nameField = within(publishDialog).getByLabelText("Version name") await user.clear(nameField) await user.type(nameField, "v1.0") + await user.click( + within(publishDialog).getByLabelText(Language.defaultCheckboxLabel), + ) await user.click( within(publishDialog).getByRole("button", { name: "Publish" }), )