Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALS-5654] Add dropdown to help link if more than one url is given #163

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading