Skip to content

Commit

Permalink
Add: Appliance logo in the app header
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng committed Sep 27, 2024
1 parent 40e19d4 commit 7cd202a
Show file tree
Hide file tree
Showing 15 changed files with 397 additions and 21 deletions.
57 changes: 39 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"node": ">=18.0"
},
"dependencies": {
"@greenbone/opensight-ui-components": "^0.3.0",
"@greenbone/opensight-ui-components": "^0.4.1-alpha1",
"@mantine/core": "^6.0.0",
"@reduxjs/toolkit": "^2.2.7",
"@sentry/react": "^8.28.0",
Expand Down
25 changes: 25 additions & 0 deletions src/web/components/icon/GreenboneApplianceLogo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import SvgIconWrapper from './SvgIconWrapper';
import Enterprise150Svg from 'web/components/icon/svg/Enterprise_150.svg';
import Enterprise400Svg from 'web/components/icon/svg/Enterprise_400.svg';
import Enterprise450Svg from 'web/components/icon/svg/Enterprise_450.svg';
import Enterprise600Svg from 'web/components/icon/svg/Enterprise_600.svg';
import Enterprise650Svg from 'web/components/icon/svg/Enterprise_650.svg';
import Enterprise5400Svg from 'web/components/icon/svg/Enterprise_5400.svg';
import Enterprise6500Svg from 'web/components/icon/svg/Enterprise_6500.svg';

const createEnterpriseComponent = Component => () => (
<SvgIconWrapper size={['150px', '150px']} component={Component} />
);

export const Enterprise150 = createEnterpriseComponent(Enterprise150Svg);
export const Enterprise400 = createEnterpriseComponent(Enterprise400Svg);
export const Enterprise450 = createEnterpriseComponent(Enterprise450Svg);
export const Enterprise600 = createEnterpriseComponent(Enterprise600Svg);
export const Enterprise650 = createEnterpriseComponent(Enterprise650Svg);
export const Enterprise5400 = createEnterpriseComponent(Enterprise5400Svg);
export const Enterprise6500 = createEnterpriseComponent(Enterprise6500Svg);
23 changes: 23 additions & 0 deletions src/web/components/icon/SvgIconWrapper.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import PropTypes from 'web/utils/proptypes';
import SvgIcon from './svgicon';

const SvgIconWrapper = ({component: Component, size, ...props}) => (
<SvgIcon size={size} {...props}>
{svgProps => <Component {...svgProps} />}
</SvgIcon>
);

SvgIconWrapper.propTypes = {
component: PropTypes.node.isRequired,
size: PropTypes.oneOfType([
PropTypes.oneOf(['tiny', 'small', 'medium', 'large']),
PropTypes.string,
]),
};

export default SvgIconWrapper;
31 changes: 31 additions & 0 deletions src/web/components/icon/svg/Enterprise_150.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/web/components/icon/svg/Enterprise_400.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/web/components/icon/svg/Enterprise_450.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/web/components/icon/svg/Enterprise_5400.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/web/components/icon/svg/Enterprise_600.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/web/components/icon/svg/Enterprise_650.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/web/components/icon/svg/Enterprise_6500.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions src/web/components/structure/__tests__/getLogo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {describe, test, expect} from '@gsa/testing';
import {render} from 'web/utils/testing';
import getLogo from 'web/components/structure/getLogo';

describe('getLogo', () => {
const testCases = [
['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'],
];

test.each(testCases)('returns %s for %s', (model, expectedTestId) => {
const {getByTestId} = render(getLogo(model));
expect(getByTestId(expectedTestId)).toBeInTheDocument();
});

test('returns undefined for unknown model', () => {
const result = getLogo('unknown_model.svg');
expect(result).toBeUndefined();
});
});
52 changes: 52 additions & 0 deletions src/web/components/structure/getLogo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* SPDX-FileCopyrightText: 2024 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import PropTypes from 'web/utils/proptypes';
import {
Enterprise150,
Enterprise400,
Enterprise450,
Enterprise600,
Enterprise650,
Enterprise5400,
Enterprise6500,
} 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,
};

const getLogo = model => {
const Component = APPLIANCE_MODELS[model];
return Component ? <Component /> : undefined;
};

getLogo.propTypes = {
model: PropTypes.oneOf([
'gsm-150_label.svg',
'gsm-400_label.svg',
'gsm-400r2_label.svg',
'gsm-450_label.svg',
'gsm-450r2_label.svg',
'gsm-600_label.svg',
'gsm-600r2_label.svg',
'gsm-650_label.svg',
'gsm-650r2_label.svg',
'gsm-5400_label.svg',
'gsm-6500_label.svg',
]),
};

export default getLogo;
6 changes: 5 additions & 1 deletion src/web/components/structure/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import useUserName from 'web/hooks/useUserName';
import useGmp from 'web/hooks/useGmp';

import LogoutIcon from 'web/components/icon/logouticon';
import getLogo from 'web/components/structure/getLogo';

Check warning on line 19 in src/web/components/structure/header.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/structure/header.jsx#L19

Added line #L19 was not covered by tests
import MySettingsIcon from 'web/components/icon/mysettingsicon';
import LanguageSwitch from './languageswitch';
import SessionTimer from '../sessionTimer/SessionTimer';
Expand All @@ -25,6 +26,7 @@ const Header = () => {
const username = useUserName();
const loggedIn = useUserIsLoggedIn();
const navigate = useNavigate();
const logoComponent = getLogo(gmp.settings.vendorLabel);

Check warning on line 29 in src/web/components/structure/header.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/structure/header.jsx#L29

Added line #L29 was not covered by tests

const handleSettingsClick = useCallback(
event => {
Expand Down Expand Up @@ -57,14 +59,16 @@ const Header = () => {
icon: <LogoutIcon />,
},
];

return (
<AppHeader
logo={logoComponent}

Check warning on line 65 in src/web/components/structure/header.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/structure/header.jsx#L65

Added line #L65 was not covered by tests
languageSwitch={<LanguageSwitch />}
menuPoints={menuPoints}
isLoggedIn={loggedIn}
sessionTimer={<SessionTimer />}
username={username}
logoLink="/"
logoLink="/dashboards"

Check warning on line 71 in src/web/components/structure/header.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/components/structure/header.jsx#L71

Added line #L71 was not covered by tests
/>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/web/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const LoggedInRoutes = () => {
/>
}
/>
<Route path="/" element={<Navigate to="/dashboard" />} />
<Route path="/" element={<Navigate to="/dashboards" />} />

Check warning on line 247 in src/web/routes.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/routes.jsx#L247

Added line #L247 was not covered by tests

<Route path="*" element={<PageNotFound />} />
</Routes>
Expand Down

0 comments on commit 7cd202a

Please sign in to comment.