Skip to content

Commit 9a804ed

Browse files
committed
fix(dasha-timeline): derive the heading from the payload so attribute-less hosts read correctly
1 parent e79107c commit 9a804ed

2 files changed

Lines changed: 81 additions & 14 deletions

File tree

packages/ui/src/components/dasha-timeline.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
239239
* Which dasha endpoint fed this element. `sub`, `antara` and `sookshma` are the
240240
* three drill-down levels and render identically; they stay distinct because
241241
* each maps one-to-one onto its endpoint binding, which is what lets a widget
242-
* pick a level. The LABELS come from the payload, not from here.
242+
* pick a level. The heading and the level LABELS come from the payload, not
243+
* from here, so a host that cannot set attributes still renders correctly.
243244
*/
244245
@property({ type: String, reflect: true })
245246
period: 'current' | 'major' | 'sub' | 'antara' | 'sookshma' = 'current';
@@ -248,11 +249,6 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
248249
@state()
249250
private view: 'timeline' | 'readings' | 'frame' = 'timeline';
250251

251-
/** True for any of the drill-down levels, which share one layout. */
252-
private get isDrillDown(): boolean {
253-
return this.period !== 'current' && this.period !== 'major';
254-
}
255-
256252
protected renderEmpty() {
257253
return html`<div class="roxy-empty" role="status">No dasha data</div>`;
258254
}
@@ -412,16 +408,25 @@ export class RoxyDashaTimeline extends RoxyDataElement<DashaData> {
412408
</dl>`;
413409
}
414410

411+
/**
412+
* Heading, decided by the PAYLOAD first and the `period` attribute only as a
413+
* tie-break.
414+
*
415+
* Not every host can set the attribute. The WordPress plugin maps an
416+
* operationId to a bare component tag with no attrs, so every dasha shortcode
417+
* arrives with the default `period="current"`; keying off the attribute alone
418+
* titled an antardasha list "Active dashas" there. A drill-down response is
419+
* self-identifying (it carries a parent period), so the markup does not need
420+
* to be told.
421+
*/
415422
private heading(d: DashaData): string {
416-
if (this.period === 'major') return 'Vimshottari Mahadasha';
417-
if (this.isDrillDown) {
418-
const parent = parentOf(d);
419-
const level = levelOf(d);
420-
return parent
421-
? `${level}s in ${parent.period.planet} ${parent.label}`
422-
: `${level}s`;
423+
const parent = parentOf(d);
424+
if (parent) {
425+
return `${levelOf(d)}s in ${parent.period.planet} ${parent.label}`;
423426
}
424-
return 'Active dashas';
427+
if ('mahadashas' in d) return 'Vimshottari Mahadasha';
428+
if ('mahadasha' in d) return 'Active dashas';
429+
return this.period === 'major' ? 'Vimshottari Mahadasha' : 'Active dashas';
425430
}
426431

427432
/**

packages/ui/tests/components.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,3 +2094,65 @@ describe('roxy-dasha-timeline date column adapts to the period length', () => {
20942094
el.remove();
20952095
});
20962096
});
2097+
2098+
/**
2099+
* A host that cannot pass attributes must still get correct headings. The
2100+
* WordPress plugin maps an operationId to a bare tag with no attrs, so every
2101+
* dasha shortcode arrives with the default `period="current"`; the heading has to
2102+
* come from the payload or an antardasha list is titled "Active dashas" there.
2103+
*/
2104+
describe('roxy-dasha-timeline heads correctly with no period attribute', () => {
2105+
async function mountNoAttrs(data: unknown) {
2106+
const el = document.createElement('roxy-dasha-timeline') as HTMLElement & {
2107+
data?: unknown;
2108+
};
2109+
document.body.appendChild(el);
2110+
el.data = data;
2111+
await settled(el);
2112+
return el;
2113+
}
2114+
const heading = (el: Element) =>
2115+
el.shadowRoot?.querySelector('.title')?.textContent?.trim() ?? '';
2116+
2117+
test('a drill-down payload titles itself, not "Active dashas"', async () => {
2118+
const el = await mountNoAttrs({
2119+
mahadashaLord: 'Saturn',
2120+
antardashaLord: 'Venus',
2121+
antardashaPeriod: { planet: 'Venus', durationYears: 3.2 },
2122+
pratyantardashas: [
2123+
{
2124+
planet: 'Venus',
2125+
startDate: '2025-06-20T00:00:00',
2126+
endDate: '2025-12-29T00:00:00',
2127+
durationYears: 0.5,
2128+
},
2129+
],
2130+
});
2131+
expect(heading(el)).toBe('Pratyantardashas in Venus Antardasha');
2132+
el.remove();
2133+
});
2134+
2135+
test('a major payload titles itself', async () => {
2136+
const el = await mountNoAttrs({
2137+
mahadashas: [
2138+
{
2139+
planet: 'Ketu',
2140+
startDate: '1990-01-15T00:00:00',
2141+
endDate: '1997-01-15T00:00:00',
2142+
durationYears: 7,
2143+
},
2144+
],
2145+
});
2146+
expect(heading(el)).toBe('Vimshottari Mahadasha');
2147+
el.remove();
2148+
});
2149+
2150+
test('a current payload still reads as the running periods', async () => {
2151+
const el = await mountNoAttrs({
2152+
mahadasha: { planet: 'Saturn' },
2153+
antardasha: { planet: 'Venus' },
2154+
});
2155+
expect(heading(el)).toBe('Active dashas');
2156+
el.remove();
2157+
});
2158+
});

0 commit comments

Comments
 (0)