mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Public Dashboards: Dont make annotations request when access token is falsey (#60202)
dont make annotations request when access token is falsey
This commit is contained in:
parent
46e86300cb
commit
d2f9d7f39b
@ -45,6 +45,34 @@ describe('PublicDashboardDatasource', () => {
|
||||
expect(annotation?.queryType).toEqual(GrafanaQueryType.Annotations);
|
||||
});
|
||||
|
||||
test('will not fetch annotations when access token is falsey', async () => {
|
||||
mockDatasourceRequest.mockReset();
|
||||
mockDatasourceRequest.mockReturnValue(Promise.resolve([]));
|
||||
|
||||
const ds = new PublicDashboardDataSource('public');
|
||||
const panelId = 1;
|
||||
const publicDashboardAccessToken = undefined;
|
||||
|
||||
await ds.query({
|
||||
maxDataPoints: 10,
|
||||
intervalMs: 5000,
|
||||
targets: [
|
||||
{
|
||||
refId: 'A',
|
||||
datasource: { uid: GRAFANA_DATASOURCE_NAME, type: 'sample' },
|
||||
queryType: GrafanaQueryType.Annotations,
|
||||
},
|
||||
],
|
||||
panelId,
|
||||
publicDashboardAccessToken,
|
||||
range: { from: new Date().toLocaleString(), to: new Date().toLocaleString() } as unknown as TimeRange,
|
||||
} as DataQueryRequest);
|
||||
|
||||
const mock = mockDatasourceRequest.mock;
|
||||
|
||||
expect(mock.calls.length).toBe(0);
|
||||
});
|
||||
|
||||
test('fetches results from the pubdash annotations endpoint when it is an annotation query', async () => {
|
||||
mockDatasourceRequest.mockReset();
|
||||
mockDatasourceRequest.mockReturnValue(Promise.resolve([]));
|
||||
|
@ -130,7 +130,10 @@ export class PublicDashboardDataSource extends DataSourceApi<DataQuery, DataSour
|
||||
from: from.valueOf(),
|
||||
to: to.valueOf(),
|
||||
};
|
||||
const annotations = await getBackendSrv().get(`/api/public/dashboards/${accessToken}/annotations`, params);
|
||||
|
||||
const annotations = accessToken
|
||||
? await getBackendSrv().get(`/api/public/dashboards/${accessToken}/annotations`, params)
|
||||
: [];
|
||||
|
||||
return { data: [toDataFrame(annotations)] };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user