From 546254c1a244acdcc0fd8d755927d7f3ce79b069 Mon Sep 17 00:00:00 2001 From: daniele-mng Date: Tue, 1 Oct 2024 10:47:33 +0200 Subject: [PATCH] add: appliance model to page title --- index.html | 23 +++- .../__snapshots__/pagetitle.jsx.snap | 3 - .../components/layout/__tests__/pagetitle.jsx | 32 ++++-- src/web/components/layout/pagetitle.jsx | 12 ++- src/web/components/structure/getLogo.jsx | 35 +----- src/web/utils/applianceData.js | 100 ++++++++++++++++++ 6 files changed, 157 insertions(+), 48 deletions(-) delete mode 100644 src/web/components/layout/__tests__/__snapshots__/pagetitle.jsx.snap create mode 100644 src/web/utils/applianceData.js diff --git a/index.html b/index.html index cec5d6ca6e..9dac9d0087 100644 --- a/index.html +++ b/index.html @@ -1,8 +1,8 @@ - + - + Greenbone Security Assistant @@ -11,5 +11,24 @@
+ diff --git a/src/web/components/layout/__tests__/__snapshots__/pagetitle.jsx.snap b/src/web/components/layout/__tests__/__snapshots__/pagetitle.jsx.snap deleted file mode 100644 index 2805c1d908..0000000000 --- a/src/web/components/layout/__tests__/__snapshots__/pagetitle.jsx.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html - -exports[`PageTitle tests > should render 1`] = `null`; diff --git a/src/web/components/layout/__tests__/pagetitle.jsx b/src/web/components/layout/__tests__/pagetitle.jsx index 3c9fc0419d..997fcc3449 100644 --- a/src/web/components/layout/__tests__/pagetitle.jsx +++ b/src/web/components/layout/__tests__/pagetitle.jsx @@ -3,20 +3,22 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import {describe, test, expect} from '@gsa/testing'; import PageTitle from 'web/components/layout/pagetitle'; -import {render} from 'web/utils/testing'; +import {rendererWith} from 'web/utils/testing'; -describe('PageTitle tests', () => { - test('should render', () => { - const {element} = render(); - expect(element).toMatchSnapshot(); - }); +const gmp = { + settings: { + vendorLabel: 'someVendorLabel', + }, +}; +describe('PageTitle tests', () => { test('Should render default title', () => { + const {render} = rendererWith({gmp}); + const defaultTitle = 'Greenbone Security Assistant'; render(); @@ -24,6 +26,8 @@ describe('PageTitle tests', () => { }); test('Should render custom title', () => { + const {render} = rendererWith({gmp}); + const title = 'foo'; const defaultTitle = 'Greenbone Security Assistant'; render(); @@ -32,6 +36,8 @@ describe('PageTitle tests', () => { }); test('should update value', () => { + const {render} = rendererWith({gmp}); + const title1 = 'foo'; const title2 = 'bar'; const defaultTitle = 'Greenbone Security Assistant'; @@ -43,4 +49,16 @@ describe('PageTitle tests', () => { expect(global.window.document.title).toBe(defaultTitle + ' - ' + title2); }); + test('should render appliance model title', () => { + const {render} = rendererWith({ + gmp: { + settings: { + vendorLabel: 'gsm-150_label.svg', + }, + }, + }); + render(); + + expect(global.window.document.title).toBe('Greenbone - 150'); + }); }); diff --git a/src/web/components/layout/pagetitle.jsx b/src/web/components/layout/pagetitle.jsx index b1382eacd0..a66ad27012 100644 --- a/src/web/components/layout/pagetitle.jsx +++ b/src/web/components/layout/pagetitle.jsx @@ -6,10 +6,15 @@ import {useEffect} from 'react'; import {isDefined} from 'gmp/utils/identity'; import PropTypes from 'web/utils/proptypes'; - -const defaultTitle = 'Greenbone Security Assistant'; +import useGmp from 'web/hooks/useGmp'; +import {applianceTitle} from 'web/utils/applianceData'; const PageTitle = ({title}) => { + const gmp = useGmp(); + const vendorLabel = gmp?.settings?.vendorLabel || 'defaultVendorLabel'; + const defaultTitle = + applianceTitle[vendorLabel] || 'Greenbone Security Assistant'; + useEffect(() => { if (isDefined(title)) { document.title = defaultTitle + ' - ' + title; @@ -20,7 +25,8 @@ const PageTitle = ({title}) => { return () => { document.title = defaultTitle; }; - }, [title]); + }, [defaultTitle, title]); + return null; }; diff --git a/src/web/components/structure/getLogo.jsx b/src/web/components/structure/getLogo.jsx index 6c74e67670..2910361220 100644 --- a/src/web/components/structure/getLogo.jsx +++ b/src/web/components/structure/getLogo.jsx @@ -4,42 +4,11 @@ */ import PropTypes from 'web/utils/proptypes'; -import { - Enterprise150, - Enterprise400, - Enterprise450, - Enterprise600, - Enterprise650, - Enterprise5400, - Enterprise6500, - EnterpriseCeno, - EnterpriseDeca, - EnterpriseExa, - EnterprisePeta, - EnterpriseTera, -} from 'web/components/icon/GreenboneApplianceLogo'; -const APPLIANCE_MODELS = { - 'gsm-150_label.svg': Enterprise150, - 'gsm-400_label.svg': Enterprise400, - 'gsm-400r2_label.svg': Enterprise400, - 'gsm-450_label.svg': Enterprise450, - 'gsm-450r2_label.svg': Enterprise450, - 'gsm-600_label.svg': Enterprise600, - 'gsm-600r2_label.svg': Enterprise600, - 'gsm-650_label.svg': Enterprise650, - 'gsm-650r2_label.svg': Enterprise650, - 'gsm-5400_label.svg': Enterprise5400, - 'gsm-6500_label.svg': Enterprise6500, - 'gsm-ceno_label.svg': EnterpriseCeno, - 'gsm-deca_label.svg': EnterpriseDeca, - 'gsm-exa_label.svg': EnterpriseExa, - 'gsm-peta_label.svg': EnterprisePeta, - 'gsm-tera_label.svg': EnterpriseTera, -}; +import {applianceComponent} from 'web/utils/applianceData'; const getLogo = model => { - const Component = APPLIANCE_MODELS[model]; + const Component = applianceComponent[model]; return Component ? : undefined; }; diff --git a/src/web/utils/applianceData.js b/src/web/utils/applianceData.js new file mode 100644 index 0000000000..9b6270756d --- /dev/null +++ b/src/web/utils/applianceData.js @@ -0,0 +1,100 @@ +/* SPDX-FileCopyrightText: 2024 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { + Enterprise150, + Enterprise400, + Enterprise450, + Enterprise600, + Enterprise650, + Enterprise5400, + Enterprise6500, + EnterpriseCeno, + EnterpriseDeca, + EnterpriseExa, + EnterprisePeta, + EnterpriseTera, +} from 'web/components/icon/GreenboneApplianceLogo'; + +const APPLIANCE_DATA = { + 'gsm-150_label.svg': { + title: 'Greenbone - 150', + component: Enterprise150, + }, + 'gsm-400_label.svg': { + title: 'Greenbone - 400', + component: Enterprise400, + }, + 'gsm-400r2_label.svg': { + title: 'Greenbone - 400', + component: Enterprise400, + }, + 'gsm-450_label.svg': { + title: 'Greenbone - 450', + component: Enterprise450, + }, + 'gsm-450r2_label.svg': { + title: 'Greenbone - 450', + component: Enterprise450, + }, + 'gsm-600_label.svg': { + title: 'Greenbone - 600', + component: Enterprise600, + }, + 'gsm-600r2_label.svg': { + title: 'Greenbone - 600', + component: Enterprise600, + }, + 'gsm-650_label.svg': { + title: 'Greenbone - 650', + component: Enterprise650, + }, + 'gsm-650r2_label.svg': { + title: 'Greenbone - 650', + component: Enterprise650, + }, + 'gsm-5400_label.svg': { + title: 'Greenbone - 5400', + component: Enterprise5400, + }, + 'gsm-6500_label.svg': { + title: 'Greenbone - 6500', + component: Enterprise6500, + }, + 'gsm-ceno_label.svg': { + title: 'Greenbone - CENO', + component: EnterpriseCeno, + }, + 'gsm-deca_label.svg': { + title: 'Greenbone - DECA', + component: EnterpriseDeca, + }, + 'gsm-exa_label.svg': { + title: 'Greenbone - EXA', + component: EnterpriseExa, + }, + 'gsm-peta_label.svg': { + title: 'Greenbone - PETA', + component: EnterprisePeta, + }, + 'gsm-tera_label.svg': { + title: 'Greenbone - TERA', + component: EnterpriseTera, + }, +}; + +export const applianceTitle = Object.fromEntries( + Object.entries(APPLIANCE_DATA).map(([vendorLabel, {title}]) => [ + vendorLabel, + title, + ]), +); + +export const applianceComponent = Object.fromEntries( + Object.entries(APPLIANCE_DATA).map(([vendorLabel, {component}]) => [ + vendorLabel, + component, + ]), +);