Skip to content

Commit

Permalink
Remove the checks CAN_GET_NS and prometheusBaseURL for monitoring Das…
Browse files Browse the repository at this point in the history
…hboard and Metrics tabs in devconsole
  • Loading branch information
vikram-raj committed Jun 10, 2020
1 parent fd7e2f9 commit 29740cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 101 deletions.
@@ -1,10 +1,8 @@
import * as React from 'react';
import { Helmet } from 'react-helmet';
import { match as RMatch } from 'react-router';
import { connect } from 'react-redux';
import { HorizontalNav, PageHeading, history } from '@console/internal/components/utils';
import { featureReducerName } from '@console/internal/reducers/features';
import { TechPreviewBadge, ALL_NAMESPACES_KEY, FLAGS } from '@console/shared';
import { TechPreviewBadge, ALL_NAMESPACES_KEY } from '@console/shared';
import { withStartGuide } from '@console/internal/components/start-guide';
import NamespacedPage, { NamespacedPageVariants } from '../NamespacedPage';
import ProjectListPage from '../projects/ProjectListPage';
Expand All @@ -20,47 +18,31 @@ type MonitoringPageProps = {
}>;
};

type StateProps = {
canAccess: boolean;
};

type Props = MonitoringPageProps & StateProps;

const handleNamespaceChange = (newNamespace: string): void => {
if (newNamespace === ALL_NAMESPACES_KEY) {
history.push(MONITORING_ALL_NS_PAGE_URI);
}
};

export const PageContents: React.FC<Props> = ({ match, canAccess }) => {
export const PageContents: React.FC<MonitoringPageProps> = ({ match }) => {
const activeNamespace = match.params.ns;
const canAccessPrometheus = canAccess && !!window.SERVER_FLAGS.prometheusBaseURL;

const pages = React.useMemo(
() => [
...(canAccessPrometheus
? [
{
href: '',
name: 'Dashboard',
component: ConnectedMonitoringDashboard,
},
{
href: 'metrics',
name: 'Metrics',
component: ConnectedMonitoringMetrics,
},
]
: []),
{
href: canAccessPrometheus ? 'events' : '',
name: 'Events',
component: MonitoringEvents,
},
],
[canAccessPrometheus],
);

const pages = [
{
href: '',
name: 'Dashboard',
component: ConnectedMonitoringDashboard,
},
{
href: 'metrics',
name: 'Metrics',
component: ConnectedMonitoringMetrics,
},
{
href: 'events',
name: 'Events',
component: MonitoringEvents,
},
];
return activeNamespace ? (
<>
<PageHeading badge={<TechPreviewBadge />} title="Monitoring" />
Expand All @@ -75,7 +57,7 @@ export const PageContents: React.FC<Props> = ({ match, canAccess }) => {

const PageContentsWithStartGuide = withStartGuide(PageContents);

export const MonitoringPage: React.FC<Props> = (props) => (
export const MonitoringPage: React.FC<MonitoringPageProps> = (props) => (
<>
<Helmet>
<title>Monitoring</title>
Expand All @@ -90,8 +72,4 @@ export const MonitoringPage: React.FC<Props> = (props) => (
</>
);

const stateToProps = (state) => ({
canAccess: !!state[featureReducerName].get(FLAGS.CAN_GET_NS),
});

export default connect<StateProps, {}, MonitoringPageProps>(stateToProps)(MonitoringPage);
export default MonitoringPage;
Expand Up @@ -15,7 +15,6 @@ describe('Monitoring Page ', () => {
isExact: true,
params: {},
},
canAccess: true,
};
const component = shallow(<PageContents {...monPageProps} />);
expect(component.find(ProjectListPage).exists()).toBe(true);
Expand All @@ -33,65 +32,8 @@ describe('Monitoring Page ', () => {
ns: 'test-proj',
},
},
canAccess: true,
};

window.SERVER_FLAGS.prometheusBaseURL = 'http://some-mock-url.com';

const component = shallow(<PageContents {...monPageProps} />);
expect(component.find(PageHeading).exists()).toBe(true);
expect(component.find(PageHeading).prop('title')).toBe('Monitoring');
expect(component.find(HorizontalNav).exists()).toBe(true);
const actualTabs = component
.find(HorizontalNav)
.prop('pages')
.map((page) => page.name);
expect(actualTabs).toEqual(expectedTabs);
});

it('should render only events tab of Monitoring page for selected project when user cannot access namespaces', () => {
const expectedTabs: string[] = ['Events'];
monPageProps = {
match: {
path: '/dev-monitoring/ns/:ns',
url: '/dev-monitoring/ns/test-proj',
isExact: true,
params: {
ns: 'test-proj',
},
},
canAccess: false,
};

window.SERVER_FLAGS.prometheusBaseURL = 'http://some-mock-url.com';

const component = shallow(<PageContents {...monPageProps} />);
expect(component.find(PageHeading).exists()).toBe(true);
expect(component.find(PageHeading).prop('title')).toBe('Monitoring');
expect(component.find(HorizontalNav).exists()).toBe(true);
const actualTabs = component
.find(HorizontalNav)
.prop('pages')
.map((page) => page.name);
expect(actualTabs).toEqual(expectedTabs);
});

it('should render only events tab of Monitoring page for selected project when prometheus is disabled', () => {
const expectedTabs: string[] = ['Events'];
monPageProps = {
match: {
path: '/dev-monitoring/ns/:ns',
url: '/dev-monitoring/ns/test-proj',
isExact: true,
params: {
ns: 'test-proj',
},
},
canAccess: true,
};

window.SERVER_FLAGS.prometheusBaseURL = undefined;

const component = shallow(<PageContents {...monPageProps} />);
expect(component.find(PageHeading).exists()).toBe(true);
expect(component.find(PageHeading).prop('title')).toBe('Monitoring');
Expand Down

0 comments on commit 29740cd

Please sign in to comment.