mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 05:21:15 +00:00
fix(pdf): give up a routing export once its dialog or sheet is gone
A PDF of a long trip routes for minutes, and only the skip button could stop it. Closing the export dialog, hiding the phone sheet or leaving the trip left the legs going out and opened the document later on whatever page the user was on. Closing now stops the routing and the document never opens; skipping still prints without the remaining legs. The plan filter moves from TripPDF to pdfScope beside the other plan predicate, which keeps TripPDF under its size entry. The routing test name gets its quotes back, and the export dialog and sheet tests cover the leg count, the skip button and closing while routing.
This commit is contained in:
@@ -393,4 +393,15 @@ describe('trip route map in the PDF', () => {
|
||||
.toEqual([[48.86, 2.35], [48.88, 2.5], [48.90, 2.42]])
|
||||
expect(onProgress).toHaveBeenLastCalledWith(2, 2)
|
||||
})
|
||||
|
||||
it('FE-COMP-TRIPPDF-MAP-016: an export given up while it routes opens no document', async () => {
|
||||
const givenUp = new AbortController()
|
||||
vi.mocked(calculateRouteWithLegs).mockImplementation(async (points) => {
|
||||
givenUp.abort()
|
||||
return { coordinates: points.map(p => [p.lat, p.lng] as [number, number]), distance: 0, duration: 0, legs: [leg(12000)] }
|
||||
})
|
||||
await downloadTripPDF({ ...args, signal: givenUp.signal })
|
||||
|
||||
expect(document.getElementById('pdf-preview-overlay')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -20,8 +20,7 @@ import { routeDistanceLabel } from '../Map/tripRouteLabels'
|
||||
import { drawTripRoute, type TripPdfRouteOptions } from './tripPdfRoute'
|
||||
import { fetchExchangeRates } from '../../hooks/useExchangeRates'
|
||||
import { getFlightLegs, getTrainLegs, usesStationRoute } from '../../utils/flightLegs'
|
||||
import { isServiceStopType } from '../Roadtrip/roadtripModel'
|
||||
import { onlyMyPlan } from './pdfScope'
|
||||
import { onlyMyPlan, planAssignments } from './pdfScope'
|
||||
import { createPdfMarkdown, PDF_MARKDOWN_CSS } from './pdfMarkdown'
|
||||
|
||||
/**
|
||||
@@ -201,27 +200,13 @@ interface downloadTripPDFProps {
|
||||
onlyUserId?: number
|
||||
/** The planner's road trip vias and tour stages, and the routing progress and stop (#2876). */
|
||||
route?: TripPdfRouteOptions
|
||||
}
|
||||
|
||||
/**
|
||||
* The stops the day plan lists, out of everything the store holds for the trip.
|
||||
*
|
||||
* The stop a booked night wrote onto its check-in day is out whatever the switch says:
|
||||
* the day already shows that booking as its accommodation block, and the row would be
|
||||
* the same hotel a second time. The service stops go with the setting. One predicate
|
||||
* for the whole document, so the day lists, the route map, the cover's planned count
|
||||
* and every cost total agree with the plan and with each other, whichever shell asked.
|
||||
*/
|
||||
function planAssignments(assignments: AssignmentsMap, showServiceStops: boolean): AssignmentsMap {
|
||||
return Object.fromEntries(Object.entries(assignments).map(([dayId, list]) => [
|
||||
dayId,
|
||||
(list || []).filter(a => a.accommodation_id == null && (showServiceStops || !isServiceStopType(a.place?.stop_type))),
|
||||
]))
|
||||
/** Aborted once nobody waits for the document any more (its dialog was closed): it then never opens. */
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
// `assignments` is normalised here once, to the plan's own list; every read below
|
||||
// (and fetchPlacePhotos) relies on it being an object.
|
||||
export async function downloadTripPDF({ trip, days, places, assignments: allStored = {}, categories, dayNotes, reservations: allReservations = [], t: _t, locale: _locale, timeFormat: _timeFormat, distanceUnit: _distanceUnit, showServiceStops = true, budgetItems, costsEnabled, onlyUserId, route }: downloadTripPDFProps) {
|
||||
export async function downloadTripPDF({ trip, days, places, assignments: allStored = {}, categories, dayNotes, reservations: allReservations = [], t: _t, locale: _locale, timeFormat: _timeFormat, distanceUnit: _distanceUnit, showServiceStops = true, budgetItems, costsEnabled, onlyUserId, route, signal }: downloadTripPDFProps) {
|
||||
const { assignments: stored, reservations } = onlyUserId != null
|
||||
? onlyMyPlan(allStored, allReservations, onlyUserId)
|
||||
: { assignments: allStored, reservations: allReservations }
|
||||
@@ -904,6 +889,7 @@ ${daysHtml}
|
||||
${pluginSectionsHtml}
|
||||
</body></html>`
|
||||
markdown.dispose()
|
||||
if (signal?.aborted) return
|
||||
|
||||
// Open in modal with srcdoc iframe (no URL loading = no X-Frame-Options issue)
|
||||
const overlay = document.createElement('div')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { AssignmentsMap } from '../../types'
|
||||
import { isServiceStopType } from '../Roadtrip/roadtripModel'
|
||||
|
||||
interface WithTravelers { travelers?: { user_id: number }[] | null }
|
||||
|
||||
@@ -27,3 +28,19 @@ export function onlyMyPlan<R extends WithTravelers>(
|
||||
reservations: reservations.filter(r => mine(r.travelers)),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The stops the day plan lists, out of everything the store holds for the trip.
|
||||
*
|
||||
* The stop a booked night wrote onto its check-in day is out whatever the switch says:
|
||||
* the day already shows that booking as its accommodation block, and the row would be
|
||||
* the same hotel a second time. The service stops go with the setting. One predicate
|
||||
* for the whole document, so the day lists, the route map, the cover's planned count
|
||||
* and every cost total agree with the plan and with each other, whichever shell asked.
|
||||
*/
|
||||
export function planAssignments(assignments: AssignmentsMap, showServiceStops: boolean): AssignmentsMap {
|
||||
return Object.fromEntries(Object.entries(assignments).map(([dayId, list]) => [
|
||||
dayId,
|
||||
(list || []).filter(a => a.accommodation_id == null && (showServiceStops || !isServiceStopType(a.place?.stop_type))),
|
||||
]))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user