PanelQueryRunner: use refId from results if the key value was not set in the packet (#47598)

This commit is contained in:
Ryan McKinley
2022-04-12 07:24:46 -07:00
committed by GitHub
parent 4b889eb336
commit f80a0d2a9b
2 changed files with 38 additions and 2 deletions

View File

@@ -156,7 +156,7 @@ describe('runRequest', () => {
});
});
runRequestScenario('After tree responses, 2 with different keys', (ctx) => {
runRequestScenario('After three responses, 2 with different keys', (ctx) => {
ctx.setup(() => {
ctx.start();
ctx.emitPacket({
@@ -186,6 +186,40 @@ describe('runRequest', () => {
});
});
runRequestScenario('When the key is defined in refId', (ctx) => {
ctx.setup(() => {
ctx.start();
ctx.emitPacket({
data: [{ name: 'DataX-1', refId: 'X' } as DataFrame],
});
ctx.emitPacket({
data: [{ name: 'DataY-1', refId: 'Y' } as DataFrame],
});
ctx.emitPacket({
data: [{ name: 'DataY-2', refId: 'Y' } as DataFrame],
});
});
it('should emit 3 separate results', () => {
expect(ctx.results.length).toBe(3);
});
it('should keep data for X and Y', () => {
expect(ctx.results[2].series).toMatchInlineSnapshot(`
Array [
Object {
"name": "DataX-1",
"refId": "X",
},
Object {
"name": "DataY-2",
"refId": "Y",
},
]
`);
});
});
runRequestScenario('After response with state Streaming', (ctx) => {
ctx.setup(() => {
ctx.start();

View File

@@ -43,7 +43,9 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ
...state.packets,
};
packets[packet.key || 'A'] = packet;
// updates to the same key will replace previous values
const key = packet.key ?? packet.data?.[0]?.refId ?? 'A';
packets[key] = packet;
let loadingState = packet.state || LoadingState.Done;
let error: DataQueryError | undefined = undefined;