Explore: Avoid duplicate refIds when adding a new query (#67499)

This commit is contained in:
Giordano Ricci 2023-04-28 15:01:50 +01:00 committed by GitHub
parent 932136807b
commit 15363e416b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -489,4 +489,10 @@ describe('generateEmptyQuery', () => {
expect(query.datasource?.type).toBe('loki');
expect(query.refId).toBe('B');
});
it('should generate a query with a unique refId', async () => {
const query = await generateEmptyQuery([{ refId: 'A' }], 2);
expect(query.refId).not.toBe('A');
});
});

View File

@ -275,7 +275,7 @@ export async function generateEmptyQuery(
defaultQuery = datasourceInstance.getDefaultQuery?.(CoreApp.Explore);
}
return { refId: getNextRefIdChar(queries), key: generateKey(index), datasource: datasourceRef, ...defaultQuery };
return { ...defaultQuery, refId: getNextRefIdChar(queries), key: generateKey(index), datasource: datasourceRef };
}
export const generateNewKeyAndAddRefIdIfMissing = (target: DataQuery, queries: DataQuery[], index = 0): DataQuery => {