Skip to content

Commit

Permalink
[ALS-5654] Add dropdown to help link if more than one url is given (#163
Browse files Browse the repository at this point in the history
)
  • Loading branch information
srpiatt authored Jan 24, 2024
1 parent 64741dc commit cdad231
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
36 changes: 32 additions & 4 deletions addons/addon-custom/packages/main/src/parts/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Switch, Redirect, withRouter } from 'react-router-dom';
import { action, decorate, computed } from 'mobx';
import { inject, observer } from 'mobx-react';
import { getEnv } from 'mobx-state-tree';
import { Menu } from 'semantic-ui-react';
import { Menu, Dropdown, DropdownMenu, DropdownItem } from 'semantic-ui-react';

import { getRoutes, getMenuItems, getDefaultRouteLocation } from '@aws-ee/base-ui/dist/helpers/plugins-util';
import MainLayout from '@aws-ee/base-ui/dist/parts/MainLayout';
Expand Down Expand Up @@ -73,14 +73,42 @@ class RegisterApp extends React.Component {
}
}

openHelp() {
window.open(branding.page.help, '_blank');
openHelp(url) {
return () => window.open(url, '_blank');
}

getLinks() {
const helpLinks = (branding.page.help || '').split(',').filter(x => x);
if (helpLinks.length < 2) {
return helpLinks;
}
return helpLinks.reduce((items, link) => {
const [text, ...urlParts] = link.split('=');
const url = urlParts.join('='); // if there are query params then we need to rebuild the url
if (!text || !url) {
console.error(`Poorly formed help link was provided: "${link}"`, 'Expected: "Text=URL"');
return items;
}
return [...items, { text, url }];
}, []);
}

appMenuItems() {
const links = this.getLinks();
return (
<>
{branding.page.help && <Menu.Item onClick={this.openHelp}>Help</Menu.Item>}
{links.length === 1 && <Menu.Item onClick={this.openHelp(links[0])}>Help</Menu.Item>}
{links.length > 1 && (
<Dropdown item text="Help">
<DropdownMenu>
{links.map(({ text, url }) => (
<DropdownItem key={text} onClick={this.openHelp(url)}>
{text}
</DropdownItem>
))}
</DropdownMenu>
</Dropdown>
)}
<TermsModal // Clickable Terms menu item
trigger={<Menu.Item>Terms of Service</Menu.Item>}
closeOnDimmerClick
Expand Down
2 changes: 1 addition & 1 deletion main/config/settings/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,5 @@ HostedZoneId: 'Z02455261RJ9QQPVHFZGA'
# Should the TOS link be enabled on the landing page.
#tosLinkOnLanding: true

# URL for help link
# URL for help link. Can be empty, a single url, or a list like, "Some Link=https://www.google.com/?q=what,Other Link=https://www.example.com/"
#helpUrl: about:blank

0 comments on commit cdad231

Please sign in to comment.