Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import of dispatchAPICallbackToast helper #42

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions webpack/api_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,17 @@ const apiUpdateResourceQuota = (

/**
* Handles the callback response from an asynchronous operation, displaying a toast message accordingly.
* @param {function} dispatcher - The dispatcher function to dispatch actions.
* @param {boolean} isSuccess - Indicates whether the operation was successful or not.
* @param {object} response - The response object returned from the operation.
* @param {string} successMessage - The success message to display in case of success.
* @param {string} errorMessage - The error message to display in case of failure.
*/
const dispatchAPICallbackToast = (
dispatch,
isSuccess,
response,
successMessage,
errorMessage
) => {
) => dispatch => {
if (isSuccess) {
dispatch(
addToast({
Expand Down
12 changes: 6 additions & 6 deletions webpack/api_helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ describe('dispatchAPICallbackToast', () => {
const successMessage = 'Success message';
const errorMessage = 'Error message';

dispatchAPICallbackToast(
dispatch,
const dispatcher = dispatchAPICallbackToast(
isSuccess,
response,
successMessage,
errorMessage
);
dispatcher(dispatch);

expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({
Expand All @@ -50,13 +50,13 @@ describe('dispatchAPICallbackToast', () => {
const successMessage = 'Success message';
const errorMessage = 'Error message';

dispatchAPICallbackToast(
dispatch,
const dispatcher = dispatchAPICallbackToast(
isSuccess,
response,
successMessage,
errorMessage
);
dispatcher(dispatch);

expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({
Expand All @@ -79,13 +79,13 @@ describe('dispatchAPICallbackToast', () => {
const successMessage = 'Success message';
const errorMessage = 'Error message';

dispatchAPICallbackToast(
dispatch,
const dispatcher = dispatchAPICallbackToast(
isSuccess,
response,
successMessage,
errorMessage
);
dispatcher(dispatch);

expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { translate as __ } from 'foremanReact/common/I18n';

import ActionableDetail from '../../../../lib/ActionableDetail';
import StaticDetail from './StaticDetail';
import dispatchAPICallbackToast from '../../../../api_helper';
import { dispatchAPICallbackToast } from '../../../../api_helper';

const TextInputField = ({
initialValue,
Expand Down Expand Up @@ -36,12 +36,13 @@ const TextInputField = ({

const callback = (success, response) => {
setIsLoading(false);
dispatchAPICallbackToast(
dispatch,
success,
response,
`Sucessfully applied ${label}.`,
`An error occurred appyling ${label}.`
dispatch(
dispatchAPICallbackToast(
success,
response,
`Sucessfully applied ${label}.`,
`An error occurred appyling ${label}.`
)
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import ClusterIcon from '@patternfly/react-icons/dist/esm/icons/cluster-icon';
import SyncAltIcon from '@patternfly/react-icons/dist/esm/icons/sync-alt-icon';

import { translate as __ } from 'foremanReact/common/I18n';
import dispatchAPICallbackToast from '../../../../api_helper';
import { dispatchAPICallbackToast } from '../../../../api_helper';

import './Properties.scss';
import StatusPropertiesLabel from './StatusPropertiesLabel';
Expand Down Expand Up @@ -58,12 +58,13 @@ const Properties = ({

const callbackFetch = (success, response) => {
setIsFetchLoading(false);
dispatchAPICallbackToast(
dispatch,
success,
response,
`Sucessfully fetched latest data.`,
`An error occurred fetching quota information.`
dispatch(
dispatchAPICallbackToast(
success,
response,
`Sucessfully fetched latest data.`,
`An error occurred fetching quota information.`
)
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import UnitInputField from './UnitInputField';
import UtilizationProgress from './UtilizationProgress';

import { resourceAttributesByIdentifier } from '../../ResourceQuotaFormConstants';
import dispatchAPICallbackToast from '../../../../api_helper';
import { dispatchAPICallbackToast } from '../../../../api_helper';

// TODO: Visualize maximum resource (tooltip?)
// TODO: Add error message if given quota limit exceeds present quota utilization (consumed resources)
Expand Down Expand Up @@ -70,12 +70,13 @@ const Resource = ({
setInputValue(response.data[resourceIdentifier]);
setIsEnabled(response.data[resourceIdentifier] !== null);
}
dispatchAPICallbackToast(
dispatch,
success,
response,
`Sucessfully applied ${resourceTitle}.`,
`An error occurred appyling ${resourceTitle}.`
dispatch(
dispatchAPICallbackToast(
success,
response,
`Sucessfully applied ${resourceTitle}.`,
`An error occurred appyling ${resourceTitle}.`
)
);
};

Expand Down
15 changes: 8 additions & 7 deletions webpack/components/ResourceQuotaForm/components/Submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button, Flex, FlexItem } from '@patternfly/react-core';

import { translate as __ } from 'foremanReact/common/I18n';

import dispatchAPICallbackToast from '../../../api_helper';
import { dispatchAPICallbackToast } from '../../../api_helper';

import {
RESOURCE_IDENTIFIER_ID,
Expand All @@ -27,12 +27,13 @@ const Submit = ({ isValid, onCreate, onSubmit }) => {

const onCreateCallback = (success, response) => {
setIsSubmitLoading(false);
dispatchAPICallbackToast(
dispatch,
success,
response,
`Sucessfully created new Resource Quota`,
`An error occurred while creating new Resource Quota.`
dispatch(
dispatchAPICallbackToast(
success,
response,
`Sucessfully created new Resource Quota`,
`An error occurred while creating new Resource Quota.`
)
);
if (onSubmit) onSubmit(success);
};
Expand Down
Loading