fix: display numeric tracked prices
This commit is contained in:
@@ -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) {
|
function renderSourceSelect(opt) {
|
||||||
const sources = getAvailableSources(opt);
|
const sources = getAvailableSources(opt);
|
||||||
if (sources.length <= 1) {
|
if (sources.length <= 1) {
|
||||||
@@ -1894,7 +1911,7 @@
|
|||||||
const sourceLabel = source?.sourceLabel || opt.automationInsights?.source || 'Unknown source';
|
const sourceLabel = source?.sourceLabel || opt.automationInsights?.source || 'Unknown source';
|
||||||
const meta = source ? [
|
const meta = source ? [
|
||||||
formatBookingType(source.bookingType, source.priceBasis),
|
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'}` : '',
|
source.pointCount ? `${source.pointCount} point${source.pointCount === 1 ? '' : 's'}` : '',
|
||||||
].filter(Boolean).join(' · ') : '';
|
].filter(Boolean).join(' · ') : '';
|
||||||
return `
|
return `
|
||||||
@@ -1909,7 +1926,7 @@
|
|||||||
const labelParts = [
|
const labelParts = [
|
||||||
source.sourceLabel || 'Unknown source',
|
source.sourceLabel || 'Unknown source',
|
||||||
formatBookingType(source.bookingType, source.priceBasis),
|
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'}` : '',
|
source.pointCount ? `${source.pointCount} pt${source.pointCount === 1 ? '' : 's'}` : '',
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
return `<option value="${escapeHtml(source.sourceKey)}"${source.sourceKey === selectedSourceKey ? ' selected' : ''}>${escapeHtml(labelParts.join(' · '))}</option>`;
|
return `<option value="${escapeHtml(source.sourceKey)}"${source.sourceKey === selectedSourceKey ? ' selected' : ''}>${escapeHtml(labelParts.join(' · '))}</option>`;
|
||||||
@@ -1935,7 +1952,8 @@
|
|||||||
currency: selectedPoint.currency || 'USD',
|
currency: selectedPoint.currency || 'USD',
|
||||||
} : (opt.automationInsights || {});
|
} : (opt.automationInsights || {});
|
||||||
const currentPrice = typeof selectedPoint?.price === 'number' ? formatCurrency(selectedPoint.price, insights.currency || 'USD') : '';
|
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 sourceLabel = selectedMeta?.sourceLabel || insights.source || 'Automation feed';
|
||||||
const bookingLabel = formatBookingType(
|
const bookingLabel = formatBookingType(
|
||||||
selectedMeta?.bookingType || insights.bookingType,
|
selectedMeta?.bookingType || insights.bookingType,
|
||||||
@@ -1949,7 +1967,7 @@
|
|||||||
const inclusions = normalizeTextList(selectedPoint?.inclusions || opt.automationInsights?.inclusions);
|
const inclusions = normalizeTextList(selectedPoint?.inclusions || opt.automationInsights?.inclusions);
|
||||||
const limitations = normalizeTextList(selectedPoint?.limitations || opt.automationInsights?.limitations);
|
const limitations = normalizeTextList(selectedPoint?.limitations || opt.automationInsights?.limitations);
|
||||||
const sourceMetaLine = selectedMeta
|
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)
|
.filter(Boolean)
|
||||||
.join(' · ')
|
.join(' · ')
|
||||||
: '';
|
: '';
|
||||||
@@ -1961,6 +1979,7 @@
|
|||||||
<div class="option-fact">
|
<div class="option-fact">
|
||||||
<span class="option-fact-label">Current price</span>
|
<span class="option-fact-label">Current price</span>
|
||||||
<div class="option-fact-value">${escapeHtml(priceLabel)}</div>
|
<div class="option-fact-value">${escapeHtml(priceLabel)}</div>
|
||||||
|
${priceContext ? `<div class="option-source-sub">${escapeHtml(priceContext)}</div>` : ''}
|
||||||
</div>
|
</div>
|
||||||
<div class="option-fact">
|
<div class="option-fact">
|
||||||
<span class="option-fact-label">Source</span>
|
<span class="option-fact-label">Source</span>
|
||||||
@@ -2088,13 +2107,16 @@
|
|||||||
: `${delta > 0 ? '+' : '−'}${formatCurrency(Math.abs(delta), latest.currency)}`;
|
: `${delta > 0 ? '+' : '−'}${formatCurrency(Math.abs(delta), latest.currency)}`;
|
||||||
const checkedLabel = latest.checkedAt ? formatTrackedDate(latest.checkedAt) : '';
|
const checkedLabel = latest.checkedAt ? formatTrackedDate(latest.checkedAt) : '';
|
||||||
const sourceLabel = selectedMeta?.sourceLabel || latest.source || 'Tracked source';
|
const sourceLabel = selectedMeta?.sourceLabel || latest.source || 'Tracked source';
|
||||||
|
const latestPriceLabel = formatCurrency(latest.price, latest.currency) || 'Tracked price';
|
||||||
|
const latestContext = getPointContext(latest);
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<div class="price-trend">
|
<div class="price-trend">
|
||||||
<div class="price-trend-header">
|
<div class="price-trend-header">
|
||||||
<div>
|
<div>
|
||||||
<div class="price-trend-label">Automation price trail</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>
|
||||||
<div class="price-trend-sub">${series.length} point${series.length === 1 ? '' : 's'}${checkedLabel ? ` · ${checkedLabel}` : ''}</div>
|
<div class="price-trend-sub">${series.length} point${series.length === 1 ? '' : 's'}${checkedLabel ? ` · ${checkedLabel}` : ''}</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -2113,7 +2135,7 @@
|
|||||||
<path d="${path}" class="price-trend-line" stroke="url(#priceTrendStroke-${chartKey})"></path>
|
<path d="${path}" class="price-trend-line" stroke="url(#priceTrendStroke-${chartKey})"></path>
|
||||||
${points.map((point, index) => `
|
${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}">
|
<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>
|
</circle>
|
||||||
`).join('')}
|
`).join('')}
|
||||||
</svg>
|
</svg>
|
||||||
|
|||||||
Reference in New Issue
Block a user