Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2022-06-05 18:08:59 +00:00
parent 118f3e3bdb
commit 36d0a94b85
9 changed files with 41 additions and 16 deletions

View File

@ -166,6 +166,7 @@ export default (resolvers = {}, config = {}) => {
PerformanceBarService.interceptor({
config: {
url: httpResponse.url,
operationName: operation.operationName,
},
headers: {
'x-request-id': httpResponse.headers.get('x-request-id'),

View File

@ -121,7 +121,7 @@ export default {
return window.URL.createObjectURL(blob);
},
downloadName() {
const fileName = this.requests[0].truncatedUrl;
const fileName = this.requests[0].displayName;
return `${fileName}_perf_bar_${Date.now()}.json`;
},
memoryReportPath() {

View File

@ -31,7 +31,7 @@ export default {
:value="request.id"
data-qa-selector="request_dropdown_option"
>
{{ request.truncatedUrl }}
{{ request.displayName }}
</option>
</select>
</div>

View File

@ -56,12 +56,12 @@ const initPerformanceBar = (el) => {
this.addRequest(urlOrRequestId, urlOrRequestId);
}
},
addRequest(requestId, requestUrl) {
addRequest(requestId, requestUrl, operationName) {
if (!this.store.canTrackRequest(requestUrl)) {
return;
}
this.store.addRequest(requestId, requestUrl);
this.store.addRequest(requestId, requestUrl, operationName);
},
loadRequestDetails(requestId) {
const request = this.store.findRequest(requestId);

View File

@ -10,13 +10,15 @@ export default class PerformanceBarService {
static registerInterceptor(peekUrl, callback) {
PerformanceBarService.interceptor = (response) => {
const [fireCallback, requestId, requestUrl] = PerformanceBarService.callbackParams(
response,
peekUrl,
);
const [
fireCallback,
requestId,
requestUrl,
operationName,
] = PerformanceBarService.callbackParams(response, peekUrl);
if (fireCallback) {
callback(requestId, requestUrl);
callback(requestId, requestUrl, operationName);
}
return response;
@ -36,7 +38,8 @@ export default class PerformanceBarService {
const cachedResponse =
response.headers && parseBoolean(response.headers['x-gitlab-from-cache']);
const fireCallback = requestUrl !== peekUrl && Boolean(requestId) && !cachedResponse;
const operationName = response.config?.operationName;
return [fireCallback, requestId, requestUrl];
return [fireCallback, requestId, requestUrl, operationName];
}
}

View File

@ -3,15 +3,19 @@ export default class PerformanceBarStore {
this.requests = [];
}
addRequest(requestId, requestUrl) {
addRequest(requestId, requestUrl, operationName) {
if (!this.findRequest(requestId)) {
const shortUrl = PerformanceBarStore.truncateUrl(requestUrl);
let displayName = PerformanceBarStore.truncateUrl(requestUrl);
if (operationName) {
displayName += ` (${operationName})`;
}
this.requests.push({
id: requestId,
url: requestUrl,
truncatedUrl: shortUrl,
details: {},
displayName,
});
}

View File

@ -69,7 +69,7 @@ describe('performance bar wrapper', () => {
it('adds the request immediately', () => {
vm.addRequest('123', 'https://gitlab.com/');
expect(vm.store.addRequest).toHaveBeenCalledWith('123', 'https://gitlab.com/');
expect(vm.store.addRequest).toHaveBeenCalledWith('123', 'https://gitlab.com/', undefined);
});
});

View File

@ -63,5 +63,17 @@ describe('PerformanceBarService', () => {
);
});
});
describe('operationName', () => {
function requestUrl(response, peekUrl) {
return PerformanceBarService.callbackParams(response, peekUrl)[3];
}
it('gets the operation name from response.config', () => {
expect(
requestUrl({ headers: {}, config: { operationName: 'someOperation' } }, '/peek'),
).toBe('someOperation');
});
});
});
});

View File

@ -1,9 +1,9 @@
import PerformanceBarStore from '~/performance_bar/stores/performance_bar_store';
describe('PerformanceBarStore', () => {
describe('truncateUrl', () => {
describe('displayName', () => {
let store;
const findUrl = (id) => store.findRequest(id).truncatedUrl;
const findUrl = (id) => store.findRequest(id).displayName;
beforeEach(() => {
store = new PerformanceBarStore();
@ -41,6 +41,11 @@ describe('PerformanceBarStore', () => {
store.addRequest('id', 'http://localhost:3001/h5bp/html5-boilerplate/#frag/ment');
expect(findUrl('id')).toEqual('html5-boilerplate');
});
it('appends the GraphQL operation name', () => {
store.addRequest('id', 'http://localhost:3001/api/graphql', 'someOperation');
expect(findUrl('id')).toBe('graphql (someOperation)');
});
});
describe('setRequestDetailsData', () => {