Geo: Replication Details links use the secondary site host
Problem
The links to the left of the progress bars, such as Project Repositories
always take you to the secondary site (if its external URL is different than the primary site's external URL). E.g. https://<secondary site host>/admin/geo/sites/2/project_repositories
.
But it should always link to the same host that you are currently visiting. E.g. if you are viewing Admin > Geo > Sites on the primary site, then https://<primary site host>/admin/geo/sites/2/project_repositories
.
Since the page is supposed to work from either host, we should consider that you are probably already browsing the site of your preference. Perhaps you are closer to the primary site.
Proposal
Replace the custom routing logic in geo_site_replication_deatils.vue
Implementation Guide
- Remove ternary
?
logic fromgeo_site_replication_details.vue#L74-78
- Replace step 1 removed code with standard frontend path building strategy using
joinPaths
and accounting forgon.relative_url_root
getReplicationView(replicable) {
if (replicable.noReplicationView) {
return null;
}
return joinPaths(gon.relative_url_root || '/', `/admin/geo/sites/${this.site.id}/replication/${replicable.namePlural}`)
},
- Remove references to
customReplicationUrl
from themock_data.js
used in specs - Update expectation mocks used in
geo_site_replication_details_spec.js
to have newreplicationView
string
Now that the logic is simpler we can build the URL in the same fashion as in the component. We will need to do this for all 4 of the mocked objects
const mockExpectedNoValues = {
dataTypeTitle: MOCK_SORTED_REPLICABLE_TYPES[1].dataTypeTitle,
component: MOCK_SORTED_REPLICABLE_TYPES[1].titlePlural,
replicationView: `/admin/geo/sites/${MOCK_SECONDARY_SITE.id}/replication/${MOCK_SORTED_REPLICABLE_TYPES[1].namePlural}`,
syncValues: null,
verificationValues: null,
};
-
Delete no longer needed tests related to
customReplicationUrl
-
Add new test block that tests the specifics of the
joinPaths
andgon.releative_url_root
introduced in step 1. This can be done by mocking the relative_url_root in one spec and not the other and asserting the expected output
describe.each`
description | relativeUrl | expectedUrl
${'with relativeUrl'} | ${'/gitlab'} | ${`/gitlab/admin/geo/sites/${MOCK_SECONDARY_SITE.id}/replication/${MOCK_SORTED_REPLICABLE_TYPES[1].namePlural}`}
${'without relativeUrl'} | ${''} | ${`/admin/geo/sites/${MOCK_SECONDARY_SITE.id}/replication/${MOCK_SORTED_REPLICABLE_TYPES[1].namePlural}`}
`('component links $description', ({ relativeUrl, expectedUrl }) => {
beforeEach(() => {
gon.relative_url_root = relativeUrl
createComponent(null, { sortedReplicableTypes: () => [MOCK_SORTED_REPLICABLE_TYPES[1]] });
});
it(`renders GlLink to secondary replication view`, () => {
expect(findReplicableComponentLink().exists()).toBe(true);
expect(findReplicableComponentLink().attributes('href')).toBe(expectedUrl);
});
});