forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Serverless] Sidenav API cleanup (elastic#174544)
- Loading branch information
Showing
77 changed files
with
2,960 additions
and
5,346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/core/chrome/core-chrome-browser-internal/src/project_navigation/cloud_links.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { i18n } from '@kbn/i18n'; | ||
import type { CloudLinks, CloudLink, CloudURLs } from '@kbn/core-chrome-browser'; | ||
|
||
const stripTrailingForwardSlash = (str: string) => { | ||
return str[str.length - 1] === '/' ? str.substring(0, str.length - 1) : str; | ||
}; | ||
|
||
const parseCloudURLs = (cloudLinks: CloudLinks): CloudLinks => { | ||
const { userAndRoles, billingAndSub, deployment, performance } = cloudLinks; | ||
|
||
// We remove potential trailing forward slash ("/") at the end of the URL | ||
// because it breaks future navigation in Cloud console once we navigate there. | ||
const parseLink = (link?: CloudLink): CloudLink | undefined => { | ||
if (!link) return undefined; | ||
return { ...link, href: stripTrailingForwardSlash(link.href) }; | ||
}; | ||
|
||
return { | ||
...cloudLinks, | ||
userAndRoles: parseLink(userAndRoles), | ||
billingAndSub: parseLink(billingAndSub), | ||
deployment: parseLink(deployment), | ||
performance: parseLink(performance), | ||
}; | ||
}; | ||
|
||
export const getCloudLinks = (cloud: CloudURLs): CloudLinks => { | ||
const { billingUrl, deploymentUrl, performanceUrl, usersAndRolesUrl } = cloud; | ||
|
||
const links: CloudLinks = {}; | ||
|
||
if (usersAndRolesUrl) { | ||
links.userAndRoles = { | ||
title: i18n.translate('core.ui.chrome.sideNavigation.cloudLinks.usersAndRolesLinkText', { | ||
defaultMessage: 'Users and roles', | ||
}), | ||
href: usersAndRolesUrl, | ||
}; | ||
} | ||
|
||
if (performanceUrl) { | ||
links.performance = { | ||
title: i18n.translate('core.ui.chrome.sideNavigation.cloudLinks.performanceLinkText', { | ||
defaultMessage: 'Performance', | ||
}), | ||
href: performanceUrl, | ||
}; | ||
} | ||
|
||
if (billingUrl) { | ||
links.billingAndSub = { | ||
title: i18n.translate('core.ui.chrome.sideNavigation.cloudLinks.billingLinkText', { | ||
defaultMessage: 'Billing and subscription', | ||
}), | ||
href: billingUrl, | ||
}; | ||
} | ||
|
||
if (deploymentUrl) { | ||
links.deployment = { | ||
title: i18n.translate('core.ui.chrome.sideNavigation.cloudLinks.deploymentLinkText', { | ||
defaultMessage: 'Project', | ||
}), | ||
href: deploymentUrl, | ||
}; | ||
} | ||
|
||
return parseCloudURLs(links); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.