From c4542fd7101aff2342d558310fb40b3d14b587c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Wed, 19 Jun 2024 12:04:31 +0200 Subject: [PATCH] Change: Move useGmp hook to hooks directory --- src/web/components/bar/titlebar.jsx | 5 +-- src/web/components/img/product.jsx | 3 +- src/web/components/link/manuallink.jsx | 3 +- src/web/components/link/protocoldoclink.jsx | 2 +- src/web/components/menu/usermenu.jsx | 2 +- .../components/provider/licenseprovider.jsx | 3 +- src/web/entities/BulkTags.jsx | 2 +- src/web/entities/useEntitiesReloadInterval.js | 2 +- src/web/{utils => hooks}/__tests__/useGmp.jsx | 2 +- src/web/{utils => hooks}/useGmp.js | 0 src/web/hooks/usePageFilter.js | 2 +- src/web/pages/cves/details.jsx | 5 +-- src/web/pages/cves/row.jsx | 20 +++++----- src/web/pages/cves/table.jsx | 17 ++++----- src/web/pages/extras/feedstatuspage.jsx | 2 +- src/web/pages/nvts/details.jsx | 38 ++++++++++++------- src/web/pages/nvts/row.jsx | 18 ++++----- src/web/pages/nvts/table.jsx | 17 +++------ src/web/pages/portlists/listpage.jsx | 2 +- src/web/pages/scanners/detailspage.jsx | 2 +- src/web/pages/scanners/listpage.jsx | 2 +- src/web/pages/scanners/row.jsx | 2 +- 22 files changed, 72 insertions(+), 79 deletions(-) rename src/web/{utils => hooks}/__tests__/useGmp.jsx (92%) rename src/web/{utils => hooks}/useGmp.js (100%) diff --git a/src/web/components/bar/titlebar.jsx b/src/web/components/bar/titlebar.jsx index 460cfd624e..772cd5854c 100644 --- a/src/web/components/bar/titlebar.jsx +++ b/src/web/components/bar/titlebar.jsx @@ -3,7 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React from 'react'; import {connect} from 'react-redux'; @@ -25,7 +24,7 @@ import {isLoggedIn} from 'web/store/usersettings/selectors'; import PropTypes from 'web/utils/proptypes'; import Theme from 'web/utils/theme'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; const TITLE_BAR_HEIGHT = '42px'; @@ -90,7 +89,7 @@ const Titlebar = ({loggedIn}) => { ); -} +}; Titlebar.propTypes = { loggedIn: PropTypes.bool.isRequired, diff --git a/src/web/components/img/product.jsx b/src/web/components/img/product.jsx index e684a73a42..0744170572 100644 --- a/src/web/components/img/product.jsx +++ b/src/web/components/img/product.jsx @@ -3,7 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React from 'react'; import styled from 'styled-components'; @@ -12,7 +11,7 @@ import _ from 'gmp/locale'; import {isDefined} from 'gmp/utils/identity'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import Img from './img'; diff --git a/src/web/components/link/manuallink.jsx b/src/web/components/link/manuallink.jsx index 38977d8325..c53a43df39 100644 --- a/src/web/components/link/manuallink.jsx +++ b/src/web/components/link/manuallink.jsx @@ -3,7 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React from 'react'; import {getLocale} from 'gmp/locale/lang'; @@ -11,7 +10,7 @@ import {getLocale} from 'gmp/locale/lang'; import {isDefined} from 'gmp/utils/identity'; import PropTypes from 'web/utils/proptypes'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import BlankLink from './blanklink'; diff --git a/src/web/components/link/protocoldoclink.jsx b/src/web/components/link/protocoldoclink.jsx index 2b7c6cf508..ded9d8fd8f 100644 --- a/src/web/components/link/protocoldoclink.jsx +++ b/src/web/components/link/protocoldoclink.jsx @@ -7,7 +7,7 @@ import React from 'react'; import PropTypes from 'web/utils/proptypes'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import BlankLink from './blanklink'; diff --git a/src/web/components/menu/usermenu.jsx b/src/web/components/menu/usermenu.jsx index 83a68623f2..9aef15e649 100644 --- a/src/web/components/menu/usermenu.jsx +++ b/src/web/components/menu/usermenu.jsx @@ -22,7 +22,7 @@ import Divider from 'web/components/layout/divider'; import Link from 'web/components/link/link'; import Theme from 'web/utils/theme'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import useUserName from 'web/hooks/useUserName'; import useUserSessionTimeout from 'web/hooks/useUserSessionTimeout'; import useUserTimezone from 'web/hooks/useUserTimezone'; diff --git a/src/web/components/provider/licenseprovider.jsx b/src/web/components/provider/licenseprovider.jsx index 3b4c2eab62..14492eb5f8 100644 --- a/src/web/components/provider/licenseprovider.jsx +++ b/src/web/components/provider/licenseprovider.jsx @@ -3,10 +3,9 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React, {useEffect, useState} from 'react'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; export const LicenseContext = React.createContext({}); diff --git a/src/web/entities/BulkTags.jsx b/src/web/entities/BulkTags.jsx index 8fcd855b30..e8bfc14628 100644 --- a/src/web/entities/BulkTags.jsx +++ b/src/web/entities/BulkTags.jsx @@ -13,7 +13,7 @@ import {apiType, getEntityType, typeName} from 'gmp/utils/entitytype'; import PropTypes from 'web/utils/proptypes'; import SelectionType from 'web/utils/selectiontype'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import useUserSessionTimeout from 'web/hooks/useUserSessionTimeout'; import TagDialog from 'web/pages/tags/dialog'; diff --git a/src/web/entities/useEntitiesReloadInterval.js b/src/web/entities/useEntitiesReloadInterval.js index d834d536d3..703d3c5956 100644 --- a/src/web/entities/useEntitiesReloadInterval.js +++ b/src/web/entities/useEntitiesReloadInterval.js @@ -7,7 +7,7 @@ import {useCallback} from 'react'; import {isDefined} from 'gmp/utils/identity'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; /** * Hook to get the reload interval for entities diff --git a/src/web/utils/__tests__/useGmp.jsx b/src/web/hooks/__tests__/useGmp.jsx similarity index 92% rename from src/web/utils/__tests__/useGmp.jsx rename to src/web/hooks/__tests__/useGmp.jsx index 6a5e54b94a..8b60e435dc 100644 --- a/src/web/utils/__tests__/useGmp.jsx +++ b/src/web/hooks/__tests__/useGmp.jsx @@ -5,7 +5,7 @@ import {describe, test, expect, testing} from '@gsa/testing'; -import {rendererWith} from '../testing'; +import {rendererWith} from 'web/utils/testing'; import useGmp from '../useGmp'; diff --git a/src/web/utils/useGmp.js b/src/web/hooks/useGmp.js similarity index 100% rename from src/web/utils/useGmp.js rename to src/web/hooks/useGmp.js diff --git a/src/web/hooks/usePageFilter.js b/src/web/hooks/usePageFilter.js index f8f3408649..1588264732 100644 --- a/src/web/hooks/usePageFilter.js +++ b/src/web/hooks/usePageFilter.js @@ -26,7 +26,7 @@ import {getUserSettingsDefaults} from 'web/store/usersettings/defaults/selectors import {loadUserSettingsDefaultFilter} from 'web/store/usersettings/defaultfilters/actions'; import {getUserSettingsDefaultFilter} from 'web/store/usersettings/defaultfilters/selectors'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import useShallowEqualSelector from './useShallowEqualSelector'; diff --git a/src/web/pages/cves/details.jsx b/src/web/pages/cves/details.jsx index df0d48f31d..dafde48567 100644 --- a/src/web/pages/cves/details.jsx +++ b/src/web/pages/cves/details.jsx @@ -3,7 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React from 'react'; import {_, _l} from 'gmp/locale/lang'; @@ -25,7 +24,7 @@ import TableData from 'web/components/table/data'; import TableRow from 'web/components/table/row'; import PropTypes from 'web/utils/proptypes'; -import useGmp from "web/utils/useGmp"; +import useGmp from 'web/hooks/useGmp'; const CVSS_PROPS = { cvssAccessVector: _l('Access Vector'), @@ -45,7 +44,7 @@ const CVSS_PROPS = { cvssAvailabilityVS: _l('Vulnerable System Availability Impact'), cvssConfidentialitySS: _l('Subsequent System Confidentiality Impact'), cvssIntegritySS: _l('Subsequent System Integrity Impact'), - cvssAvailabilitySS: _l('Subsequent System Availability Impact'), + cvssAvailabilitySS: _l('Subsequent System Availability Impact'), }; const CveDetails = ({entity}) => { diff --git a/src/web/pages/cves/row.jsx b/src/web/pages/cves/row.jsx index 0305ed6d68..e820241956 100644 --- a/src/web/pages/cves/row.jsx +++ b/src/web/pages/cves/row.jsx @@ -3,7 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React from 'react'; import {_} from 'gmp/locale/lang'; @@ -25,8 +24,8 @@ import EntitiesActions from 'web/entities/actions'; import {RowDetailsToggle} from 'web/entities/row'; import PropTypes from 'web/utils/proptypes'; -import {isNumber} from "gmp/utils/identity"; -import useGmp from "web/utils/useGmp"; +import {isNumber} from 'gmp/utils/identity'; +import useGmp from 'web/hooks/useGmp'; const Row = ({ actionsComponent: ActionsComponent = EntitiesActions, @@ -36,8 +35,8 @@ const Row = ({ ...props }) => { const gmp = useGmp(); - const epssScore = entity?.epss?.score - const epssPercentile = entity?.epss?.percentile + const epssScore = entity?.epss?.score; + const epssPercentile = entity?.epss?.percentile; return ( @@ -60,20 +59,19 @@ const Row = ({ - { - gmp.settings.enableEPSS && + {gmp.settings.enableEPSS && ( <> - {isNumber(epssScore) ? epssScore.toFixed(5) : _("N/A")} + {isNumber(epssScore) ? epssScore.toFixed(5) : _('N/A')} - {isNumber(epssPercentile) ? epssPercentile.toFixed(5) : _("N/A")} + {isNumber(epssPercentile) ? epssPercentile.toFixed(5) : _('N/A')} - } + )} - ) + ); }; Row.propTypes = { diff --git a/src/web/pages/cves/table.jsx b/src/web/pages/cves/table.jsx index 95e8306cc6..aa44580998 100644 --- a/src/web/pages/cves/table.jsx +++ b/src/web/pages/cves/table.jsx @@ -20,8 +20,8 @@ import TableRow from 'web/components/table/row'; import CveDetails from './details'; import CveRow from './row'; -import {isDefined} from "gmp/utils/identity.js"; -import useGmp from "web/utils/useGmp"; +import {isDefined} from 'gmp/utils/identity.js'; +import useGmp from 'web/hooks/useGmp'; const Header = ({ actionsColumn, @@ -80,11 +80,9 @@ const Header = ({ onSortChange={onSortChange} title={_('Severity')} /> - {gmp.settings.enableEPSS && - - {_("EPSS")} - - } + {gmp.settings.enableEPSS && ( + {_('EPSS')} + )} {isDefined(actionsColumn) ? ( actionsColumn ) : ( @@ -93,8 +91,7 @@ const Header = ({ )} - { - gmp.settings.enableEPSS && + {gmp.settings.enableEPSS && ( - } + )} ); }; diff --git a/src/web/pages/extras/feedstatuspage.jsx b/src/web/pages/extras/feedstatuspage.jsx index 5c1adacd47..985c28a0cc 100644 --- a/src/web/pages/extras/feedstatuspage.jsx +++ b/src/web/pages/extras/feedstatuspage.jsx @@ -50,7 +50,7 @@ import Reload, { USE_DEFAULT_RELOAD_INTERVAL_ACTIVE, } from 'web/components/loading/reload'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import PropTypes from 'web/utils/proptypes'; const ToolBarIcons = () => ( diff --git a/src/web/pages/nvts/details.jsx b/src/web/pages/nvts/details.jsx index 5f7e80511d..2a4ac1e8d8 100644 --- a/src/web/pages/nvts/details.jsx +++ b/src/web/pages/nvts/details.jsx @@ -12,7 +12,7 @@ import {isDefined, isNumber} from 'gmp/utils/identity'; import {TAG_NA} from 'gmp/models/nvt'; import PropTypes from 'web/utils/proptypes'; -import useGmp from "web/utils/useGmp"; +import useGmp from 'web/hooks/useGmp'; import {na, getTranslatableSeverityOrigin} from 'web/utils/render'; @@ -33,7 +33,7 @@ import TableRow from 'web/components/table/row'; import References from './references'; import Solution from './solution'; import Pre from './preformatted'; -import CveLink from "web/components/link/cvelink"; +import CveLink from 'web/components/link/cvelink'; const NvtDetails = ({entity, links = true}) => { const { @@ -99,7 +99,7 @@ const NvtDetails = ({entity, links = true}) => { )} - { gmp.settings.enableEPSS && isDefined(epss?.max_severity) && + {gmp.settings.enableEPSS && isDefined(epss?.max_severity) && ( <> {_('EPSS (CVE with highest severity)')} @@ -108,14 +108,16 @@ const NvtDetails = ({entity, links = true}) => { {_('EPSS Score')} {isNumber(epss?.max_severity?.score) - ? epss?.max_severity?.score.toFixed(5) : _("N/A")} + ? epss?.max_severity?.score.toFixed(5) + : _('N/A')} {_('EPSS Percentile')} {isNumber(epss?.max_severity?.percentile) - ? epss?.max_severity?.percentile.toFixed(5) : _("N/A")} + ? epss?.max_severity?.percentile.toFixed(5) + : _('N/A')} @@ -129,13 +131,16 @@ const NvtDetails = ({entity, links = true}) => { {_('CVE Severity')} - } - { gmp.settings.enableEPSS && isDefined(epss?.max_epss) && + )} + {gmp.settings.enableEPSS && isDefined(epss?.max_epss) && ( <> {_('EPSS (highest EPSS score)')} @@ -144,14 +149,16 @@ const NvtDetails = ({entity, links = true}) => { {_('EPSS Score')} {isNumber(epss?.max_epss?.score) - ? epss?.max_epss?.score.toFixed(5) : _("N/A")} + ? epss?.max_epss?.score.toFixed(5) + : _('N/A')} {_('EPSS Percentile')} {isNumber(epss?.max_epss?.percentile) - ? epss?.max_epss?.percentile.toFixed(5) : _("N/A")} + ? epss?.max_epss?.percentile.toFixed(5) + : _('N/A')} @@ -166,13 +173,16 @@ const NvtDetails = ({entity, links = true}) => { {_('CVE Severity')} - } + )} diff --git a/src/web/pages/nvts/row.jsx b/src/web/pages/nvts/row.jsx index 13fb41c812..03c588b224 100644 --- a/src/web/pages/nvts/row.jsx +++ b/src/web/pages/nvts/row.jsx @@ -3,7 +3,6 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React from 'react'; import Filter from 'gmp/models/filter.js'; @@ -30,8 +29,8 @@ import EntitiesActions from 'web/entities/actions'; import {RowDetailsToggle} from 'web/entities/row'; import PropTypes from 'web/utils/proptypes'; -import useGmp from "web/utils/useGmp"; -import {_} from "gmp/locale/lang.js"; +import useGmp from 'web/hooks/useGmp'; +import {_} from 'gmp/locale/lang.js'; const Row = ({ actionsComponent: ActionsComponent = EntitiesActions, @@ -46,8 +45,8 @@ const Row = ({ const filter = Filter.fromString('family="' + entity.family + '"'); onFilterChanged(filter); }; - const epssScore = entity?.epss?.max_severity?.score - const epssPercentile = entity?.epss?.max_severity?.percentile + const epssScore = entity?.epss?.max_severity?.score; + const epssPercentile = entity?.epss?.max_severity?.percentile; return ( @@ -94,17 +93,16 @@ const Row = ({ {entity.qod && } - { - gmp.settings.enableEPSS && + {gmp.settings.enableEPSS && ( <> - {isNumber(epssScore) ? epssScore.toFixed(5) : _("N/A")} + {isNumber(epssScore) ? epssScore.toFixed(5) : _('N/A')} - {isNumber(epssPercentile) ? epssPercentile.toFixed(5) : _("N/A")} + {isNumber(epssPercentile) ? epssPercentile.toFixed(5) : _('N/A')} - } + )} ); diff --git a/src/web/pages/nvts/table.jsx b/src/web/pages/nvts/table.jsx index e343e10bca..4b41f07f21 100644 --- a/src/web/pages/nvts/table.jsx +++ b/src/web/pages/nvts/table.jsx @@ -27,7 +27,7 @@ import TableRow from 'web/components/table/row'; import NvtDetails from './details'; import NvtRow from './row'; -import useGmp from "web/utils/useGmp"; +import useGmp from 'web/hooks/useGmp'; const Header = ({ actionsColumn, @@ -115,16 +115,12 @@ const Header = ({ onSortChange={onSortChange} title={_('QoD')} /> - { - gmp.settings.enableEPSS && - - {_("EPSS")} - - } + {gmp.settings.enableEPSS && ( + {_('EPSS')} + )} {actionsColumn} - { - gmp.settings.enableEPSS && + {gmp.settings.enableEPSS && ( - } - + )} ); }; diff --git a/src/web/pages/portlists/listpage.jsx b/src/web/pages/portlists/listpage.jsx index 65ac7964d7..8b0b6123df 100644 --- a/src/web/pages/portlists/listpage.jsx +++ b/src/web/pages/portlists/listpage.jsx @@ -14,7 +14,7 @@ import {isDefined, hasValue} from 'gmp/utils/identity'; import useCapabilities from 'web/hooks/useCapabilities'; import useUserSessionTimeout from 'web/hooks/useUserSessionTimeout'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import usePageFilter from 'web/hooks/usePageFilter'; import useShallowEqualSelector from 'web/hooks/useShallowEqualSelector'; import useReload from 'web/hooks/useReload'; diff --git a/src/web/pages/scanners/detailspage.jsx b/src/web/pages/scanners/detailspage.jsx index 1dd432c191..bdb06cc896 100644 --- a/src/web/pages/scanners/detailspage.jsx +++ b/src/web/pages/scanners/detailspage.jsx @@ -56,7 +56,7 @@ import PropTypes from 'web/utils/proptypes'; import ScannerComponent from './component'; import ScannerDetails from './details'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; const ToolBarIcons = ({ entity, diff --git a/src/web/pages/scanners/listpage.jsx b/src/web/pages/scanners/listpage.jsx index dd289e1275..944738c053 100644 --- a/src/web/pages/scanners/listpage.jsx +++ b/src/web/pages/scanners/listpage.jsx @@ -29,7 +29,7 @@ import { selector as entitiesSelector, } from 'web/store/entities/scanners'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; import ScannerComponent from './component'; import ScannersTable, {SORT_FIELDS} from './table'; diff --git a/src/web/pages/scanners/row.jsx b/src/web/pages/scanners/row.jsx index 01cf5e7fa7..754c3c185a 100644 --- a/src/web/pages/scanners/row.jsx +++ b/src/web/pages/scanners/row.jsx @@ -34,7 +34,7 @@ import EditIcon from 'web/entity/icon/editicon'; import TrashIcon from 'web/entity/icon/trashicon'; import PropTypes from 'web/utils/proptypes'; -import useGmp from 'web/utils/useGmp'; +import useGmp from 'web/hooks/useGmp'; const Actions = withEntitiesActions( ({