Update useBrandName

Update useBrandName and its usage.

It was verified on downstrean this solution.

See:https://github.com/ansible/awx/issues/10775
This commit is contained in:
nixocio 2021-08-06 10:03:20 -04:00
parent 80053cea83
commit efcac6d55a
9 changed files with 22 additions and 29 deletions

View File

@ -1,5 +1,4 @@
{
"BRAND_NAME": "Ansible AWX",
"COMPONENT_NAME": "",
"PENDO_API_KEY": ""
}

View File

@ -5,14 +5,17 @@ import { AboutModal } from '@patternfly/react-core';
import useBrandName from 'hooks/useBrandName';
function About({ version, isOpen, onClose }) {
const {
current: { brandName, componentName },
} = useBrandName();
const brandName = useBrandName();
const createSpeechBubble = () => {
let text =
componentName !== ''
? `${brandName} ${componentName} ${version}`
: `${brandName} ${version}`;
let text = '';
if (typeof brandName === 'string' && brandName.length > 0) {
text =
brandName.indexOf('AWX') === -1
? `${brandName} Controller ${version}`
: `${brandName} ${version}`;
}
let top = '';
let bottom = '';

View File

@ -5,7 +5,7 @@ import About from './About';
jest.mock('../../hooks/useBrandName', () => ({
__esModule: true,
default: () => ({
current: { brandName: 'AWX', componentName: '' },
current: 'AWX',
}),
}));

View File

@ -22,9 +22,7 @@ const TooltipWrapper = styled.div`
`;
function AdHocDetailsStep({ verbosityOptions, moduleOptions }) {
const {
current: { brandName },
} = useBrandName();
const brandName = useBrandName();
const [moduleNameField, moduleNameMeta, moduleNameHelpers] = useField({
name: 'module_name',
validate: required(null),

View File

@ -22,7 +22,6 @@ describe('<AppContainer />', () => {
RootAPI.readAssetVariables.mockResolvedValue({
data: {
BRAND_NAME: 'AWX',
COMPONENT_NAME: '',
PENDO_API_KEY: 'some-pendo-key',
},
});
@ -100,7 +99,6 @@ describe('<AppContainer />', () => {
RootAPI.readAssetVariables.mockResolvedValue({
data: {
BRAND_NAME: 'AWX',
COMPONENT_NAME: '',
PENDO_API_KEY: '',
},
});

View File

@ -1,19 +1,18 @@
import { useEffect, useRef } from 'react';
import { useEffect, useState } from 'react';
import { RootAPI } from 'api';
export default function useBrandName() {
const platform = useRef({});
const [brandName, setBrandName] = useState('');
useEffect(() => {
async function fetchBrandName() {
const {
data: { BRAND_NAME, COMPONENT_NAME },
data: { BRAND_NAME },
} = await RootAPI.readAssetVariables();
platform.current.brandName = BRAND_NAME;
platform.current.componentName = COMPONENT_NAME || '';
setBrandName(BRAND_NAME);
}
fetchBrandName();
}, []);
return platform;
return brandName;
}

View File

@ -14,9 +14,8 @@ const ManualSubForm = ({
project_base_dir,
project_local_paths,
}) => {
const {
current: { brandName },
} = useBrandName();
const brandName = useBrandName();
const localPaths = [...new Set([...project_local_paths, localPath])];
const options = [
{

View File

@ -45,9 +45,8 @@ const CardDescription = styled.div`
function SettingList() {
const config = useConfig();
const {
current: { brandName },
} = useBrandName();
const brandName = useBrandName();
const settingRoutes = [
{
header: t`Authentication`,

View File

@ -66,9 +66,7 @@ function JobTemplateForm({
Boolean(template.webhook_service)
);
const isMounted = useIsMounted();
const {
current: { brandName },
} = useBrandName();
const brandName = useBrandName();
const [askInventoryOnLaunchField] = useField('ask_inventory_on_launch');
const [jobTypeField, jobTypeMeta, jobTypeHelpers] = useField({