Commit ba26ac34 by Torkel Ödegaard

BackendSrv: Adds config to response to fix external plugins that use this (#23032)

* BackendSrv: Added config to response

* QueryInspector: Removing config from showing up

* Replace config with request and make it be the unmodified params sent in

(cherry picked from commit 40d195e4)
parent 27a8112e
...@@ -447,7 +447,7 @@ export class BackendSrv implements BackendService { ...@@ -447,7 +447,7 @@ export class BackendSrv implements BackendService {
url, url,
type, type,
redirected, redirected,
request: { url, ...init }, config: options,
}; };
return fetchResponse; return fetchResponse;
}), }),
...@@ -555,7 +555,7 @@ export class BackendSrv implements BackendService { ...@@ -555,7 +555,7 @@ export class BackendSrv implements BackendService {
data: [], data: [],
status: this.HTTP_REQUEST_CANCELED, status: this.HTTP_REQUEST_CANCELED,
statusText: 'Request was aborted', statusText: 'Request was aborted',
request: { url: parseUrlFromOptions(options), ...parseInitFromOptions(options) }, config: options,
}); });
} }
......
...@@ -345,7 +345,8 @@ describe('backendSrv', () => { ...@@ -345,7 +345,8 @@ describe('backendSrv', () => {
it('then it should not emit message', async () => { it('then it should not emit message', async () => {
const url = 'http://localhost:3000/api/some-mock'; const url = 'http://localhost:3000/api/some-mock';
const { backendSrv, appEventsMock, expectDataSourceRequestCallChain } = getTestContext({ url }); const { backendSrv, appEventsMock, expectDataSourceRequestCallChain } = getTestContext({ url });
const result = await backendSrv.datasourceRequest({ url, method: 'GET', silent: true }); const options = { url, method: 'GET', silent: true };
const result = await backendSrv.datasourceRequest(options);
expect(result).toEqual({ expect(result).toEqual({
data: { test: 'hello world' }, data: { test: 'hello world' },
ok: true, ok: true,
...@@ -354,16 +355,7 @@ describe('backendSrv', () => { ...@@ -354,16 +355,7 @@ describe('backendSrv', () => {
statusText: 'Ok', statusText: 'Ok',
type: 'basic', type: 'basic',
url, url,
request: { config: options,
url,
method: 'GET',
body: undefined,
headers: {
map: {
accept: 'application/json, text/plain, */*',
},
},
},
}); });
expect(appEventsMock.emit).not.toHaveBeenCalled(); expect(appEventsMock.emit).not.toHaveBeenCalled();
expectDataSourceRequestCallChain({ url, method: 'GET', silent: true }); expectDataSourceRequestCallChain({ url, method: 'GET', silent: true });
...@@ -374,7 +366,8 @@ describe('backendSrv', () => { ...@@ -374,7 +366,8 @@ describe('backendSrv', () => {
it('then it should not emit message', async () => { it('then it should not emit message', async () => {
const url = 'http://localhost:3000/api/some-mock'; const url = 'http://localhost:3000/api/some-mock';
const { backendSrv, appEventsMock, expectDataSourceRequestCallChain } = getTestContext({ url }); const { backendSrv, appEventsMock, expectDataSourceRequestCallChain } = getTestContext({ url });
const result = await backendSrv.datasourceRequest({ url, method: 'GET' }); const options = { url, method: 'GET' };
const result = await backendSrv.datasourceRequest(options);
const expectedResult = { const expectedResult = {
data: { test: 'hello world' }, data: { test: 'hello world' },
ok: true, ok: true,
...@@ -383,16 +376,7 @@ describe('backendSrv', () => { ...@@ -383,16 +376,7 @@ describe('backendSrv', () => {
statusText: 'Ok', statusText: 'Ok',
type: 'basic', type: 'basic',
url, url,
request: { config: options,
url,
method: 'GET',
body: undefined as any,
headers: {
map: {
accept: 'application/json, text/plain, */*',
},
},
},
}; };
expect(result).toEqual(expectedResult); expect(result).toEqual(expectedResult);
...@@ -447,16 +431,7 @@ describe('backendSrv', () => { ...@@ -447,16 +431,7 @@ describe('backendSrv', () => {
statusText: 'Ok', statusText: 'Ok',
type: 'basic', type: 'basic',
url: '/api/dashboard/', url: '/api/dashboard/',
request: { config: options,
url: '/api/dashboard/',
method: 'GET',
body: undefined,
headers: {
map: {
accept: 'application/json, text/plain, */*',
},
},
},
}); });
const result = await slowRequest; const result = await slowRequest;
...@@ -464,16 +439,7 @@ describe('backendSrv', () => { ...@@ -464,16 +439,7 @@ describe('backendSrv', () => {
data: [], data: [],
status: -1, status: -1,
statusText: 'Request was aborted', statusText: 'Request was aborted',
request: { config: options,
url: '/api/dashboard/',
method: 'GET',
body: undefined,
headers: {
map: {
accept: 'application/json, text/plain, */*',
},
},
},
}); });
expect(unsubscribe).toHaveBeenCalledTimes(1); expect(unsubscribe).toHaveBeenCalledTimes(1);
}); });
......
...@@ -96,7 +96,10 @@ export class QueryInspector extends PureComponent<Props, State> { ...@@ -96,7 +96,10 @@ export class QueryInspector extends PureComponent<Props, State> {
delete response.headers; delete response.headers;
} }
if (response.request) { if (response.config) {
response.request = response.config;
delete response.config;
delete response.request.transformRequest; delete response.request.transformRequest;
delete response.request.transformResponse; delete response.request.transformResponse;
delete response.request.paramSerializer; delete response.request.paramSerializer;
...@@ -111,6 +114,7 @@ export class QueryInspector extends PureComponent<Props, State> { ...@@ -111,6 +114,7 @@ export class QueryInspector extends PureComponent<Props, State> {
if (response.data) { if (response.data) {
response.response = response.data; response.response = response.data;
delete response.config;
delete response.data; delete response.data;
delete response.status; delete response.status;
delete response.statusText; delete response.statusText;
...@@ -120,6 +124,7 @@ export class QueryInspector extends PureComponent<Props, State> { ...@@ -120,6 +124,7 @@ export class QueryInspector extends PureComponent<Props, State> {
delete response.type; delete response.type;
delete response.$$config; delete response.$$config;
} }
this.setState(prevState => ({ this.setState(prevState => ({
...prevState, ...prevState,
dsQuery: { dsQuery: {
......
...@@ -51,7 +51,7 @@ export interface DataSourceResponse<T> { ...@@ -51,7 +51,7 @@ export interface DataSourceResponse<T> {
readonly redirected: boolean; readonly redirected: boolean;
readonly type: ResponseType; readonly type: ResponseType;
readonly url: string; readonly url: string;
readonly request: any; readonly config: any;
} }
type DataSourceResponsePayload = DataSourceResponse<any>; type DataSourceResponsePayload = DataSourceResponse<any>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment