fix: display numeric tracked prices

This commit is contained in:
TopherMayor
2026-04-30 12:15:43 -07:00
parent 3e0a462431
commit 4a83abf05e

View File

@@ -1887,6 +1887,23 @@
`;
}
function formatSourcePrice(source) {
if (!source) return '';
return typeof source.latestPrice === 'number'
? formatCurrency(source.latestPrice, source.currency || 'USD')
: source.latestDisplayPrice || '';
}
function getPointContext(point) {
if (!point) return '';
const unitContext = point.tripNights && point.unitPrice
? `${formatCurrency(point.unitPrice, point.currency || 'USD')} x ${point.tripNights} nights`
: '';
return [unitContext, point.unitDisplayPrice || point.displayPrice || point.decisionNote || '']
.filter(Boolean)
.join(' · ');
}
function renderSourceSelect(opt) {
const sources = getAvailableSources(opt);
if (sources.length <= 1) {
@@ -1894,7 +1911,7 @@
const sourceLabel = source?.sourceLabel || opt.automationInsights?.source || 'Unknown source';
const meta = source ? [
formatBookingType(source.bookingType, source.priceBasis),
source.latestDisplayPrice || (typeof source.latestPrice === 'number' ? formatCurrency(source.latestPrice, source.currency || 'USD') : ''),
formatSourcePrice(source),
source.pointCount ? `${source.pointCount} point${source.pointCount === 1 ? '' : 's'}` : '',
].filter(Boolean).join(' · ') : '';
return `
@@ -1909,7 +1926,7 @@
const labelParts = [
source.sourceLabel || 'Unknown source',
formatBookingType(source.bookingType, source.priceBasis),
source.latestDisplayPrice || (typeof source.latestPrice === 'number' ? formatCurrency(source.latestPrice, source.currency || 'USD') : ''),
formatSourcePrice(source),
source.pointCount ? `${source.pointCount} pt${source.pointCount === 1 ? '' : 's'}` : '',
].filter(Boolean);
return `<option value="${escapeHtml(source.sourceKey)}"${source.sourceKey === selectedSourceKey ? ' selected' : ''}>${escapeHtml(labelParts.join(' · '))}</option>`;
@@ -1935,7 +1952,8 @@
currency: selectedPoint.currency || 'USD',
} : (opt.automationInsights || {});
const currentPrice = typeof selectedPoint?.price === 'number' ? formatCurrency(selectedPoint.price, insights.currency || 'USD') : '';
const priceLabel = selectedPoint?.displayPrice || insights.displayPrice || currentPrice || 'Not yet tracked';
const priceLabel = currentPrice || insights.displayPrice || 'Not yet tracked';
const priceContext = getPointContext(selectedPoint);
const sourceLabel = selectedMeta?.sourceLabel || insights.source || 'Automation feed';
const bookingLabel = formatBookingType(
selectedMeta?.bookingType || insights.bookingType,
@@ -1949,7 +1967,7 @@
const inclusions = normalizeTextList(selectedPoint?.inclusions || opt.automationInsights?.inclusions);
const limitations = normalizeTextList(selectedPoint?.limitations || opt.automationInsights?.limitations);
const sourceMetaLine = selectedMeta
? [selectedMeta.latestDisplayPrice || priceLabel, selectedMeta.pointCount ? `${selectedMeta.pointCount} point${selectedMeta.pointCount === 1 ? '' : 's'}` : '']
? [formatSourcePrice(selectedMeta) || priceLabel, selectedMeta.pointCount ? `${selectedMeta.pointCount} point${selectedMeta.pointCount === 1 ? '' : 's'}` : '']
.filter(Boolean)
.join(' · ')
: '';
@@ -1961,6 +1979,7 @@
<div class="option-fact">
<span class="option-fact-label">Current price</span>
<div class="option-fact-value">${escapeHtml(priceLabel)}</div>
${priceContext ? `<div class="option-source-sub">${escapeHtml(priceContext)}</div>` : ''}
</div>
<div class="option-fact">
<span class="option-fact-label">Source</span>
@@ -2088,13 +2107,16 @@
: `${delta > 0 ? '+' : ''}${formatCurrency(Math.abs(delta), latest.currency)}`;
const checkedLabel = latest.checkedAt ? formatTrackedDate(latest.checkedAt) : '';
const sourceLabel = selectedMeta?.sourceLabel || latest.source || 'Tracked source';
const latestPriceLabel = formatCurrency(latest.price, latest.currency) || 'Tracked price';
const latestContext = getPointContext(latest);
return `
<div class="price-trend">
<div class="price-trend-header">
<div>
<div class="price-trend-label">Automation price trail</div>
<div class="price-trend-value">${escapeHtml(sourceLabel)} · ${escapeHtml(latest.displayPrice || formatCurrency(latest.price, latest.currency) || 'Tracked price')}</div>
<div class="price-trend-value">${escapeHtml(sourceLabel)} · ${escapeHtml(latestPriceLabel)}</div>
${latestContext ? `<div class="price-trend-sub">${escapeHtml(latestContext)}</div>` : ''}
</div>
<div class="price-trend-sub">${series.length} point${series.length === 1 ? '' : 's'}${checkedLabel ? ` · ${checkedLabel}` : ''}</div>
</div>
@@ -2113,7 +2135,7 @@
<path d="${path}" class="price-trend-line" stroke="url(#priceTrendStroke-${chartKey})"></path>
${points.map((point, index) => `
<circle class="price-trend-points" cx="${point.x.toFixed(1)}" cy="${point.y.toFixed(1)}" r="${index === points.length - 1 ? 3.4 : 2.4}">
<title>${(point.displayPrice || formatCurrency(point.price, point.currency) || 'Tracked price')} · ${formatTrackedDate(point.checkedAt) || 'automation run'}</title>
<title>${formatCurrency(point.price, point.currency) || 'Tracked price'}${getPointContext(point) ? ` · ${getPointContext(point)}` : ''} · ${formatTrackedDate(point.checkedAt) || 'automation run'}</title>
</circle>
`).join('')}
</svg>