Skip to content

Commit

Permalink
Use useCapabilities hook in alert method parts
Browse files Browse the repository at this point in the history
Instead of using the withCapabilities HOC, the alert method parts now
use the useCapabilities hook.
  • Loading branch information
timopollmeier committed Jul 22, 2024
1 parent 8ad3e57 commit a9f6185
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 25 deletions.
9 changes: 4 additions & 5 deletions src/web/pages/alerts/emailmethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ import Divider from 'web/components/layout/divider';
import IconDivider from 'web/components/layout/icondivider';
import Layout from 'web/components/layout/layout';

import compose from 'web/utils/compose';
import useCapabilities from "web/hooks/useCapabilities";

import PropTypes from 'web/utils/proptypes';
import {renderSelectItems, UNSET_VALUE} from 'web/utils/render';
import withCapabilities from 'web/utils/withCapabilities';
import withPrefix from 'web/utils/withPrefix';

const EmailMethodPart = ({
capabilities,
credentials = [],
fromAddress,
event,
Expand All @@ -62,6 +61,7 @@ const EmailMethodPart = ({
onCredentialChange,
onNewCredentialClick,
}) => {
const capabilities = useCapabilities();

Check warning on line 64 in src/web/pages/alerts/emailmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/emailmethodpart.jsx#L64

Added line #L64 was not covered by tests
const taskEvent = isTaskEvent(event);
const secinfoEvent = isSecinfoEvent(event);
const textReportFormatItems = renderSelectItems(
Expand Down Expand Up @@ -295,7 +295,6 @@ const EmailMethodPart = ({

EmailMethodPart.propTypes = {
attachConfigItems: PropTypes.array,
capabilities: PropTypes.capabilities.isRequired,
credentials: PropTypes.array,
event: PropTypes.string.isRequired,
fromAddress: PropTypes.string.isRequired,
Expand All @@ -318,6 +317,6 @@ EmailMethodPart.propTypes = {
onNewCredentialClick: PropTypes.func,
};

export default compose(withCapabilities, withPrefix)(EmailMethodPart);
export default withPrefix(EmailMethodPart);

// vim: set ts=2 sw=2 tw=80:
8 changes: 3 additions & 5 deletions src/web/pages/alerts/scpmethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ import Layout from 'web/components/layout/layout';

import PropTypes from 'web/utils/proptypes';

import useCapabilities from "web/hooks/useCapabilities";
import {renderSelectItems, UNSET_VALUE} from '../../utils/render';
import compose from "web/utils/compose";
import withCapabilities from "web/utils/withCapabilities";
import withPrefix from 'web/utils/withPrefix';

import Select from 'web/components/form/select';
Expand All @@ -33,7 +32,6 @@ import NewIcon from 'web/components/icon/newicon';

const ScpMethodPart = ({
prefix,
capabilities,
credentials = [],
reportFormats,
reportConfigs,
Expand All @@ -48,6 +46,7 @@ const ScpMethodPart = ({
onCredentialChange,
onNewCredentialClick,
}) => {
const capabilities = useCapabilities();

Check warning on line 49 in src/web/pages/alerts/scpmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/scpmethodpart.jsx#L49

Added line #L49 was not covered by tests
const [reportFormatIdInState, setReportFormatId] = useState(
selectSaveId(reportFormats, scpReportFormat),
);
Expand Down Expand Up @@ -158,7 +157,6 @@ const ScpMethodPart = ({
};

ScpMethodPart.propTypes = {
capabilities: PropTypes.capabilities.isRequired,
credentials: PropTypes.array,
prefix: PropTypes.string,
reportConfigs: PropTypes.array,
Expand All @@ -175,6 +173,6 @@ ScpMethodPart.propTypes = {
onNewCredentialClick: PropTypes.func.isRequired,
};

export default compose(withCapabilities, withPrefix)(ScpMethodPart);
export default withPrefix(ScpMethodPart);

// vim: set ts=2 sw=2 tw=80:
8 changes: 3 additions & 5 deletions src/web/pages/alerts/sendmethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import _ from 'gmp/locale';
import Divider from 'web/components/layout/divider';
import Layout from 'web/components/layout/layout';

import useCapabilities from "web/hooks/useCapabilities";
import PropTypes from 'web/utils/proptypes';
import compose from "web/utils/compose";
import withCapabilities from "web/utils/withCapabilities";
import withPrefix from 'web/utils/withPrefix';

import Select from 'web/components/form/select';
Expand All @@ -23,7 +22,6 @@ import TextField from 'web/components/form/textfield';

const SendMethodPart = ({
prefix,
capabilities,
reportConfigs,
reportFormats,
sendHost,
Expand All @@ -32,6 +30,7 @@ const SendMethodPart = ({
sendReportFormat,
onChange,
}) => {
const capabilities = useCapabilities();

Check warning on line 33 in src/web/pages/alerts/sendmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/sendmethodpart.jsx#L33

Added line #L33 was not covered by tests
const [reportFormatIdInState, setReportFormatId] = useState(
selectSaveId(reportFormats, sendReportFormat),
);
Expand Down Expand Up @@ -101,7 +100,6 @@ const SendMethodPart = ({
};

SendMethodPart.propTypes = {
capabilities: PropTypes.capabilities.isRequired,
prefix: PropTypes.string,
reportConfigs: PropTypes.array,
reportFormats: PropTypes.array,
Expand All @@ -112,6 +110,6 @@ SendMethodPart.propTypes = {
onChange: PropTypes.func,
};

export default compose(withCapabilities, withPrefix)(SendMethodPart);
export default withPrefix(SendMethodPart);

// vim: set ts=2 sw=2 tw=80:
8 changes: 3 additions & 5 deletions src/web/pages/alerts/smbmethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ import Layout from 'web/components/layout/layout';

import PropTypes from 'web/utils/proptypes';

import useCapabilities from "web/hooks/useCapabilities";
import {renderSelectItems, UNSET_VALUE} from 'web/utils/render';
import compose from "web/utils/compose";
import withCapabilities from "web/utils/withCapabilities";
import withPrefix from 'web/utils/withPrefix';

import Select from 'web/components/form/select';
Expand All @@ -39,7 +38,6 @@ const smbMaxProtocolItems = [

const SmbMethodPart = ({
prefix,
capabilities,
credentials = [],
reportConfigs,
reportFormats,
Expand All @@ -53,6 +51,7 @@ const SmbMethodPart = ({
onNewCredentialClick,
onCredentialChange,
}) => {
const capabilities = useCapabilities();

Check warning on line 54 in src/web/pages/alerts/smbmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/smbmethodpart.jsx#L54

Added line #L54 was not covered by tests
const [reportFormatIdInState, setReportFormatId] = useState(
selectSaveId(reportFormats, smbReportFormat),
);
Expand Down Expand Up @@ -160,7 +159,6 @@ const SmbMethodPart = ({
};

SmbMethodPart.propTypes = {
capabilities: PropTypes.capabilities.isRequired,
credentials: PropTypes.array,
prefix: PropTypes.string,
reportConfigs: PropTypes.array,
Expand All @@ -176,6 +174,6 @@ SmbMethodPart.propTypes = {
onNewCredentialClick: PropTypes.func.isRequired,
};

export default compose(withCapabilities, withPrefix)(SmbMethodPart);
export default withPrefix(SmbMethodPart);

// vim: set ts=2 sw=2 tw=80:
8 changes: 3 additions & 5 deletions src/web/pages/alerts/verinicemethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import {USERNAME_PASSWORD_CREDENTIAL_TYPE} from 'gmp/models/credential';
import Divider from 'web/components/layout/divider';
import Layout from 'web/components/layout/layout';

import useCapabilities from "web/hooks/useCapabilities";
import PropTypes from 'web/utils/proptypes';
import {renderSelectItems, UNSET_VALUE} from '../../utils/render';
import compose from "web/utils/compose";
import withCapabilities from "web/utils/withCapabilities";
import withPrefix from 'web/utils/withPrefix';

import Select from 'web/components/form/select';
Expand All @@ -29,7 +28,6 @@ const VERINICE_CREDENTIAL_TYPES = [USERNAME_PASSWORD_CREDENTIAL_TYPE];

const VeriniceMethodPart = ({
prefix,
capabilities,
veriniceServerUrl,
veriniceServerCredential,
veriniceServerReportConfig,
Expand All @@ -41,6 +39,7 @@ const VeriniceMethodPart = ({
onCredentialChange,
onNewCredentialClick,
}) => {
const capabilities = useCapabilities();

Check warning on line 42 in src/web/pages/alerts/verinicemethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/verinicemethodpart.jsx#L42

Added line #L42 was not covered by tests
reportFormats = reportFormats.filter(format => format.extension === 'vna');
credentials = credentials.filter(
cred => cred.credential_type === USERNAME_PASSWORD_CREDENTIAL_TYPE,
Expand Down Expand Up @@ -124,7 +123,6 @@ const VeriniceMethodPart = ({
};

VeriniceMethodPart.propTypes = {
capabilities: PropTypes.capabilities,
credentials: PropTypes.array,
prefix: PropTypes.string,
reportConfigs: PropTypes.array,
Expand All @@ -138,6 +136,6 @@ VeriniceMethodPart.propTypes = {
onNewCredentialClick: PropTypes.func.isRequired,
};

export default compose(withCapabilities, withPrefix)(VeriniceMethodPart);
export default withPrefix(VeriniceMethodPart);

// vim: set ts=2 sw=2 tw=80:

0 comments on commit a9f6185

Please sign in to comment.