Skip to content

Commit 8dea77a

Browse files
Merge pull request #60 from ServerlessLife/57-filtering-broken-no-messages-displayed
fix: Add mappings from stackName to topic to fix an issue with messages not rendering
2 parents 63a6cec + 3e72932 commit 8dea77a

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

.prettierrc.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cli.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ async function run() {
177177
if (request.url === '/stackList') {
178178
response.writeHead(200, { 'Content-Type': 'application/json' });
179179
response.end(JSON.stringify(stackList), 'utf-8');
180+
} else if (request.url === '/stackTopicMappings') {
181+
response.writeHead(200, { 'Content-Type': 'application/json' });
182+
const mappings: Record<string, string> = {};
183+
if (cdkOutput) {
184+
for (const [stackName, stack] of Object.entries(cdkOutput)) {
185+
if (stack.ServerlessSpyWsUrl) {
186+
const [_, scope] = stack.ServerlessSpyWsUrl.split('/');
187+
if (scope) {
188+
mappings[stackName] = scope;
189+
}
190+
}
191+
}
192+
}
193+
response.end(JSON.stringify(mappings), 'utf-8');
180194
} else if (request.url?.match('^/wsUrl')) {
181195
response.writeHead(200, { 'Content-Type': 'text/html' });
182196
response.end(`ws:localhost:${options.wsport}`, 'utf-8');

cli/webServerlessSpy.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function run() {
3030
> = {};
3131
let uiNeedsRefresh = false;
3232
let stackList: string[] | undefined;
33+
let stackNameToTopicMappings: Record<string, string> | undefined;
3334
const selectedStackLocalStorageKey = 'selectedStack';
3435
let ws: WebSocket;
3536
let selectedStack: string | undefined;
@@ -75,6 +76,7 @@ function run() {
7576
void (async () => {
7677
await fillStacks();
7778
await connectToWebSocket();
79+
await loadStackNameToTopicMappings();
7880
})();
7981
window.requestAnimationFrame(render);
8082
setupTooltip();
@@ -120,6 +122,24 @@ function run() {
120122
stackList && stackList.length > 1 ? '' : 'none';
121123
}
122124

125+
function canFilterOnTopic() {
126+
return (
127+
stackList &&
128+
stackList?.length > 1 &&
129+
stackNameToTopicMappings &&
130+
Object.values(stackNameToTopicMappings).length
131+
);
132+
}
133+
134+
async function loadStackNameToTopicMappings() {
135+
const response = await fetch('/stackTopicMappings');
136+
try {
137+
stackNameToTopicMappings = await response.json();
138+
} catch {
139+
stackNameToTopicMappings = {};
140+
}
141+
}
142+
123143
async function connectToWebSocket() {
124144
try {
125145
const response = await fetch(`/wsUrl`);
@@ -335,6 +355,11 @@ function run() {
335355
return step;
336356
}
337357

358+
function resolveTopic(selectedStack: string | undefined) {
359+
if (!selectedStack || !stackNameToTopicMappings) return '#';
360+
return getTopic(stackNameToTopicMappings[selectedStack]);
361+
}
362+
338363
function renderSpyMessage(spyMessage: SpyMessageExt | SpyMessageGroup) {
339364
const serviceKey = serviceKeyFilterInputElement.value?.toLocaleLowerCase();
340365
const data = dataFilterInputElement.value?.toLocaleLowerCase();
@@ -346,7 +371,9 @@ function run() {
346371
messages = [spyMessage as SpyMessageExt];
347372
}
348373
const html = messages
349-
.filter((sm) => sm.topic === getTopic(selectedStack!))
374+
.filter(
375+
(sm) => !canFilterOnTopic() || sm.topic === resolveTopic(selectedStack)
376+
)
350377
.filter((sm) => matchFilter(sm, { serviceKey, data }))
351378
.map((sm, i) => {
352379
const service = getServiceNameFromServiceKey(sm.serviceKey);

0 commit comments

Comments
 (0)