Skip to content

Commit bc718ac

Browse files
chore: Add support for panorama in isolated widgets (#141)
1 parent ed3ca20 commit bc718ac

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/internal/base-component/__tests__/panorama-metrics.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PanoramaClient } from '../metrics/log-clients';
66
declare global {
77
interface Window {
88
panorama?: any;
9+
[key: symbol]: any;
910
}
1011
}
1112

@@ -86,4 +87,20 @@ describe('PanoramaClient', () => {
8687
panorama.sendMetric({ timestamp: 15 });
8788
expect(window.panorama).toHaveBeenCalledWith('trackCustomEvent', expect.objectContaining({ timestamp: 15 }));
8889
});
90+
91+
test('finds panorama function from Symbol.for("panorama") property', () => {
92+
// Remove the regular panorama property
93+
delete window.panorama;
94+
95+
const mockPanoramaSymbolFn = jest.fn();
96+
const panoramaSymbol = Symbol.for('panorama');
97+
(window as any)[panoramaSymbol] = mockPanoramaSymbolFn;
98+
99+
panorama.sendMetric({ eventValue: 'symbol-test' });
100+
101+
expect(mockPanoramaSymbolFn).toHaveBeenCalledWith(
102+
'trackCustomEvent',
103+
expect.objectContaining({ eventType: 'awsui', eventValue: 'symbol-test' })
104+
);
105+
});
89106
});

src/internal/base-component/metrics/log-clients.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ export class PanoramaClient {
142142
return currentWindow?.panorama;
143143
}
144144

145+
const panoramaSymbol = Symbol.for('panorama');
146+
const symbolProperty = (currentWindow as any)?.[panoramaSymbol];
147+
if (typeof symbolProperty === 'function') {
148+
return symbolProperty as PanoramaFunction;
149+
}
150+
145151
if (!currentWindow || currentWindow.parent === currentWindow) {
146152
// When the window has no more parents, it references itself
147153
return undefined;

0 commit comments

Comments
 (0)