From 42158dea5979e92d540cd280f2c7e17277dd0bb5 Mon Sep 17 00:00:00 2001 From: Marliana Lara Date: Wed, 29 Jul 2020 13:47:42 -0400 Subject: [PATCH] Hide license route based on install and add useConfig hook --- awx/ui_next/src/contexts/Config.jsx | 3 +- .../src/screens/Setting/SettingList.jsx | 29 ++++++++++++++----- awx/ui_next/src/screens/Setting/Settings.jsx | 10 +++++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/awx/ui_next/src/contexts/Config.jsx b/awx/ui_next/src/contexts/Config.jsx index 231e6f8301..e8674c955c 100644 --- a/awx/ui_next/src/contexts/Config.jsx +++ b/awx/ui_next/src/contexts/Config.jsx @@ -1,7 +1,8 @@ -import React from 'react'; +import React, { useContext } from 'react'; // eslint-disable-next-line import/prefer-default-export export const ConfigContext = React.createContext({}); export const ConfigProvider = ConfigContext.Provider; export const Config = ConfigContext.Consumer; +export const useConfig = () => useContext(ConfigContext); diff --git a/awx/ui_next/src/screens/Setting/SettingList.jsx b/awx/ui_next/src/screens/Setting/SettingList.jsx index 455215c68b..9f0e6ffe64 100644 --- a/awx/ui_next/src/screens/Setting/SettingList.jsx +++ b/awx/ui_next/src/screens/Setting/SettingList.jsx @@ -11,17 +11,19 @@ import { DataListCell, DataListItemCells, DataListItemRow, - PageSection as _PageSection, + PageSection, } from '@patternfly/react-core'; import styled from 'styled-components'; 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 // passing. Attempting to use BrandName in the template literal results // in failing tests. const brandName = BrandName; -const PageSection = styled(_PageSection)` +const SplitLayout = styled(PageSection)` column-count: 1; column-gap: 24px; @media (min-width: 576px) { @@ -47,11 +49,12 @@ const CardDescription = styled.div` `; function SettingList({ i18n }) { + const config = useConfig(); const settingRoutes = [ { header: i18n._(t`Authentication`), description: i18n._( - t`Enable simplified login for your Tower applications` + t`Enable simplified login for your ${brandName} applications` ), id: 'authentication', routes: [ @@ -87,7 +90,9 @@ function SettingList({ i18n }) { }, { 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', routes: [ { @@ -141,10 +146,20 @@ function SettingList({ i18n }) { }, ]; + if (Object.keys(config).length === 0) { + return ( + + + + + + ); + } + return ( - + {settingRoutes.map(({ description, header, id, routes }) => { - if (id === 'license' && brandName === 'Tower') { + if (id === 'license' && config?.license_info?.license_type === 'open') { return null; } return ( @@ -171,7 +186,7 @@ function SettingList({ i18n }) { ); })} - + ); } diff --git a/awx/ui_next/src/screens/Setting/Settings.jsx b/awx/ui_next/src/screens/Setting/Settings.jsx index ee0811d1eb..4d8d49830d 100644 --- a/awx/ui_next/src/screens/Setting/Settings.jsx +++ b/awx/ui_next/src/screens/Setting/Settings.jsx @@ -1,5 +1,5 @@ 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 { t } from '@lingui/macro'; import { PageSection, Card } from '@patternfly/react-core'; @@ -19,8 +19,10 @@ import SAML from './SAML'; import SettingList from './SettingList'; import TACACS from './TACACS'; import UI from './UI'; +import { useConfig } from '../../contexts/Config'; function Settings({ i18n }) { + const { license_info = {} } = useConfig(); const breadcrumbConfig = { '/settings': i18n._(t`Settings`), '/settings/activity_stream': i18n._(t`Activity stream`), @@ -61,7 +63,11 @@ function Settings({ i18n }) { - + {license_info?.license_type === 'open' ? ( + + ) : ( + + )}