Hide license route based on install and add useConfig hook

This commit is contained in:
Marliana Lara
2020-07-29 13:47:42 -04:00
parent c24e169bf6
commit 42158dea59
3 changed files with 32 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
import React from 'react'; import React, { useContext } from 'react';
// eslint-disable-next-line import/prefer-default-export // eslint-disable-next-line import/prefer-default-export
export const ConfigContext = React.createContext({}); export const ConfigContext = React.createContext({});
export const ConfigProvider = ConfigContext.Provider; export const ConfigProvider = ConfigContext.Provider;
export const Config = ConfigContext.Consumer; export const Config = ConfigContext.Consumer;
export const useConfig = () => useContext(ConfigContext);

View File

@@ -11,17 +11,19 @@ import {
DataListCell, DataListCell,
DataListItemCells, DataListItemCells,
DataListItemRow, DataListItemRow,
PageSection as _PageSection, PageSection,
} from '@patternfly/react-core'; } from '@patternfly/react-core';
import styled from 'styled-components'; import styled from 'styled-components';
import { BrandName } from '../../variables'; import { BrandName } from '../../variables';
import { useConfig } from '../../contexts/Config';
import ContentLoading from '../../components/ContentLoading/ContentLoading';
// Setting BrandName to a variable here is necessary to get the jest tests // Setting BrandName to a variable here is necessary to get the jest tests
// passing. Attempting to use BrandName in the template literal results // passing. Attempting to use BrandName in the template literal results
// in failing tests. // in failing tests.
const brandName = BrandName; const brandName = BrandName;
const PageSection = styled(_PageSection)` const SplitLayout = styled(PageSection)`
column-count: 1; column-count: 1;
column-gap: 24px; column-gap: 24px;
@media (min-width: 576px) { @media (min-width: 576px) {
@@ -47,11 +49,12 @@ const CardDescription = styled.div`
`; `;
function SettingList({ i18n }) { function SettingList({ i18n }) {
const config = useConfig();
const settingRoutes = [ const settingRoutes = [
{ {
header: i18n._(t`Authentication`), header: i18n._(t`Authentication`),
description: i18n._( description: i18n._(
t`Enable simplified login for your Tower applications` t`Enable simplified login for your ${brandName} applications`
), ),
id: 'authentication', id: 'authentication',
routes: [ routes: [
@@ -87,7 +90,9 @@ function SettingList({ i18n }) {
}, },
{ {
header: i18n._(t`Jobs`), header: i18n._(t`Jobs`),
description: i18n._(t`Update settings pertaining to Jobs within Tower`), description: i18n._(
t`Update settings pertaining to Jobs within ${brandName}`
),
id: 'jobs', id: 'jobs',
routes: [ routes: [
{ {
@@ -141,10 +146,20 @@ function SettingList({ i18n }) {
}, },
]; ];
if (Object.keys(config).length === 0) {
return (
<PageSection>
<Card>
<ContentLoading />
</Card>
</PageSection>
);
}
return ( return (
<PageSection> <SplitLayout>
{settingRoutes.map(({ description, header, id, routes }) => { {settingRoutes.map(({ description, header, id, routes }) => {
if (id === 'license' && brandName === 'Tower') { if (id === 'license' && config?.license_info?.license_type === 'open') {
return null; return null;
} }
return ( return (
@@ -171,7 +186,7 @@ function SettingList({ i18n }) {
</Card> </Card>
); );
})} })}
</PageSection> </SplitLayout>
); );
} }

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { Link, Route, Switch } from 'react-router-dom'; import { Link, Route, Switch, Redirect } from 'react-router-dom';
import { withI18n } from '@lingui/react'; import { withI18n } from '@lingui/react';
import { t } from '@lingui/macro'; import { t } from '@lingui/macro';
import { PageSection, Card } from '@patternfly/react-core'; import { PageSection, Card } from '@patternfly/react-core';
@@ -19,8 +19,10 @@ import SAML from './SAML';
import SettingList from './SettingList'; import SettingList from './SettingList';
import TACACS from './TACACS'; import TACACS from './TACACS';
import UI from './UI'; import UI from './UI';
import { useConfig } from '../../contexts/Config';
function Settings({ i18n }) { function Settings({ i18n }) {
const { license_info = {} } = useConfig();
const breadcrumbConfig = { const breadcrumbConfig = {
'/settings': i18n._(t`Settings`), '/settings': i18n._(t`Settings`),
'/settings/activity_stream': i18n._(t`Activity stream`), '/settings/activity_stream': i18n._(t`Activity stream`),
@@ -61,7 +63,11 @@ function Settings({ i18n }) {
<LDAP /> <LDAP />
</Route> </Route>
<Route path="/settings/license"> <Route path="/settings/license">
<License /> {license_info?.license_type === 'open' ? (
<License />
) : (
<Redirect to="/settings" />
)}
</Route> </Route>
<Route path="/settings/logging"> <Route path="/settings/logging">
<Logging /> <Logging />