Skip to content

Commit

Permalink
feat: hide open map button when already on map page (#2282)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemald authored Nov 16, 2023
1 parent 5a7ba3a commit db83e0e
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 30 deletions.
78 changes: 59 additions & 19 deletions assets/src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import { allOpenRouteIds } from "../models/routeTab"
import Nav from "./nav"
import RightPanel from "./rightPanel"
import { mapModeForUser } from "../util/mapMode"
import { Ghost, VehicleInScheduledService } from "../realtime"
import { Ghost, Vehicle, VehicleInScheduledService } from "../realtime"
import MapPage from "./mapPage"
import SearchPage from "./searchPage"
import { OpenView, isPagePath } from "../state/pagePanelState"
import { usePanelStateFromStateDispatchContext } from "../hooks/usePanelState"
import PropertiesPanel from "./propertiesPanel"
import { isGhost, isVehicle } from "../models/vehicle"
import { TabMode } from "./propertiesPanel/tabPanels"

export const AppRoutes = () => {
useAppcues()
Expand Down Expand Up @@ -74,24 +75,14 @@ export const AppRoutes = () => {
<Routes>
<Route
element={
<>
<Outlet />
<RightPanel
openView={openView}
propertiesPanel={
selectedVehicleOrGhost &&
(isVehicle(selectedVehicleOrGhost) ||
isGhost(selectedVehicleOrGhost)) ? (
<PropertiesPanel
selectedVehicleOrGhost={selectedVehicleOrGhost}
tabMode={vppTabMode ?? "status"}
onChangeTabMode={setTabMode}
onClosePanel={closeView}
/>
) : undefined
}
/>
</>
<RouteElement
selectedVehicleOrGhost={selectedVehicleOrGhost}
openView={openView}
openMapEnabled={true}
vppTabMode={vppTabMode}
setTabMode={setTabMode}
closeView={closeView}
/>
}
>
<BrowserRoute path="/" element={<LadderPage />} />
Expand All @@ -100,6 +91,19 @@ export const AppRoutes = () => {
element={<ShuttleMapPage />}
/>
<BrowserRoute path="/settings" element={<SettingsPage />} />
</Route>
<Route
element={
<RouteElement
selectedVehicleOrGhost={selectedVehicleOrGhost}
openView={openView}
openMapEnabled={false}
vppTabMode={vppTabMode}
setTabMode={setTabMode}
closeView={closeView}
/>
}
>
<BrowserRoute path={mapMode.path} element={mapElement} />
</Route>
</Routes>
Expand All @@ -111,6 +115,42 @@ export const AppRoutes = () => {
)
}

const RouteElement = ({
openMapEnabled,
selectedVehicleOrGhost,
openView,
vppTabMode,
setTabMode,
closeView,
}: {
openMapEnabled: boolean
selectedVehicleOrGhost?: Vehicle | Ghost | null
openView: OpenView
vppTabMode?: TabMode
setTabMode: (mode: TabMode) => void
closeView: () => void
}) => (
<>
<Outlet />
<RightPanel
openView={openView}
propertiesPanel={
selectedVehicleOrGhost &&
(isVehicle(selectedVehicleOrGhost) ||
isGhost(selectedVehicleOrGhost)) ? (
<PropertiesPanel
selectedVehicleOrGhost={selectedVehicleOrGhost}
tabMode={vppTabMode ?? "status"}
onChangeTabMode={setTabMode}
onClosePanel={closeView}
openMapEnabled={openMapEnabled}
/>
) : undefined
}
/>
</>
)

const App = (): ReactElement<HTMLDivElement> => {
return (
<BrowserRouter>
Expand Down
3 changes: 3 additions & 0 deletions assets/src/components/propertiesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { TabMode } from "./propertiesPanel/tabPanels"

interface Props extends IndividualPropertiesPanelProps {
selectedVehicleOrGhost: Vehicle | Ghost
openMapEnabled: boolean
}

export type TabModeProps = {
Expand Down Expand Up @@ -38,6 +39,7 @@ const PropertiesPanel = ({
tabMode,
onChangeTabMode,
onClosePanel,
openMapEnabled,
}: Props) => {
const { socket } = useSocket()
const liveVehicle = useVehicleForId(socket, selectedVehicleOrGhost.id)
Expand Down Expand Up @@ -68,6 +70,7 @@ const PropertiesPanel = ({
tabMode={tabMode}
onChangeTabMode={onChangeTabMode}
onClosePanel={onClosePanel}
openMapEnabled={openMapEnabled}
/>
) : (
<GhostPropertiesPanel
Expand Down
8 changes: 7 additions & 1 deletion assets/src/components/propertiesPanel/miniMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ const MiniMap = ({
vehicle,
shapes,
routeVehicles,
openMapEnabled,
}: {
vehicle: Vehicle
shapes: Shape[]
routeVehicles: VehicleInScheduledService[]
openMapEnabled: boolean
}) => {
const stations: Stop[] | null = useStations()

Expand All @@ -65,7 +67,11 @@ const MiniMap = ({
stations={stations}
allowFullscreen={!inMapBetaGroup}
>
<>{inMapBetaGroup && <SearchMapLink vehicleId={vehicle.id} />}</>
<>
{inMapBetaGroup && openMapEnabled && (
<SearchMapLink vehicleId={vehicle.id} />
)}
</>
</MapFollowingPrimaryVehicles>
)
}
Expand Down
33 changes: 28 additions & 5 deletions assets/src/components/propertiesPanel/vehiclePropertiesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { DirectionsButton } from "../directionsButton"

type Props = {
selectedVehicle: Vehicle
openMapEnabled: boolean
} & IndividualPropertiesPanelProps

const InvalidBanner = () => (
Expand Down Expand Up @@ -72,7 +73,13 @@ const useRouteVehicles = (
.filter((v) => v.id !== primaryVehicleId)
}

const Location = ({ vehicle }: { vehicle: Vehicle }) => {
const Location = ({
vehicle,
openMapEnabled,
}: {
vehicle: Vehicle
openMapEnabled: boolean
}) => {
const routeVehicles: VehicleInScheduledService[] = useRouteVehicles(
vehicle.routeId,
vehicle.id
Expand Down Expand Up @@ -113,6 +120,7 @@ const Location = ({ vehicle }: { vehicle: Vehicle }) => {
vehicle={vehicle}
routeVehicles={routeVehicles}
shapes={shapes}
openMapEnabled={openMapEnabled}
/>
</div>
</div>
Expand Down Expand Up @@ -163,7 +171,13 @@ const inDebugMode = (): boolean =>
const shouldShowDataDiscrepancies = ({ dataDiscrepancies }: Vehicle): boolean =>
inDebugMode() && dataDiscrepancies.length > 0

const StatusContent = ({ selectedVehicle }: { selectedVehicle: Vehicle }) => (
const StatusContent = ({
selectedVehicle,
openMapEnabled,
}: {
selectedVehicle: Vehicle
openMapEnabled: boolean
}) => (
<>
<div className="c-vehicle-properties-panel__notes">
{selectedVehicle.isOffCourse && <InvalidBanner />}
Expand All @@ -177,7 +191,7 @@ const StatusContent = ({ selectedVehicle }: { selectedVehicle: Vehicle }) => (

<CrowdingDiagram crowding={selectedVehicle.crowding} />

<Location vehicle={selectedVehicle} />
<Location vehicle={selectedVehicle} openMapEnabled={openMapEnabled} />

{shouldShowDataDiscrepancies(selectedVehicle) && (
<DataDiscrepancies vehicle={selectedVehicle} />
Expand All @@ -190,6 +204,7 @@ const VehiclePropertiesPanel = ({
tabMode,
onChangeTabMode,
onClosePanel,
openMapEnabled,
}: Props) => {
return (
<div className="c-vehicle-properties-panel">
Expand All @@ -210,11 +225,19 @@ const VehiclePropertiesPanel = ({
{isVehicleInScheduledService(selectedVehicle) ? (
<TabPanels
vehicleOrGhost={selectedVehicle}
statusContent={<StatusContent selectedVehicle={selectedVehicle} />}
statusContent={
<StatusContent
selectedVehicle={selectedVehicle}
openMapEnabled={openMapEnabled}
/>
}
mode={tabMode}
/>
) : (
<StatusContent selectedVehicle={selectedVehicle} />
<StatusContent
selectedVehicle={selectedVehicle}
openMapEnabled={openMapEnabled}
/>
)}
</div>
)
Expand Down
1 change: 1 addition & 0 deletions assets/tests/components/propertiesPanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const PropertiesPanelWrapper: React.FC<{
selectedVehicleOrGhost={vehicleOrGhost}
onClosePanel={closePanel || jest.fn()}
initialTab={initialTab}
openMapEnabled={true}
/>
</RoutesProvider>
)
Expand Down
55 changes: 50 additions & 5 deletions assets/tests/components/propertiesPanel/miniMap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ describe("MiniMap", () => {
render(
<MemoryRouter initialEntries={["/"]}>
<StateDispatchProvider state={initialState} dispatch={mockDispatch}>
<MiniMap vehicle={vehicle} routeVehicles={[]} shapes={[]} />
<MiniMap
vehicle={vehicle}
routeVehicles={[]}
shapes={[]}
openMapEnabled={true}
/>
</StateDispatchProvider>
</MemoryRouter>
)
Expand All @@ -88,10 +93,35 @@ describe("MiniMap", () => {
)
})

test("Map does not include link to open vehicle in search map page when disabled by prop", async () => {
const mockDispatch = jest.fn()

render(
<MemoryRouter initialEntries={["/"]}>
<StateDispatchProvider state={initialState} dispatch={mockDispatch}>
<MiniMap
vehicle={vehicle}
routeVehicles={[]}
shapes={[]}
openMapEnabled={false}
/>
</StateDispatchProvider>
</MemoryRouter>
)
expect(
screen.queryByRole("link", { name: "Open Map" })
).not.toBeInTheDocument()
})

test("Map doesn't include fullscreen button", () => {
render(
<MemoryRouter initialEntries={["/"]}>
<MiniMap vehicle={vehicle} routeVehicles={[]} shapes={[]} />
<MiniMap
vehicle={vehicle}
routeVehicles={[]}
shapes={[]}
openMapEnabled={true}
/>
</MemoryRouter>
)
expect(
Expand All @@ -107,7 +137,12 @@ describe("MiniMap", () => {
test("Map does not include link to open vehicle in search map page", () => {
render(
<MemoryRouter initialEntries={["/"]}>
<MiniMap vehicle={vehicle} routeVehicles={[]} shapes={[]} />
<MiniMap
vehicle={vehicle}
routeVehicles={[]}
shapes={[]}
openMapEnabled={true}
/>
</MemoryRouter>
)
expect(
Expand All @@ -118,7 +153,12 @@ describe("MiniMap", () => {
test("Map does include fullscreen button", () => {
render(
<MemoryRouter initialEntries={["/"]}>
<MiniMap vehicle={vehicle} routeVehicles={[]} shapes={[]} />
<MiniMap
vehicle={vehicle}
routeVehicles={[]}
shapes={[]}
openMapEnabled={true}
/>
</MemoryRouter>
)
expect(
Expand All @@ -129,7 +169,12 @@ describe("MiniMap", () => {
test("Doesn't have layers control", () => {
render(
<MemoryRouter initialEntries={["/"]}>
<MiniMap vehicle={vehicle} routeVehicles={[]} shapes={[]} />
<MiniMap
vehicle={vehicle}
routeVehicles={[]}
shapes={[]}
openMapEnabled={true}
/>
</MemoryRouter>
)
expect(layersControlButton.query()).toBeNull()
Expand Down
Loading

0 comments on commit db83e0e

Please sign in to comment.