Skip to content
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

feat: delete draft detour UI #2909

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
53 changes: 53 additions & 0 deletions assets/src/components/detours/deleteDetourModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react"
import { Button, Modal } from "react-bootstrap"
import { RoutePill } from "../routePill"

export const DeleteDetourModal = ({
onDelete,
onCancel,
routeName,
routeDescription,
routeOrigin,
routeDirection,
}: {
onDelete: () => void
onCancel: () => void
routeName: string
routeDescription: string
routeOrigin: string
routeDirection: string
}) => {
return (
<Modal show animation={false} onHide={onCancel}>
<Modal.Header closeButton>
<h3 className="fs-3 fw-semibold lh-sm my-1">Delete Draft</h3>
</Modal.Header>
<Modal.Body>
<div className="d-flex flex-row gap-2 mb-3">
<RoutePill routeName={routeName} />
<div>
<div className="fw-semibold mb-1">{routeDescription}</div>
<div className="fw-normal text-body-secondary fs-6 mb-1">
From {routeOrigin.split(" - ")[0]}
</div>
<div className="fw-normal fs-6">{routeDirection}</div>
</div>
</div>
<p>Are you sure you want to delete this draft?</p>
</Modal.Body>
<Modal.Footer>
<Button variant="outline-primary" onClick={onCancel}>
Cancel
</Button>
<Button
variant="ui-alert"
onClick={onDelete}
className="text-white"
data-fs-element="Confirm Delete Draft"
>
Delete Draft
</Button>
</Modal.Footer>
</Modal>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface DetourFinishedPanelProps extends PropsWithChildren {
missedStops?: Stop[]
onChangeDetourText: (value: string) => void
onActivateDetour?: () => void
onDeleteDetour?: () => void
affectedRoute?: ReactNode
}

Expand All @@ -28,6 +29,7 @@ export const DetourFinishedPanel = ({
missedStops,
onChangeDetourText,
onActivateDetour,
onDeleteDetour,
children,
affectedRoute,
}: DetourFinishedPanelProps) => (
Expand Down Expand Up @@ -81,15 +83,26 @@ export const DetourFinishedPanel = ({
</Panel.Body.ScrollArea>

<Panel.Body.Footer className="d-flex flex-column">
{onActivateDetour && (
<Button
className="m-3 flex-grow-1 icon-link justify-content-center"
onClick={onActivateDetour}
data-fs-element="Begin Activate Detour"
>
<BsIcons.Power />
Start Detour
</Button>
{onDeleteDetour && (
bfauble marked this conversation as resolved.
Show resolved Hide resolved
<>
<Button
className="m-3 flex-grow-1 icon-link justify-content-center"
variant="outline-ui-alert"
onClick={onDeleteDetour}
data-fs-element="Delete Detour Draft"
>
<BsIcons.Trash />
Delete Draft
</Button>
<Button
className="m-3 flex-grow-1 icon-link justify-content-center"
onClick={onActivateDetour}
data-fs-element="Begin Activate Detour"
>
<BsIcons.Power />
Start Detour
</Button>
</>
)}
</Panel.Body.Footer>
</Panel.Body>
Expand Down
27 changes: 27 additions & 0 deletions assets/src/components/detours/diversionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { timeAgoLabel } from "../../util/dateTime"
import { DetourStatus, timestampLabelFromStatus } from "../detoursTable"
import { ActivateDetour } from "./activateDetourModal"
import { DeactivateDetourModal } from "./deactivateDetourModal"
import { DeleteDetourModal } from "./deleteDetourModal"
import useScreenSize from "../../hooks/useScreenSize"
import { Drawer } from "../drawer"
import { isMobile } from "../../util/screenSize"
Expand Down Expand Up @@ -271,6 +272,13 @@ export const DiversionPage = ({
}
: undefined
}
onDeleteDetour={
inTestGroup(TestGroups.DeleteDraftDetours)
? () => {
send({ type: "detour.delete.open-delete-modal" })
}
: undefined
}
affectedRoute={
<AffectedRoute
routeName={routeName ?? "??"}
Expand Down Expand Up @@ -365,6 +373,25 @@ export const DiversionPage = ({
) : null}
</ActivateDetour.Modal>
) : null}

{snapshot.matches({
"Detour Drawing": {
"Share Detour": "Deleting",
},
}) ? (
<DeleteDetourModal
onDelete={() =>
send({ type: "detour.delete.delete-modal.delete-draft" })
}
onCancel={() =>
send({ type: "detour.delete.delete-modal.cancel" })
}
routeName={routeName || "??"}
routeDescription={routeDescription || "??"}
routeOrigin={routeOrigin || "??"}
routeDirection={routeDirection || "??"}
/>
firestack marked this conversation as resolved.
Show resolved Hide resolved
) : null}
</DetourFinishedPanel>
)
} else if (snapshot.matches({ "Detour Drawing": "Active" })) {
Expand Down
19 changes: 19 additions & 0 deletions assets/src/helpers/bsIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,25 @@ export const ThreeDotsVertical = (props: SvgProps) => (
</svg>
)

/**
* @returns https://icons.getbootstrap.com/icons/trash/
*/
export const Trash = (props: SvgProps) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
className="bi bi-trash"
viewBox="0 0 16 16"
aria-hidden
{...props}
>
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0z" />
<path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4zM2.5 3h11V2h-11z" />
</svg>
)

/**
* @returns https://icons.getbootstrap.com/icons/x-square/
*/
Expand Down
29 changes: 28 additions & 1 deletion assets/src/models/createDetourMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ export const createDetourMachine = setup({
| { type: "detour.active.deactivate-modal.deactivate" }
| { type: "detour.active.deactivate-modal.cancel" }
| { type: "detour.save.begin-save" }
| { type: "detour.save.set-uuid"; uuid: number },
| { type: "detour.save.set-uuid"; uuid: number }
| { type: "detour.delete.open-delete-modal" }
| { type: "detour.delete.delete-modal.cancel" }
| { type: "detour.delete.delete-modal.delete-draft" },

// We're making an assumption that we'll never want to save detour edits to the database when in particular stages
// of detour drafting:
Expand Down Expand Up @@ -528,6 +531,9 @@ export const createDetourMachine = setup({
editedDirections: ({ event }) => event.detourText,
}),
},
"detour.delete.open-delete-modal": {
target: "Deleting",
},
},
},
Activating: {
Expand Down Expand Up @@ -632,6 +638,27 @@ export const createDetourMachine = setup({
target: "Done",
},
},
Deleting: {
initial: "Confirming",
on: {
"detour.delete.delete-modal.cancel": {
target: "Reviewing",
},
},
states: {
Confirming: {
on: {
"detour.delete.delete-modal.delete-draft": {
target: "Done",
},
},
},
Done: { type: "final" },
},
onDone: {
target: "Done",
},
},
Done: { type: "final" },
},
onDone: {
Expand Down
1 change: 1 addition & 0 deletions assets/src/userInTestGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export enum TestGroups {
MinimalLadderPage = "minimal-ladder-page",
LateView = "late-view",
CopyButton = "copy-button",
DeleteDraftDetours = "delete-draft-detours",
}

const inTestGroup = (key: TestGroups): boolean => {
Expand Down
Loading