mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelQueryRunner: use refId from results if the key value was not set in the packet (#47598)
This commit is contained in:
@@ -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.setup(() => {
|
||||||
ctx.start();
|
ctx.start();
|
||||||
ctx.emitPacket({
|
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) => {
|
runRequestScenario('After response with state Streaming', (ctx) => {
|
||||||
ctx.setup(() => {
|
ctx.setup(() => {
|
||||||
ctx.start();
|
ctx.start();
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ export function processResponsePacket(packet: DataQueryResponse, state: RunningQ
|
|||||||
...state.packets,
|
...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 loadingState = packet.state || LoadingState.Done;
|
||||||
let error: DataQueryError | undefined = undefined;
|
let error: DataQueryError | undefined = undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user