mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 18:09:57 -03:30
Hide license route based on install and add useConfig hook
This commit is contained in:
parent
c24e169bf6
commit
42158dea59
@ -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);
|
||||
|
||||
@ -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 (
|
||||
<PageSection>
|
||||
<Card>
|
||||
<ContentLoading />
|
||||
</Card>
|
||||
</PageSection>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<PageSection>
|
||||
<SplitLayout>
|
||||
{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 }) {
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</PageSection>
|
||||
</SplitLayout>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -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 }) {
|
||||
<LDAP />
|
||||
</Route>
|
||||
<Route path="/settings/license">
|
||||
<License />
|
||||
{license_info?.license_type === 'open' ? (
|
||||
<License />
|
||||
) : (
|
||||
<Redirect to="/settings" />
|
||||
)}
|
||||
</Route>
|
||||
<Route path="/settings/logging">
|
||||
<Logging />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user