Bug 1725329 - Fixed Compare View Permalink functionality (#7241)

* Bug 1725329 -Fixed Compare View Permalink functionality

* Bug 1725329 - added permaLink constant + check condition before changin urls

* Bug 1725329 - removed unnecessary spaces

* Bug 1725329 - Address review changes

* Bug 1725329 - Address review changes

* Bug 1725329 - added more info regarding permalink exceptions
This commit is contained in:
Sorin Toma 2021-08-31 11:44:57 +03:00 коммит произвёл GitHub
Родитель 40b3bf14b3
Коммит 17c8601532
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 38 добавлений и 5 удалений

Просмотреть файл

@ -382,4 +382,22 @@ describe('Test for backwards-compatible routes for other apps', () => {
}),
);
});
test('url is not broken when it contains a table permalink hash', async () => {
fetchMock.get(getApiUrl('/user/'), []);
history.push(
'/perfherder/compare?originalProject=mozilla-central&originalRevision=54e7fb66ad44b8dcb8caab587f929dad60932d71&newProject=mozilla-central&newRevision=54e7fb66ad44b8dcb8caab587f929dad60932d71&framework=1&page=1#tableLink-header-134266337',
);
render(testApp());
expect(history.location).toEqual(
expect.objectContaining({
pathname: '/perfherder/compare',
search:
'?originalProject=mozilla-central&originalRevision=54e7fb66ad44b8dcb8caab587f929dad60932d71&newProject=mozilla-central&newRevision=54e7fb66ad44b8dcb8caab587f929dad60932d71&framework=1&page=1',
hash: '#tableLink-header-134266337',
}),
);
});
});

Просмотреть файл

@ -16,6 +16,7 @@ import ComparePageTitle from '../../../../ui/shared/ComparePageTitle';
import {
compareTableText,
filterText,
permaLinkPrefix,
} from '../../../../ui/perfherder/perf-helpers/constants';
import JobModel from '../../../../ui/models/job';
import TableColumnHeader from '../../../../ui/perfherder/shared/TableColumnHeader';
@ -132,8 +133,8 @@ jest.mock('../../../../ui/models/job');
const mockHandlePermalinkClick = jest.fn();
const mockUpdateParams = jest.fn();
const regexComptableHeaderId = /table-header-\d+/;
const regexComptableRowId = /table-row-\d+/;
const regexComptableHeaderId = new RegExp(`${permaLinkPrefix}-header-\\d+`);
const regexComptableRowId = new RegExp(`${permaLinkPrefix}-row-\\d+`);
beforeEach(() => {
JobModel.retrigger.mockClear();
@ -392,7 +393,8 @@ test('table header & rows all have hash-based ids', async () => {
// each hash suffix is unique
const tableSections = [compareTable, ...compareTableRows];
const allHashSuffixes = tableSections.map(
(section) => /table-\w+-(\d+)/g.exec(section.id)[1],
(section) =>
new RegExp(`${permaLinkPrefix}-\\w+-(\\d+)`).exec(section.id)[1],
);
const uniqueHashSuffixes = [...new Set(allHashSuffixes)];

Просмотреть файл

@ -5,6 +5,7 @@ import { Helmet } from 'react-helmet';
import { ConnectedRouter } from 'connected-react-router';
import { Provider } from 'react-redux';
import { permaLinkPrefix } from './perfherder/perf-helpers/constants';
import { configureStore, history } from './job-view/redux/configureStore';
import LoadingSpinner from './shared/LoadingSpinner';
import LoginCallback from './login-callback/LoginCallback';
@ -66,6 +67,15 @@ const updateOldUrls = () => {
history.push(updates);
};
// the urls need to be update for compatibility reasons, but we need to have exceptions from this
// the link created by the permalink functionality is broken by the updateOldUrls function
// for more information - https://bugzilla.mozilla.org/show_bug.cgi?id=1725329
const updateUrls = () => {
if (!history.location.hash.includes(permaLinkPrefix)) {
updateOldUrls();
}
};
const faviconPaths = {
'/jobs': { title: 'Treeherder Jobs View', favicon: treeFavicon },
'/logviewer': {
@ -100,7 +110,7 @@ const withFavicon = (element, route) => {
};
const App = () => {
updateOldUrls();
updateUrls();
return (
<Provider store={configureStore()}>
<ConnectedRouter history={history}>

Просмотреть файл

@ -134,4 +134,6 @@ export const scrollTypes = {
next: 'next',
};
export const permaLinkPrefix = 'tableLink';
export const maximumVisibleAlertSummaryRows = 26;

Просмотреть файл

@ -22,6 +22,7 @@ import {
phFrameworksWithRelatedBranches,
phTimeRanges,
unknownFrameworkMessage,
permaLinkPrefix,
} from './constants';
export const formatNumber = (input) =>
@ -694,7 +695,7 @@ export const getHashBasedId = function getHashBasedId(
const tableSection = platformName === null ? 'header' : 'row';
const hashValue = hashFunction(getSignatureName(testName, platformName));
return `table-${tableSection}-${hashValue}`;
return `${permaLinkPrefix}-${tableSection}-${hashValue}`;
};
const retriggerByRevision = async (