diff --git a/src/web/components/powerfilter/dialog.jsx b/src/web/components/powerfilter/dialog.jsx index ebec58535c..cd06ca0af5 100644 --- a/src/web/components/powerfilter/dialog.jsx +++ b/src/web/components/powerfilter/dialog.jsx @@ -3,10 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ - import React from 'react'; -import withFilterDialog from 'web/components/powerfilter/withFilterDialog'; import useCapabilities from 'web/hooks/useCapabilities'; import CreateNamedFilterGroup from './createnamedfiltergroup'; @@ -58,9 +56,6 @@ export const DefaultFilterDialog = ({ DefaultFilterDialog.propTypes = DefaultFilterDialogPropTypes; -export const createFilterDialog = options => - withFilterDialog(options)(DefaultFilterDialog); - export {DefaultFilterDialogPropTypes}; export default DefaultFilterDialog; diff --git a/src/web/pages/alerts/filterdialog.jsx b/src/web/pages/alerts/filterdialog.jsx new file mode 100644 index 0000000000..e32c72a62a --- /dev/null +++ b/src/web/pages/alerts/filterdialog.jsx @@ -0,0 +1,86 @@ +/* SPDX-FileCopyrightText: 2024 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import PropTypes from 'web/utils/proptypes'; + +import DefaultFilterDialog from 'web/components/powerfilter/dialog'; +import FilterDialog from 'web/components/powerfilter/filterdialog'; +import useFilterDialog from 'web/components/powerfilter/useFilterDialog'; +import useFilterDialogSave from 'web/components/powerfilter/useFilterDialogSave'; + +import useTranslation from 'web/hooks/useTranslation'; + +const AlertsFilterDialog = ({ + filter, + onCloseClick, + onClose = onCloseClick, + onFilterChanged, + onFilterCreated, + ...props +}) => { + const [_] = useTranslation(); + const filterDialogProps = useFilterDialog(filter); + const [handleSave] = useFilterDialogSave( + 'alert', + { + onClose, + onFilterChanged, + onFilterCreated, + }, + filterDialogProps, + ); + + const SORT_FIELDS = [ + { + name: 'name', + displayName: _('Name'), + width: '25%', + }, + { + name: 'event', + displayName: _('Event'), + width: '21%', + }, + { + name: 'condition', + displayName: _('Condition'), + width: '21%', + }, + { + name: 'method', + displayName: _('Method'), + width: '10%', + }, + { + name: 'filter', + displayName: _('Filter'), + width: '10%', + }, + { + name: 'active', + displayName: _('Active'), + width: '5%', + }, + ]; + return ( + + + + ); +}; + +AlertsFilterDialog.propTypes = { + filter: PropTypes.filter, + onClose: PropTypes.func, + onCloseClick: PropTypes.func, // should be removed in future + onFilterChanged: PropTypes.func, + onFilterCreated: PropTypes.func, +}; + +export default AlertsFilterDialog; diff --git a/src/web/pages/alerts/listpage.jsx b/src/web/pages/alerts/listpage.jsx index 8319ebb2a6..e397392aaf 100644 --- a/src/web/pages/alerts/listpage.jsx +++ b/src/web/pages/alerts/listpage.jsx @@ -23,15 +23,16 @@ import PageTitle from 'web/components/layout/pagetitle'; import AlertIcon from 'web/components/icon/alerticon'; -import {createFilterDialog} from 'web/components/powerfilter/dialog'; - import { loadEntities, selector as entitiesSelector, } from 'web/store/entities/alerts'; import AlertComponent from './component'; -import AlertTable, {SORT_FIELDS} from './table'; +import AlertTable from './table'; + +import {useTranslation} from 'react-i18next'; +import AlertsFilterDialog from 'web/pages/alerts/filterdialog'; export const ToolBarIcons = withCapabilities( ({capabilities, onAlertCreateClick}) => ( @@ -52,10 +53,6 @@ ToolBarIcons.propTypes = { onAlertCreateClick: PropTypes.func.isRequired, }; -const AlertFilterDialog = createFilterDialog({ - sortFields: SORT_FIELDS, -}); - const AlertsPage = ({ showError, showSuccess, @@ -64,48 +61,52 @@ const AlertsPage = ({ onError, onInteraction, ...props -}) => ( - - {({clone, create, delete: delete_func, download, edit, save, test}) => ( - - - } - table={AlertTable} - title={_('Alerts')} - toolBarIcons={ToolBarIcons} - onAlertCloneClick={clone} - onAlertCreateClick={create} - onAlertDeleteClick={delete_func} - onAlertDownloadClick={download} - onAlertEditClick={edit} - onAlertTestClick={test} - onAlertSaveClick={save} - onError={onError} - onInteraction={onInteraction} - onPermissionChanged={onChanged} - onPermissionDownloaded={onDownloaded} - onPermissionDownloadError={onError} - /> - - )} - -); +}) => { + const [_] = useTranslation(); + + return ( + + {({clone, create, delete: delete_func, download, edit, save, test}) => ( + <> + + } + table={AlertTable} + title={_('Alerts')} + toolBarIcons={ToolBarIcons} + onAlertCloneClick={clone} + onAlertCreateClick={create} + onAlertDeleteClick={delete_func} + onAlertDownloadClick={download} + onAlertEditClick={edit} + onAlertTestClick={test} + onAlertSaveClick={save} + onError={onError} + onInteraction={onInteraction} + onPermissionChanged={onChanged} + onPermissionDownloaded={onDownloaded} + onPermissionDownloadError={onError} + /> + + )} + + ); +}; AlertsPage.propTypes = { showError: PropTypes.func.isRequired, diff --git a/src/web/pages/permissions/listpage.jsx b/src/web/pages/permissions/listpage.jsx index e24698b0b4..d3a2c9358b 100644 --- a/src/web/pages/permissions/listpage.jsx +++ b/src/web/pages/permissions/listpage.jsx @@ -29,7 +29,7 @@ import useTranslation from 'web/hooks/useTranslation'; import Table from './table'; import PermissionComponent from './component'; -import FilterDialog from '../filters/dialog'; +import FilterDialog from 'web/pages/permissions/filterdialog'; const ToolBarIcons = ({onPermissionCreateClick}) => { const capabilities = useCapabilities(); diff --git a/src/web/pages/scanconfigs/filterdialog.jsx b/src/web/pages/scanconfigs/filterdialog.jsx new file mode 100644 index 0000000000..e01eb8adf3 --- /dev/null +++ b/src/web/pages/scanconfigs/filterdialog.jsx @@ -0,0 +1,77 @@ +/* SPDX-FileCopyrightText: 2024 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import PropTypes from 'web/utils/proptypes'; + +import DefaultFilterDialog from 'web/components/powerfilter/dialog'; +import FilterDialog from 'web/components/powerfilter/filterdialog'; +import useFilterDialog from 'web/components/powerfilter/useFilterDialog'; +import useFilterDialogSave from 'web/components/powerfilter/useFilterDialogSave'; + +import useTranslation from 'web/hooks/useTranslation'; + +const ScanConfigFilterDialog = ({ + filter, + onCloseClick, + onClose = onCloseClick, + onFilterChanged, + onFilterCreated, + ...props +}) => { + const [_] = useTranslation(); + const filterDialogProps = useFilterDialog(filter); + const [handleSave] = useFilterDialogSave( + 'config', + { + onClose, + onFilterChanged, + onFilterCreated, + }, + filterDialogProps, + ); + + const SORT_FIELDS = [ + { + name: 'name', + displayName: _('Name'), + }, + { + name: 'families_total', + displayName: _('Families: Total'), + }, + { + name: 'families_trend', + displayName: _('Families: Trend'), + }, + { + name: 'nvts_total', + displayName: _('NVTs: Total'), + }, + { + name: 'nvts_trend', + displayName: _('NVTs: Trend'), + }, + ]; + + return ( + + + + ); +}; + +ScanConfigFilterDialog.propTypes = { + filter: PropTypes.filter, + onClose: PropTypes.func, + onCloseClick: PropTypes.func, // should be removed in future + onFilterChanged: PropTypes.func, + onFilterCreated: PropTypes.func, +}; + +export default ScanConfigFilterDialog; diff --git a/src/web/pages/scanconfigs/listpage.jsx b/src/web/pages/scanconfigs/listpage.jsx index cc8a3c7fb2..b3118e57b8 100644 --- a/src/web/pages/scanconfigs/listpage.jsx +++ b/src/web/pages/scanconfigs/listpage.jsx @@ -5,8 +5,6 @@ import React from 'react'; -import _ from 'gmp/locale'; - import {SCANCONFIGS_FILTER_FILTER} from 'gmp/models/filter'; import PropTypes from 'web/utils/proptypes'; @@ -24,38 +22,41 @@ import PageTitle from 'web/components/layout/pagetitle'; import IconDivider from 'web/components/layout/icondivider'; -import {createFilterDialog} from 'web/components/powerfilter/dialog'; - import { loadEntities, selector as entitiesSelector, } from 'web/store/entities/scanconfigs'; import ScanConfigComponent from './component'; -import Table, {SORT_FIELDS} from './table'; +import Table from './table'; +import useTranslation from 'web/hooks/useTranslation'; +import ScanConfigFilterDialog from 'web/pages/scanconfigs/filterdialog'; export const ToolBarIcons = withCapabilities( - ({capabilities, onScanConfigCreateClick, onScanConfigImportClick}) => ( - - - {capabilities.mayCreate('config') && ( - - )} - {capabilities.mayCreate('config') && ( - { + const [_] = useTranslation(); + return ( + + - )} - - ), + {capabilities.mayCreate('config') && ( + + )} + {capabilities.mayCreate('config') && ( + + )} + + ); + }, ); ToolBarIcons.propTypes = { @@ -63,60 +64,60 @@ ToolBarIcons.propTypes = { onScanConfigImportClick: PropTypes.func.isRequired, }; -const ScanConfigFilterDialog = createFilterDialog({ - sortFields: SORT_FIELDS, -}); - const ScanConfigsPage = ({ onChanged, onDownloaded, onError, onInteraction, ...props -}) => ( - - {({ - clone, - create, - delete: delete_func, - download, - edit, - import: import_func, - }) => ( - - - } - table={Table} - title={_('Scan Configs')} - toolBarIcons={ToolBarIcons} - onError={onError} - onInteraction={onInteraction} - onScanConfigImportClick={import_func} - onScanConfigCloneClick={clone} - onScanConfigCreateClick={create} - onScanConfigDeleteClick={delete_func} - onScanConfigDownloadClick={download} - onScanConfigEditClick={edit} - /> - - )} - -); +}) => { + const [_] = useTranslation(); + + return ( + + {({ + clone, + create, + delete: delete_func, + download, + edit, + import: import_func, + }) => ( + <> + + } + table={Table} + title={_('Scan Configs')} + toolBarIcons={ToolBarIcons} + onError={onError} + onInteraction={onInteraction} + onScanConfigImportClick={import_func} + onScanConfigCloneClick={clone} + onScanConfigCreateClick={create} + onScanConfigDeleteClick={delete_func} + onScanConfigDownloadClick={download} + onScanConfigEditClick={edit} + /> + + )} + + ); +}; ScanConfigsPage.propTypes = { onChanged: PropTypes.func.isRequired, @@ -129,5 +130,3 @@ export default withEntitiesContainer('scanconfig', { entitiesSelector, loadEntities, })(ScanConfigsPage); - -// vim: set ts=2 sw=2 tw=80: diff --git a/src/web/pages/scanconfigs/table.jsx b/src/web/pages/scanconfigs/table.jsx index 8fc6ea2c70..41f2d3daec 100644 --- a/src/web/pages/scanconfigs/table.jsx +++ b/src/web/pages/scanconfigs/table.jsx @@ -13,29 +13,6 @@ import Header from './header'; import Row from './row'; import ScanConfigDetails from './details'; -export const SORT_FIELDS = [ - { - name: 'name', - displayName: _l('Name'), - }, - { - name: 'families_total', - displayName: _l('Families: Total'), - }, - { - name: 'families_trend', - displayName: _l('Families: Trend'), - }, - { - name: 'nvts_total', - displayName: _l('NVTs: Total'), - }, - { - name: 'nvts_trend', - displayName: _l('NVTs: Trend'), - }, -]; - const ScanConfigsTable = createEntitiesTable({ emptyTitle: _l('No Scan Configs available'), header: Header,