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: Move and style copyButton, add to active and past detour views #2852

Merged
merged 16 commits into from
Oct 22, 2024
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
8 changes: 6 additions & 2 deletions assets/css/_diversion_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@
.l-diversion-page__header {
border-bottom: none;
}

.l-diversion-page-panel__header {
align-items: center;
}

.c-diversion-panel__header_text,
.c-detour-panel__subheader,
.c-diversion-panel__back-button-container,
.c-active-detour__alert-icon {
.c-diversion-panel__desktop-buttons {
display: none !important;
}
}
Expand Down
33 changes: 32 additions & 1 deletion assets/src/components/detours/detourPanelComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import React from "react"
import { Stop } from "../../schedule"
import { Badge, ListGroup } from "react-bootstrap"
import {
Badge,
Button,
ListGroup,
OverlayTrigger,
Popover,
} from "react-bootstrap"
import { uniqBy } from "../../helpers/array"
import { RoutePill } from "../routePill"
import { Files } from "../../helpers/bsIcons"

interface MissedStopsProps {
missedStops?: Stop[]
Expand Down Expand Up @@ -64,3 +71,27 @@ export const AffectedRoute = ({
</div>
</section>
)

export const CopyButton = ({ detourText }: { detourText: string }) => (
<OverlayTrigger
placement="bottom"
trigger="click"
rootClose
rootCloseEvent="mousedown"
overlay={
<Popover>
<Popover.Body>Copied to clipboard!</Popover.Body>
</Popover>
}
>
<Button
className="icon-link"
variant="outline-primary"
size="sm"
onClick={() => window.navigator.clipboard?.writeText(detourText)}
>
<Files />
Copy details
</Button>
</OverlayTrigger>
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import {
ExclamationTriangleFill,
StopCircle,
} from "../../../helpers/bsIcons"
import { AffectedRoute, MissedStops } from "../detourPanelComponents"
import {
AffectedRoute,
CopyButton,
MissedStops,
} from "../detourPanelComponents"
import inTestGroup, { TestGroups } from "../../../userInTestGroup"

export interface ActiveDetourPanelProps extends PropsWithChildren {
detourText: string
directions?: DetourDirection[]
connectionPoints?: string[]
missedStops?: Stop[]
Expand All @@ -23,6 +29,7 @@ export interface ActiveDetourPanelProps extends PropsWithChildren {
}

export const ActiveDetourPanel = ({
detourText,
directions,
connectionPoints,
missedStops,
Expand All @@ -38,6 +45,7 @@ export const ActiveDetourPanel = ({
<Button
className="c-diversion-panel__back-button icon-link my-3"
variant="outline-primary"
size="sm"
onClick={onNavigateBack}
>
<ArrowLeft />
Expand All @@ -47,16 +55,20 @@ export const ActiveDetourPanel = ({

return (
<Panel as="article" className="c-diversion-panel">
<Panel.Header className="d-inline-flex justify-content-between">
<Panel.Header>
<h1 className="c-diversion-panel__header_text c-diversion-panel__h1 my-3">
Active Detour
</h1>
{backButton}
{/* TODO: temporary test group until I get the copy logic hooked up */}
{inTestGroup(TestGroups.CopyButton) && (
<CopyButton detourText={detourText} />
)}
</Panel.Header>

<Panel.Body className="d-flex flex-column">
<Panel.Body.ScrollArea>
<div className="d-flex c-diversion-panel__back-button-container justify-content-between align-items-center">
<div className="d-flex c-diversion-panel__desktop-buttons justify-content-between align-items-center">
{backButton}
<ExclamationTriangleFill className="c-active-detour__alert-icon" />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { PropsWithChildren } from "react"
import { Button, Form, OverlayTrigger, Popover } from "react-bootstrap"
import { Button, Form } from "react-bootstrap"
import * as BsIcons from "../../../helpers/bsIcons"
import { Panel } from "../diversionPage"
import { CopyButton } from "../detourPanelComponents"

interface DetourFinishedPanelProps extends PropsWithChildren {
onNavigateBack: () => void
Expand All @@ -17,9 +18,10 @@ export const DetourFinishedPanel = ({
onActivateDetour,
children,
}: DetourFinishedPanelProps) => (
<Panel as="article">
<Panel.Header className="">
<Panel as="article" className="c-diversion-panel">
<Panel.Header>
<h1 className="c-diversion-panel__h1 my-3">View Draft Detour</h1>
<CopyButton detourText={detourText} />
</Panel.Header>

<Panel.Body className="d-flex flex-column">
Expand All @@ -45,24 +47,6 @@ export const DetourFinishedPanel = ({
</Panel.Body.ScrollArea>

<Panel.Body.Footer className="d-flex flex-column">
<OverlayTrigger
placement="top"
trigger="click"
rootClose
rootCloseEvent="mousedown"
overlay={
<Popover>
<Popover.Body>Copied to clipboard!</Popover.Body>
</Popover>
}
>
<Button
className="m-3 flex-grow-1"
onClick={() => window.navigator.clipboard?.writeText(detourText)}
>
Copy Details
</Button>
</OverlayTrigger>
{onActivateDetour && (
<Button
className="m-3 flex-grow-1 icon-link justify-content-center"
Expand Down
13 changes: 12 additions & 1 deletion assets/src/components/detours/detourPanels/pastDetourPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ import { DetourDirection } from "../../../models/detour"
import { Stop } from "../../../schedule"
import { ArrowLeft } from "../../../helpers/bsIcons"
import { Button, ListGroup } from "react-bootstrap"
import { AffectedRoute, MissedStops } from "../detourPanelComponents"
import {
AffectedRoute,
CopyButton,
MissedStops,
} from "../detourPanelComponents"
import inTestGroup, { TestGroups } from "../../../userInTestGroup"

export interface PastDetourPanelProps {
detourText: string
directions?: DetourDirection[]
connectionPoints: [string, string]
missedStops?: Stop[]
Expand All @@ -18,6 +24,7 @@ export interface PastDetourPanelProps {
}

export const PastDetourPanel = ({
detourText,
directions,
connectionPoints: [connectionPointStart, connectionPointEnd],
missedStops,
Expand All @@ -30,6 +37,10 @@ export const PastDetourPanel = ({
<Panel as="article">
<Panel.Header className="">
<h1 className="c-diversion-panel__h1 my-3">View Past Detour</h1>
{/* TODO: temporary test group until I get the copy logic hooked up */}
{inTestGroup(TestGroups.CopyButton) && (
<CopyButton detourText={detourText} />
)}
</Panel.Header>

<Panel.Body className="d-flex flex-column">
Expand Down
5 changes: 5 additions & 0 deletions assets/src/components/detours/diversionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export const DiversionPage = ({
} else if (snapshot.matches({ "Detour Drawing": "Active" })) {
return (
<ActiveDetourPanel
detourText="Hello World"
directions={extendedDirections}
connectionPoints={[
connectionPoints?.start?.name ?? "N/A",
Expand Down Expand Up @@ -379,6 +380,7 @@ export const DiversionPage = ({
} else if (snapshot.matches({ "Detour Drawing": "Past" })) {
return (
<PastDetourPanel
detourText="Hello World"
directions={extendedDirections}
connectionPoints={[
connectionPoints?.start?.name ?? "N/A",
Expand Down Expand Up @@ -531,6 +533,9 @@ const DiversionPagePanelHeader = <As extends React.ElementType = "header">({
"l-diversion-page-panel__header",
"border-bottom",
"px-3",
"d-inline-flex",
"justify-content-between",
"align-items-baseline",
props.className,
])}
>
Expand Down
18 changes: 18 additions & 0 deletions assets/src/helpers/bsIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,24 @@ export const ExclamationTriangleFill = (props: SvgProps) => (
</svg>
)

/**
* @returns https://icons.getbootstrap.com/icons/files/
*/
export const Files = (props: SvgProps) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width="16"
height="16"
fill="currentColor"
className="bi bi-files"
viewBox="0 0 16 16"
aria-hidden
{...props}
>
<path d="M13 0H6a2 2 0 0 0-2 2 2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h7a2 2 0 0 0 2-2 2 2 0 0 0 2-2V2a2 2 0 0 0-2-2m0 13V4a2 2 0 0 0-2-2H5a1 1 0 0 1 1-1h7a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1M3 4a1 1 0 0 1 1-1h7a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1z" />
</svg>
)

/**
* @returns https://icons.getbootstrap.com/icons/gear-fill/
*/
Expand Down
1 change: 1 addition & 0 deletions assets/src/userInTestGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum TestGroups {
DetoursPilot = "detours-pilot",
MinimalLadderPage = "minimal-ladder-page",
LateView = "late-view",
CopyButton = "copy-button",
}

const inTestGroup = (key: TestGroups): boolean => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,37 @@ import React from "react"
import { ActiveDetourPanel } from "../../../src/components/detours/detourPanels/activeDetourPanel"
import { stopFactory } from "../../../tests/factories/stop"

const defaulText = [
"Detour:",
"66 Harvard via Allston from",
"Andrew Station",
"Outbound",
"",
"Turn-by-Turn Directions:",
"Start at Centre St & John St",
"Right on John St",
"Left on Abbotsford Rd",
"Right on Boston St",
"Regular Route",
"",
"Connection Points:",
"Centre St & John St",
"Boston St",
"",
"Missed Stops (3):",
"Example St @ Sample Ave",
"Example St opp Random Way",
"Example St @ Fake Blvd",
].join("\n")

const meta = {
component: ActiveDetourPanel,
parameters: {
layout: "fullscreen",
stretch: true,
},
args: {
detourText: defaulText,
directions: [
{ instruction: "Start at Centre St & John St" },
{ instruction: "Right on John St" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,37 @@ import React from "react"
import { PastDetourPanel } from "../../../src/components/detours/detourPanels/pastDetourPanel"
import { stopFactory } from "../../../tests/factories/stop"

const defaulText = [
"Detour:",
"66 Harvard via Allston from",
"Andrew Station",
"Outbound",
"",
"Turn-by-Turn Directions:",
"Start at Centre St & John St",
"Right on John St",
"Left on Abbotsford Rd",
"Right on Boston St",
"Regular Route",
"",
"Connection Points:",
"Centre St & John St",
"Boston St",
"",
"Missed Stops (3):",
"Example St @ Sample Ave",
"Example St opp Random Way",
"Example St @ Fake Blvd",
].join("\n")

const meta = {
component: PastDetourPanel,
parameters: {
layout: "fullscreen",
stretch: true,
},
args: {
detourText: defaulText,
directions: [
{ instruction: "Start at Centre St & John St" },
{ instruction: "Right on John St" },
Expand Down
Loading
Loading