mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
fix(ci): one save-to-list mapping for both All places views
lint:dup found the trip place to save dialog mapping copied in the desktop and phone views of All places; it is now saveDraftOf in libraryPairs, with a test.
This commit is contained in:
@@ -16,6 +16,7 @@ import LibraryFilterBar from './LibraryFilterBar';
|
||||
import LibraryOrigins from './LibraryOrigins';
|
||||
import LibraryPlaceDetail from './LibraryPlaceDetail';
|
||||
import { detailDock } from './detailDock';
|
||||
import { saveDraftOf } from './libraryPairs';
|
||||
import { usePlaceDuplicates } from './usePlaceDuplicates';
|
||||
import { usePlacesLibrary } from './usePlacesLibrary';
|
||||
|
||||
@@ -284,21 +285,7 @@ export default function PlacesLibraryView({
|
||||
onClose={lib.close}
|
||||
onOpenList={(collectionId, placeId) => navigate(`${placesPath(collectionId)}?place=${placeId}`)}
|
||||
onOpenTrip={(tripId, placeId) => navigate(`/trips/${tripId}?place=${placeId}`)}
|
||||
onSaveToList={(origin, d) =>
|
||||
openSave({
|
||||
name: d.info.name,
|
||||
source_trip_id: origin.trip_id,
|
||||
source_place_id: origin.place_id,
|
||||
description: d.info.description,
|
||||
lat: d.info.lat,
|
||||
lng: d.info.lng,
|
||||
address: d.info.address,
|
||||
category_id: lib.detail?.entry.category?.id ?? null,
|
||||
image_url: d.info.image_url,
|
||||
website: d.info.website,
|
||||
phone: d.info.phone,
|
||||
})
|
||||
}
|
||||
onSaveToList={(origin, d) => openSave(saveDraftOf(origin, d, lib.detail?.entry.category?.id))}
|
||||
onCopyToTrip={setCopyId}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// FE-COMP-LIBPAIRS-001 to FE-COMP-LIBPAIRS-008
|
||||
// FE-COMP-LIBPAIRS-001 to FE-COMP-LIBPAIRS-009
|
||||
import type { PlacesLibraryDetailResponse } from '@trek/shared';
|
||||
|
||||
import {
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
tripDetail,
|
||||
tripOrigin,
|
||||
} from '../../../tests/helpers/placesLibrary';
|
||||
import { originPairs } from './libraryPairs';
|
||||
import { originPairs, saveDraftOf } from './libraryPairs';
|
||||
|
||||
describe('originPairs', () => {
|
||||
it('FE-COMP-LIBPAIRS-001: nothing open gives nothing', () => {
|
||||
@@ -71,4 +71,18 @@ describe('originPairs', () => {
|
||||
it('FE-COMP-LIBPAIRS-008: no description anywhere leaves it undefined', () => {
|
||||
expect(originPairs(bothOrigins()).description).toBeUndefined();
|
||||
});
|
||||
|
||||
it('FE-COMP-LIBPAIRS-009: a trip place goes to the save dialog with what the trip keeps and the category', () => {
|
||||
const origin = tripOrigin({ trip_id: 5, place_id: 8 });
|
||||
const detail = tripDetail({ place_id: 8, info: libraryInfo({ name: 'Arena', website: 'https://arena.example' }) });
|
||||
const draft = saveDraftOf(origin, detail, 3);
|
||||
expect(draft).toMatchObject({
|
||||
name: 'Arena',
|
||||
source_trip_id: 5,
|
||||
source_place_id: 8,
|
||||
category_id: 3,
|
||||
website: 'https://arena.example',
|
||||
});
|
||||
expect(saveDraftOf(origin, detail, undefined).category_id).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,3 +26,21 @@ export function originPairs(data: PlacesLibraryDetailResponse | null): {
|
||||
description: pairs.map((p) => p.detail.info.description).find((d) => d?.trim()) ?? undefined,
|
||||
};
|
||||
}
|
||||
|
||||
/** A trip place of an entry, as the "save to a list" dialog takes it: what the trip keeps, the entry's category. */
|
||||
export function saveDraftOf(origin: TripOrigin, detail: TripDetail, categoryId: number | null | undefined) {
|
||||
const info = detail.info;
|
||||
return {
|
||||
name: info.name,
|
||||
source_trip_id: origin.trip_id,
|
||||
source_place_id: origin.place_id,
|
||||
description: info.description,
|
||||
lat: info.lat,
|
||||
lng: info.lng,
|
||||
address: info.address,
|
||||
category_id: categoryId ?? null,
|
||||
image_url: info.image_url,
|
||||
website: info.website,
|
||||
phone: info.phone,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from 'lucide-react';
|
||||
import { useMemo, useState } from 'react';
|
||||
import CollectionMap from '../../../components/Collections/CollectionMap';
|
||||
import { saveDraftOf } from '../../../components/Collections/libraryPairs';
|
||||
import { originName } from '../../../components/Collections/originName';
|
||||
import { usePlaceDuplicates } from '../../../components/Collections/usePlaceDuplicates';
|
||||
import { usePlacesLibrary, type LibraryKindFilter } from '../../../components/Collections/usePlacesLibrary';
|
||||
@@ -429,21 +430,7 @@ export default function MPlacesLibrary({ categories, language, dark, view, onVie
|
||||
onClose={lib.close}
|
||||
onOpenList={(collectionId, placeId) => navigate(`${placesPath(collectionId)}?place=${placeId}`)}
|
||||
onOpenTrip={(tripId, placeId) => navigate(`/trips/${tripId}?place=${placeId}`)}
|
||||
onSaveToList={(origin, d) =>
|
||||
openSave({
|
||||
name: d.info.name,
|
||||
source_trip_id: origin.trip_id,
|
||||
source_place_id: origin.place_id,
|
||||
description: d.info.description,
|
||||
lat: d.info.lat,
|
||||
lng: d.info.lng,
|
||||
address: d.info.address,
|
||||
category_id: lib.detail?.entry.category?.id ?? null,
|
||||
image_url: d.info.image_url,
|
||||
website: d.info.website,
|
||||
phone: d.info.phone,
|
||||
})
|
||||
}
|
||||
onSaveToList={(origin, d) => openSave(saveDraftOf(origin, d, lib.detail?.entry.category?.id))}
|
||||
onCopyToTrip={(id) => {
|
||||
lib.close();
|
||||
setCopyId(id);
|
||||
|
||||
Reference in New Issue
Block a user