fix(airtrail): stop labelling a merged multi-leg import "removed in AirTrail"

A multi-leg flight imported "as one flight with a layover" is detached
from sync by design — AirTrail has no single flight to round-trip a
layover chain to, so it is created with sync_enabled=0 (#1535). The
reservations badge collapsed every sync_enabled=0 AirTrail row into "Not
synced" with the tooltip "This flight was removed in AirTrail", which is
false for a merged booking that was never removed (#1646).

Give the multi-leg case (metadata.legs.length > 1) its own state: show
the normal AirTrail badge with a truthful tooltip explaining it stays a
one-time import. A genuinely removed single-leg flight still shows "Not
synced". Adds reservations.airtrail.layoverHint across all locales.
This commit is contained in:
fbnlrz
2026-07-21 22:53:11 +02:00
committed by Maurice
parent 68b0c6bceb
commit 3dc9ac6ac6
25 changed files with 65 additions and 3 deletions
@@ -464,4 +464,33 @@ describe('ReservationsPanel', () => {
const text = document.body.textContent || '';
expect(text.indexOf('Mid flight')).toBeLessThan(text.indexOf('Hotel stay'));
});
// AirTrail sync badge — three states (#1646)
it('FE-PLANNER-RESP-046: a synced AirTrail flight shows the AirTrail badge', () => {
const res = buildReservation({ title: 'Synced flight', type: 'flight', external_source: 'airtrail', sync_enabled: 1 } as any);
render(<ReservationsPanel {...defaultProps} reservations={[res]} />);
expect(screen.getByTitle('Synced from AirTrail — edits stay in sync both ways.')).toBeInTheDocument();
expect(screen.queryByText('Not synced')).not.toBeInTheDocument();
});
it('FE-PLANNER-RESP-047: a multi-leg import shows the layover hint, not the "removed" message', () => {
const res = buildReservation({
title: 'Layover flight', type: 'flight', external_source: 'airtrail', sync_enabled: 0,
metadata: JSON.stringify({ legs: [{ from: 'AMS' }, { from: 'IST' }] }),
} as any);
render(<ReservationsPanel {...defaultProps} reservations={[res]} />);
// Not falsely labelled "Not synced" / "removed in AirTrail"…
expect(screen.queryByText('Not synced')).not.toBeInTheDocument();
// …and carries the truthful layover explanation.
expect(
screen.getByTitle('Imported from AirTrail. A multi-leg flight with a layover has no single AirTrail flight to sync back to, so it stays as a one-time import.'),
).toBeInTheDocument();
});
it('FE-PLANNER-RESP-048: a single-leg flight removed upstream still shows "Not synced"', () => {
const res = buildReservation({ title: 'Removed flight', type: 'flight', external_source: 'airtrail', sync_enabled: 0 } as any);
render(<ReservationsPanel {...defaultProps} reservations={[res]} />);
expect(screen.getByText('Not synced')).toBeInTheDocument();
expect(screen.getByTitle('This flight was removed in AirTrail and no longer syncs.')).toBeInTheDocument();
});
});
@@ -97,6 +97,16 @@ function ReservationCard({ r, tripId, onEdit, onDelete, files = [], onNavigateTo
const typeInfo = getType(r.type)
const TypeIcon = typeInfo.Icon
const confirmed = r.status === 'confirmed'
// A multi-leg AirTrail import is detached from sync *by design* — AirTrail has
// no single flight to round-trip a layover chain to, so it's created with
// sync_enabled=0 (#1535). Distinguish it from a flight that was removed
// upstream so the badge doesn't falsely claim it "was removed in AirTrail" (#1646).
const airtrailMultiLeg = r.external_source === 'airtrail' && !r.sync_enabled && (() => {
try {
const m = typeof r.metadata === 'string' ? JSON.parse(r.metadata || '{}') : (r.metadata || {})
return Array.isArray(m?.legs) && m.legs.length > 1
} catch { return false }
})()
const attachedFiles = files.filter(f => f.reservation_id === r.id || (f.linked_reservation_ids || []).includes(r.id))
const linked = r.assignment_id ? assignmentLookup[r.assignment_id] : null
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
@@ -196,12 +206,12 @@ function ReservationCard({ r, tripId, onEdit, onDelete, files = [], onNavigateTo
) : null}
{r.external_source === 'airtrail' ? (
<span
className={r.sync_enabled ? 'text-[#2563eb] bg-[rgba(59,130,246,0.12)]' : 'text-content-faint bg-surface-tertiary'}
className={r.sync_enabled || airtrailMultiLeg ? 'text-[#2563eb] bg-[rgba(59,130,246,0.12)]' : 'text-content-faint bg-surface-tertiary'}
style={{ display: 'inline-flex', alignItems: 'center', gap: 4, fontSize: 'calc(11px * var(--fs-scale-caption, 1))', fontWeight: 600, padding: '3px 8px', borderRadius: 6 }}
title={r.sync_enabled ? t('reservations.airtrail.syncedHint') : t('reservations.airtrail.notSyncedHint')}
title={r.sync_enabled ? t('reservations.airtrail.syncedHint') : airtrailMultiLeg ? t('reservations.airtrail.layoverHint') : t('reservations.airtrail.notSyncedHint')}
>
<Plane size={11} />
{r.sync_enabled ? t('reservations.airtrail.synced') : t('reservations.airtrail.notSynced')}
{r.sync_enabled || airtrailMultiLeg ? t('reservations.airtrail.synced') : t('reservations.airtrail.notSynced')}
</span>
) : null}
</div>