Skip to content

fix: don't navigate away from editor after publishing #9153

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 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 17 additions & 16 deletions site/src/components/TemplateVersionEditor/TemplateVersionEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Button from "@mui/material/Button"
import IconButton from "@mui/material/IconButton"
import Link from "@mui/material/Link"
import { makeStyles } from "@mui/styles"
import Tooltip from "@mui/material/Tooltip"
import CreateIcon from "@mui/icons-material/AddOutlined"
Expand All @@ -13,6 +14,7 @@ import {
VariableValue,
WorkspaceResource,
} from "api/typesGenerated"
import { Link as RouterLink } from "react-router-dom"
import { Alert, AlertDetail } from "components/Alert/Alert"
import { Avatar } from "components/Avatar/Avatar"
import { AvatarData } from "components/AvatarData/AvatarData"
Expand Down Expand Up @@ -186,15 +188,21 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({
<div className={styles.root}>
<div className={styles.topbar} data-testid="topbar">
<div className={styles.topbarSides}>
<AvatarData
title={template.display_name || template.name}
subtitle={template.description}
avatar={
hasIcon && (
<Avatar src={template.icon} variant="square" fitImage />
)
}
/>
<Link
component={RouterLink}
underline="none"
to={`/templates/${template.name}`}
>
<AvatarData
title={template.display_name || template.name}
subtitle={template.description}
avatar={
hasIcon && (
<Avatar src={template.icon} variant="square" fitImage />
)
}
/>
</Link>
</div>

<div className={styles.topbarSides}>
Expand All @@ -217,13 +225,6 @@ export const TemplateVersionEditor: FC<TemplateVersionEditorProps> = ({

<Button
variant="contained"
title={
dirty
? "You have edited files! Run another build before updating."
: templateVersion.job.status !== "succeeded"
? "Something"
: ""
}
Comment on lines -220 to -226
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this because browsers disable title whenever the element they apply to is disabled. The only text that ever had a chance of being seen by a user was the "Something" placeholder text. 😅

disabled={dirty || disableUpdate}
onClick={onPublish}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { useNavigate, useParams } from "react-router-dom"
import { useParams } from "react-router-dom"
import { pageTitle } from "utils/page"
import { templateVersionEditorMachine } from "xServices/templateVersionEditor/templateVersionEditorXService"
import { useTemplateVersionData } from "./data"
Expand All @@ -16,15 +16,9 @@ type Params = {

export const TemplateVersionEditorPage: FC = () => {
const { version: versionName, template: templateName } = useParams() as Params
const navigate = useNavigate()
const orgId = useOrganizationId()
const [editorState, sendEvent] = useMachine(templateVersionEditorMachine, {
context: { orgId },
actions: {
onPublish: () => {
navigate(`/templates/${templateName}`)
},
},
})
const permissions = usePermissions()
const { isSuccess, data } = useTemplateVersionData(
Expand Down Expand Up @@ -59,14 +53,14 @@ export const TemplateVersionEditorPage: FC = () => {
templateId: data.template.id,
})
}}
onCancelPublish={() => {
onPublish={() => {
sendEvent({
type: "CANCEL_PUBLISH",
type: "PUBLISH",
})
}}
onPublish={() => {
onCancelPublish={() => {
sendEvent({
type: "PUBLISH",
type: "CANCEL_PUBLISH",
})
}}
onConfirmPublish={(data) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface TemplateVersionEditorMachineContext {

export const templateVersionEditorMachine = createMachine(
{
/** @xstate-layout N4IgpgJg5mDOIC5QBcwFsAOAbAhqgamAE6wCWA9gHYCiEpy5RAdKZfaTlqQF6tQDEASQByggCqCAggBlBALWoBtAAwBdRKAzkyyCpQ0gAHogC0AVgCMAJiZWAnBYDMZu3eVXHdq1YA0IAJ6IFhY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XQC1Zw3eQ0bYQkxrI4uG8OMxA8dIrGNtpYNMiUlnJU4bvcB+9IFHxXnmg6j0NLOFCJqiIck+b6INbYJYsETiPSzJmrhe8D5L3bRPKedBHyz2ZZfedx9O0w3sBMSw3a5iDu-oYid0xrC1KgmYadzaeEbr4WsrdKId3tRoUbWYOx0zf32KOi0cEjjRSvUUGxdiHFOIfesBCtgHAmuhNidwTdJhnLTccbwOLEkpCAA */
predictableActionArguments: true,
id: "templateVersionEditor",
schema: {
Expand Down Expand Up @@ -85,39 +86,45 @@ export const templateVersionEditorMachine = createMachine(
},
},
},

idle: {
on: {
CREATE_VERSION: {
actions: ["assignCreateBuild"],
target: "cancelingBuild",
target: "cancelingInProgressBuild",
},
PUBLISH: {
target: "askPublishParameters",
},
},
},

askPublishParameters: {
on: {
CANCEL_PUBLISH: "idle",
CONFIRM_PUBLISH: "publishingVersion",
},
},

publishingVersion: {
tags: "loading",
entry: ["clearPublishingError"],
invoke: {
id: "publishingVersion",
src: "publishingVersion",
onDone: {
actions: ["onPublish"],
},

onError: {
actions: ["assignPublishingError"],
target: "askPublishParameters",
},

onDone: {
target: ["idle"],
},
},
},
cancelingBuild: {

cancelingInProgressBuild: {
tags: "loading",
invoke: {
id: "cancelBuild",
Expand All @@ -127,6 +134,7 @@ export const templateVersionEditorMachine = createMachine(
},
},
},

uploadTar: {
tags: "loading",
invoke: {
Expand All @@ -138,6 +146,7 @@ export const templateVersionEditorMachine = createMachine(
},
},
},

creatingBuild: {
tags: "loading",
invoke: {
Expand All @@ -149,6 +158,7 @@ export const templateVersionEditorMachine = createMachine(
},
},
},

watchingBuildLogs: {
tags: "loading",
invoke: {
Expand All @@ -161,19 +171,21 @@ export const templateVersionEditorMachine = createMachine(
},
BUILD_DONE: "fetchingVersion",
CANCEL_VERSION: {
target: "cancelingBuild",
target: "cancelingInProgressBuild",
},
CREATE_VERSION: {
actions: ["assignCreateBuild"],
target: "uploadTar",
},
},
},

fetchingVersion: {
tags: "loading",
invoke: {
id: "fetchVersion",
src: "fetchVersion",

onDone: [
{
actions: ["assignBuild"],
Expand All @@ -187,6 +199,7 @@ export const templateVersionEditorMachine = createMachine(
],
},
},

promptVariables: {
initial: "loadingMissingVariables",
states: {
Expand All @@ -212,6 +225,7 @@ export const templateVersionEditorMachine = createMachine(
},
},
},

fetchResources: {
tags: "loading",
invoke: {
Expand Down