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

feat: add a mechanism to hide top-level nav items #7323

Merged
merged 1 commit into from
Dec 5, 2019
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
6 changes: 6 additions & 0 deletions app/ui-react/packages/ui/src/Layout/PfVerticalNavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Link } from 'react-router-dom';
export interface IPfVerticalNavItem {
className?: string;
exact?: boolean;
hidden?: boolean;
isActive?: (match: any, location: any) => boolean;
location?: any;
strict?: boolean;
Expand All @@ -18,6 +19,7 @@ export interface IPfVerticalNavItem {
function PfVerticalNavItem({
className,
exact,
hidden,
isActive: isActiveProp,
location,
strict,
Expand All @@ -42,6 +44,10 @@ function PfVerticalNavItem({
? isActiveProp(match, childLocation)
: match);

if (hidden) {
return null;
}

return children ? (
<NavExpandable title={label} isActive={isActive} isExpanded={isActive}>
{children}
Expand Down
5 changes: 4 additions & 1 deletion app/ui-react/syndesis/config.minishift.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"enabled": 1
},
"features": {
"logging": false
"extensions": true,
"integrations": true,
"connections": true,
"data": true
}
}
5 changes: 4 additions & 1 deletion app/ui-react/syndesis/config.proxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"enabled": 1
},
"features": {
"logging": false
"extensions": true,
"integrations": true,
"connections": true,
"data": true
}
}
5 changes: 4 additions & 1 deletion app/ui-react/syndesis/config.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"enabled": 1
},
"features": {
"logging": false
"extensions": true,
"integrations": true,
"connections": true,
"data": true
}
}
44 changes: 44 additions & 0 deletions app/ui-react/syndesis/src/app/UI.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WithApiVersion, WithUserHelpers } from '@syndesis/api';
import { StringMap } from '@syndesis/models';
import {
AboutModal,
AboutModalContent,
Expand Down Expand Up @@ -40,6 +41,36 @@ export interface IAppUIState {
showAboutModal: boolean;
}

/**
* Convert a route to a feature name based on it's path, returns
* undefined if the route doesn't have a path.
* @param route
*/
function routeToFeatureName(route: IAppRoute) {
if (!route.to) {
return undefined;
}
return route.to.replace(/\//g, '').trim();
}

/**
* Compares the supplied route to the given feature map and
* returns whether or not that module should be visible to the
* user or not
* @param features
* @param route
*/
function featureEnabled(features: StringMap<any>, route: IAppRoute) {
const feature = routeToFeatureName(route);
if (typeof feature === 'undefined') {
return true;
}
return (
typeof features[feature] === 'undefined' ||
(typeof features[feature] === 'boolean' && features[feature])
);
}

export const UI: React.FunctionComponent<IAppUIProps> = ({ routes }) => {
const [showNavigation, setShowNavigation] = React.useState(true);
const onHideNavigation = () => setShowNavigation(false);
Expand Down Expand Up @@ -151,6 +182,7 @@ export const UI: React.FunctionComponent<IAppUIProps> = ({ routes }) => {
const isProductBuild = config && config.branding.productBuild;
setProductBuild(isProductBuild);
const productName = isProductBuild ? 'Fuse Online' : 'Syndesis';
const features = (config && config.features) || {} as Map<string, any>;
return (
<>
{
Expand Down Expand Up @@ -260,6 +292,12 @@ export const UI: React.FunctionComponent<IAppUIProps> = ({ routes }) => {
!(route as IAppRouteWithChildrens)
.childrens ? (
<PfVerticalNavItem
hidden={
!featureEnabled(
features,
route as IAppRoute
)
}
exact={(route as IAppRoute).exact}
label={t((route as IAppRoute).label)}
to={(route as IAppRoute).to}
Expand All @@ -277,6 +315,12 @@ export const UI: React.FunctionComponent<IAppUIProps> = ({ routes }) => {
{(route as IAppRouteWithChildrens).childrens.map(
(subRoute, subIndex) => (
<PfVerticalNavItem
hidden={
!featureEnabled(
features,
subRoute as IAppRoute
)
}
exact={subRoute.exact}
label={t(subRoute.label)}
to={subRoute.to}
Expand Down
5 changes: 2 additions & 3 deletions app/ui-react/syndesis/src/app/WithConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { StringMap } from '@syndesis/models';
import * as React from 'react';

export interface IConfigFile {
Expand All @@ -17,9 +18,7 @@ export interface IConfigFile {
dvUrl: string;
enabled: number;
};
features: {
logging: boolean;
};
features: StringMap<any>,
branding: {
logoWhiteBg: string;
logoDarkBg: string;
Expand Down