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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 18 additions & 3 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 Expand Up @@ -89,7 +93,7 @@
}
}

.l-diversion-page-panel__header .c-diversion-panel__back-button {
.l-diversion-page-panel__header .c-diversion-panel__outline-button--back {
Copy link
Member

Choose a reason for hiding this comment

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

question: why change the name of this button? IMO the "outline" info doesn't seem necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're totally right. I renamed at one point, assuming I'd use the --back as an extension of outline button, as in these lines, but not needed. (Plus, I see those might need tweaking as well)

display: none;
}
}
Expand Down Expand Up @@ -161,3 +165,14 @@
height: 1.5rem;
width: 1.5rem;
}

.c-diversion-panel__outline-button {
height: 2rem;
border-radius: 0.2rem;
font-size: 0.875rem;
padding: 0.375rem 0.5rem;

&--copy {
margin: 0.78125rem 0;
}
Comment on lines +175 to +177
Copy link
Member

Choose a reason for hiding this comment

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

I think this margin should be handled via the .align-items-baseline class on the parent flex

}
Comment on lines +169 to +178
Copy link
Member

@firestack firestack Oct 18, 2024

Choose a reason for hiding this comment

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

I don't think we need this? this seems like a size="sm" property on the React Bootstrap <Button/>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh my gosh, I totally reinvented the wheel. Thanks!!

32 changes: 31 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,26 @@ 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="c-diversion-panel__outline-button c-diversion-panel__outline-button--copy icon-link"
Copy link
Member

Choose a reason for hiding this comment

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

Between these two suggestions

I don't think most of the classes are needed?

Suggested change
className="c-diversion-panel__outline-button c-diversion-panel__outline-button--copy icon-link"
className="icon-link"

variant="outline-primary"
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 @@ -36,7 +43,7 @@ export const ActiveDetourPanel = ({
}: ActiveDetourPanelProps) => {
const backButton = (
<Button
className="c-diversion-panel__back-button icon-link my-3"
className="c-diversion-panel__outline-button c-diversion-panel__outline-button--back icon-link my-3"
variant="outline-primary"
onClick={onNavigateBack}
>
Expand All @@ -52,11 +59,15 @@ export const ActiveDetourPanel = ({
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 className="d-inline-flex justify-content-between">
<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
2 changes: 2 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
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