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", "BRAND_NAME": "Ansible AWX",
"COMPONENT_NAME": "",
"PENDO_API_KEY": "" "PENDO_API_KEY": ""
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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