mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
Timeseries: move join field to index zero (#35217)
This commit is contained in:
parent
1dc387536e
commit
e1af571efd
@ -180,11 +180,11 @@ describe('align frames', () => {
|
||||
`);
|
||||
});
|
||||
|
||||
it('sort single frame', () => {
|
||||
it('sort single frame as index zero', () => {
|
||||
const series1 = toDataFrame({
|
||||
fields: [
|
||||
{ name: 'TheTime', type: FieldType.time, values: [6000, 2000, 1500] },
|
||||
{ name: 'A1', type: FieldType.number, values: [1, 22, 15] },
|
||||
{ name: 'TheTime', type: FieldType.time, values: [6000, 2000, 1500] },
|
||||
],
|
||||
});
|
||||
|
||||
|
@ -78,6 +78,9 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
|
||||
let frame = options.frames[0];
|
||||
let frameCopy = frame;
|
||||
|
||||
const joinFieldMatcher = getJoinMatcher(options);
|
||||
let joinIndex = frameCopy.fields.findIndex((f) => joinFieldMatcher(f, frameCopy, options.frames));
|
||||
|
||||
if (options.keepOriginIndices) {
|
||||
frameCopy = {
|
||||
...frame,
|
||||
@ -95,10 +98,16 @@ export function outerJoinDataFrames(options: JoinOptions): DataFrame | undefined
|
||||
return copy;
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const joinFieldMatcher = getJoinMatcher(options);
|
||||
const joinIndex = frameCopy.fields.findIndex((f) => joinFieldMatcher(f, frameCopy, options.frames));
|
||||
// Make sure the join field is first
|
||||
if (joinIndex > 0) {
|
||||
const joinField = frameCopy.fields[joinIndex];
|
||||
const fields = frameCopy.fields.filter((f, idx) => idx !== joinIndex);
|
||||
fields.unshift(joinField);
|
||||
frameCopy.fields = fields;
|
||||
joinIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.enforceSort) {
|
||||
if (joinIndex >= 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user