Skip to content

Commit

Permalink
Only show the Service Instances menu if the broker is configured. (#1930
Browse files Browse the repository at this point in the history
)
  • Loading branch information
absoludity authored Aug 10, 2020
1 parent 35d9ee5 commit 314e834
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
20 changes: 20 additions & 0 deletions dashboard/src/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,31 @@ const defaultProps = {
getNamespace: jest.fn(),
featureFlags: { operators: false, additionalClusters: [], ui: "hex" },
appVersion: "",
isServiceCatalogInstalled: false,
};
it("renders the header links and titles", () => {
const wrapper = shallow(<Header {...defaultProps} />);
const menubar = wrapper.find(".header__nav__menu").first();
const items = menubar.children().map(p => p.props().children.props);
const expectedItems = [
{ children: "Applications", to: app.apps.list("default", "default") },
{ children: "Catalog", to: app.catalog("default", "default") },
];
expect(items.length).toEqual(expectedItems.length);
expectedItems.forEach((expectedItem, index) => {
expect(expectedItem.children).toBe(items[index].children);
expect(expectedItem.to).toBe(items[index].to);
});
});

it("includes the service instances when the broker is installed", () => {
const props = {
...defaultProps,
isServiceCatalogInstalled: true,
};
const wrapper = shallow(<Header {...props} />);
const menubar = wrapper.find(".header__nav__menu").first();
const items = menubar.children().map(p => p.props().children.props);
const expectedItems = [
{ children: "Applications", to: app.apps.list("default", "default") },
{ children: "Catalog", to: app.catalog("default", "default") },
Expand Down
14 changes: 9 additions & 5 deletions dashboard/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface IHeaderProps {
createNamespace: (cluster: string, ns: string) => Promise<boolean>;
getNamespace: (cluster: string, ns: string) => void;
featureFlags: IFeatureFlags;
isServiceCatalogInstalled: boolean;
}

interface IHeaderState {
Expand Down Expand Up @@ -59,6 +60,7 @@ class Header extends React.Component<IHeaderProps, IHeaderState> {
authenticated: showNav,
createNamespace,
getNamespace,
isServiceCatalogInstalled,
} = this.props;
const showClusterSelector = Object.keys(clusters.clusters).length > 1;
const cluster = clusters.clusters[clusters.currentCluster];
Expand Down Expand Up @@ -104,11 +106,13 @@ class Header extends React.Component<IHeaderProps, IHeaderState> {
Catalog
</HeaderLink>
</li>
<li>
<HeaderLink to={app.servicesInstances(cluster.currentNamespace)}>
Service Instances (alpha)
</HeaderLink>
</li>
{isServiceCatalogInstalled && (
<li>
<HeaderLink to={app.servicesInstances(cluster.currentNamespace)}>
Service Instances (alpha)
</HeaderLink>
</li>
)}
</ul>
</nav>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const defaultState = {
config: {
featureFlags: { operators: true, additionalClusters: [], ui: "hex" },
},
catalog: { isServiceCatalogInstalled: false },
clusters: {
currentCluster: "default",
clusters: {
Expand Down
2 changes: 2 additions & 0 deletions dashboard/src/containers/HeaderContainer/HeaderContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function mapStateToProps({
location: { pathname },
},
config: { featureFlags, appVersion },
catalog: { isServiceCatalogInstalled },
}: IStoreState) {
return {
authenticated,
Expand All @@ -23,6 +24,7 @@ function mapStateToProps({
featureFlags,
UI: featureFlags.ui,
appVersion,
isServiceCatalogInstalled,
};
}

Expand Down

0 comments on commit 314e834

Please sign in to comment.