Skip to content

Commit

Permalink
Merge pull request #7783 from ycombinator/chrome/remove-basepath-method
Browse files Browse the repository at this point in the history
Adding method removeBasePath
  • Loading branch information
ycombinator authored Jul 20, 2016
2 parents 19ed484 + db08f21 commit 0724220
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ui/public/chrome/api/__tests__/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ describe('chrome nav apis', function () {
});
});

describe('#removeBasePath', () => {
it ('returns the given URL as-is when no basepath is set', () => {
const basePath = '';
const { chrome } = init({ basePath });
expect(chrome.removeBasePath('/app/kibana?a=b')).to.be('/app/kibana?a=b');
});

it ('returns the given URL with the basepath stripped out when basepath is set', () => {
const { chrome } = init();
expect(chrome.removeBasePath(`${basePath}/app/kibana?a=b`)).to.be('/app/kibana?a=b');
});
});

describe('#getNavLinkById', () => {
it ('retrieves the correct nav link, given its ID', () => {
const appUrlStore = new StubBrowserStorage();
Expand Down
9 changes: 9 additions & 0 deletions src/ui/public/chrome/api/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export default function (chrome, internals) {
});
};

chrome.removeBasePath = function (url) {
if (!internals.basePath) {
return url;
}

const basePathRegExp = new RegExp(`^${internals.basePath}`);
return url.replace(basePathRegExp, '');
};

function lastSubUrlKey(link) {
return `lastSubUrl:${link.url}`;
}
Expand Down

0 comments on commit 0724220

Please sign in to comment.