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

Add support for configurable navbar title links. #1704

Merged
merged 2 commits into from Feb 7, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -111,6 +111,10 @@ public static RootUrlMode parse(String value) {
@JsonProperty
private Map<String, Map<String, List<UIQuickLinkConfiguration>>> quickLinks = Collections.emptyMap();

// e.g. {"QA": "https://singularity-qa.my-paas.net", "Production": "https://singularity-prod.my-paas.net"}
@JsonProperty
private Map<String, String> navTitleLinks = Collections.emptyMap();

public boolean isHideNewDeployButton() {
return hideNewDeployButton;
}
Expand Down Expand Up @@ -294,4 +298,12 @@ public Map<String, Map<String, List<UIQuickLinkConfiguration>>> getQuickLinks()
public void setQuickLinks(Map<String, Map<String, List<UIQuickLinkConfiguration>>> quickLinks) {
this.quickLinks = quickLinks;
}

public Map<String, String> getNavTitleLinks() {
return navTitleLinks;
}

public void setNavTitleLinks(Map<String, String> navTitleLinks) {
this.navTitleLinks = navTitleLinks;
}
}
Expand Up @@ -66,6 +66,7 @@ public class IndexView extends View {
private final String authCookieName;
private final String authTokenKey;
private final String quickLinks;
private final String navTitleLinks;

public IndexView(String singularityUriBase, String appRoot, IndexViewConfiguration configuration, ObjectMapper mapper) {
super("index.mustache");
Expand Down Expand Up @@ -139,6 +140,12 @@ public IndexView(String singularityUriBase, String appRoot, IndexViewConfigurati
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}

try {
this.navTitleLinks = ow.writeValueAsString(uiConfiguration.getNavTitleLinks());
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
}

public String getAppRoot() {
Expand Down Expand Up @@ -281,6 +288,10 @@ public String getQuickLinks() {
return quickLinks;
}

public String getNavTitleLinks() {
return navTitleLinks;
}

@Override
public String toString() {
return "IndexView{" +
Expand Down Expand Up @@ -319,6 +330,7 @@ public String toString() {
", authCookieName='" + authCookieName + '\'' +
", authTokenKey='" + authTokenKey + '\'' +
", quickLinks='" + quickLinks + '\'' +
", navTitleLinks='" + navTitleLinks + '\'' +
"} " + super.toString();
}
}
3 changes: 2 additions & 1 deletion SingularityUI/app/assets/index.mustache
Expand Up @@ -52,7 +52,8 @@
generateAuthHeader: {{{generateAuthHeader}}},
authCookieName: "{{{ authCookieName }}}",
authTokenKey: "{{{ authTokenKey }}}",
quickLinks: {{{quickLinks}}}
quickLinks: {{{quickLinks}}},
navTitleLinks: {{{navTitleLinks}}}
};
</script>
<script src="{{{staticRoot}}}/js/vendor.bundle.js"></script>
Expand Down
24 changes: 22 additions & 2 deletions SingularityUI/app/components/common/Navigation.jsx
Expand Up @@ -35,6 +35,26 @@ function isActive(navbarPath, fragment) {
// put into page wrapper, render children
const Navigation = (props) => {
const fragment = props.location.pathname.split('/')[1];
const navTitle = config.navTitleLinks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed a null check for the config field itself somewhere, otherwise it would break if it wasn't set.

? (
<ul className="nav navbar-nav">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping this in the same ul structure will give the consistent menu look you seek.

<li className="dropdown nav">
<a href="#" className="dropdown-toggle navbar-brand" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
{config.title} <span className="caret" />
</a>
<ul className="dropdown-menu">
{Object.keys(config.navTitleLinks).map((linkTitle, index) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These links can be inlined

<li key={index}>
<a href={config.navTitleLinks[linkTitle]}>{linkTitle}</a>
</li>
)}
</ul>
</li>
</ul>
) : (
<Link className="navbar-brand" to="/">{config.title}</Link>
);

return (
<nav className="navbar navbar-default">
<div className="container-fluid">
Expand All @@ -45,7 +65,7 @@ const Navigation = (props) => {
<span className="icon-bar"></span>
<span className="icon-bar"></span>
</button>
<Link className="navbar-brand" to="/">{config.title}</Link>
{navTitle}
</div>
<div className="collapse navbar-collapse" id="navbar-collapse">
<ul className="nav navbar-nav">
Expand All @@ -63,7 +83,7 @@ const Navigation = (props) => {
</li>
<li className={classnames('dropdown', {active: isActive('admin', fragment)})}>
<a href="#" className="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Admin <span className="caret"></span>
Admin <span className="caret" />
</a>
<ul className="dropdown-menu">
<li><Link to="/racks">Racks</Link></li>
Expand Down
3 changes: 2 additions & 1 deletion SingularityUI/gulpfile.js
Expand Up @@ -49,7 +49,8 @@ var templateData = {
generateAuthHeader: process.env.SINGULARITY_GENERATE_AUTH_HEADER || 'false',
authTokenKey: process.env.SINGULARITY_AUTH_TOKEN_KEY || 'token',
authCookieName: process.env.SINGULARITY_AUTH_COOKIE_NAME || '',
quickLinks: process.env.SINGULARITY_QUICK_LINKS || '{}'
quickLinks: process.env.SINGULARITY_QUICK_LINKS || '{}',
navTitleLinks: process.env.SINGULARITY_NAV_TITLE_LINKS || '{}'
};

var dest = path.resolve(__dirname, 'dist');
Expand Down