Commit 40d195e4 by Torkel Ödegaard Committed by GitHub

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
parent bcad3fbd
......@@ -447,7 +447,7 @@ export class BackendSrv implements BackendService {
url,
type,
redirected,
request: { url, ...init },
config: options,
};
return fetchResponse;
}),
......@@ -555,7 +555,7 @@ export class BackendSrv implements BackendService {
data: [],
status: this.HTTP_REQUEST_CANCELED,
statusText: 'Request was aborted',
request: { url: parseUrlFromOptions(options), ...parseInitFromOptions(options) },
config: options,
});
}
......
......@@ -345,7 +345,8 @@ describe('backendSrv', () => {
it('then it should not emit message', async () => {
const url = 'http://localhost:3000/api/some-mock';
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({
data: { test: 'hello world' },
ok: true,
......@@ -354,16 +355,7 @@ describe('backendSrv', () => {
statusText: 'Ok',
type: 'basic',
url,
request: {
url,
method: 'GET',
body: undefined,
headers: {
map: {
accept: 'application/json, text/plain, */*',
},
},
},
config: options,
});
expect(appEventsMock.emit).not.toHaveBeenCalled();
expectDataSourceRequestCallChain({ url, method: 'GET', silent: true });
......@@ -374,7 +366,8 @@ describe('backendSrv', () => {
it('then it should not emit message', async () => {
const url = 'http://localhost:3000/api/some-mock';
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 = {
data: { test: 'hello world' },
ok: true,
......@@ -383,16 +376,7 @@ describe('backendSrv', () => {
statusText: 'Ok',
type: 'basic',
url,
request: {
url,
method: 'GET',
body: undefined as any,
headers: {
map: {
accept: 'application/json, text/plain, */*',
},
},
},
config: options,
};
expect(result).toEqual(expectedResult);
......@@ -447,16 +431,7 @@ describe('backendSrv', () => {
statusText: 'Ok',
type: 'basic',
url: '/api/dashboard/',
request: {
url: '/api/dashboard/',
method: 'GET',
body: undefined,
headers: {
map: {
accept: 'application/json, text/plain, */*',
},
},
},
config: options,
});
const result = await slowRequest;
......@@ -464,16 +439,7 @@ describe('backendSrv', () => {
data: [],
status: -1,
statusText: 'Request was aborted',
request: {
url: '/api/dashboard/',
method: 'GET',
body: undefined,
headers: {
map: {
accept: 'application/json, text/plain, */*',
},
},
},
config: options,
});
expect(unsubscribe).toHaveBeenCalledTimes(1);
});
......
......@@ -96,7 +96,10 @@ export class QueryInspector extends PureComponent<Props, State> {
delete response.headers;
}
if (response.request) {
if (response.config) {
response.request = response.config;
delete response.config;
delete response.request.transformRequest;
delete response.request.transformResponse;
delete response.request.paramSerializer;
......@@ -111,6 +114,7 @@ export class QueryInspector extends PureComponent<Props, State> {
if (response.data) {
response.response = response.data;
delete response.config;
delete response.data;
delete response.status;
delete response.statusText;
......@@ -120,6 +124,7 @@ export class QueryInspector extends PureComponent<Props, State> {
delete response.type;
delete response.$$config;
}
this.setState(prevState => ({
...prevState,
dsQuery: {
......
......@@ -51,7 +51,7 @@ export interface DataSourceResponse<T> {
readonly redirected: boolean;
readonly type: ResponseType;
readonly url: string;
readonly request: any;
readonly config: 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