Skip to content

Commit

Permalink
Refs #37395 - Moved error notifications to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
parthaa committed May 29, 2024
1 parent d01ac68 commit 1fab291
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ import {
Radio,
} from '@patternfly/react-core';
import { addToast } from '../../../ToastsList/slice';
import { actionTypeGenerator } from '../../../../redux/API/APIActionTypeGenerator';
import { translate as __ } from '../../../../common/I18n';
import { urlWithSearch } from '../../../../common/urlHelpers';

import { failedHostsToastParams } from '../helpers';
import { STATUS } from '../../../../constants';
import { selectAPIStatus } from '../../../../redux/API/APISelectors';
import { bulkBuildHosts, HOST_BUILD_KEY } from './actions';
import { foremanUrl } from '../../../../common/helpers';

const BulkBuildHostModal = ({
isOpen,
Expand All @@ -39,31 +36,12 @@ const BulkBuildHostModal = ({
closeModal();
};

const searchLink = ({ query, message, baseUrl }) => {
return {
children: message,
href: urlWithSearch(baseUrl, query),
};
};

const handleError = ({ response }) => {
handleModalClose();
const { FAILURE } = actionTypeGenerator(HOST_BUILD_KEY);
const data = response.data.error;
const query = `id ^ (${data.failed_host_ids.join(',')})`;
const hostsBaseUrl = foremanUrl('new/hosts');

dispatch(
addToast({
type: 'danger',
link: searchLink({
query,
message: __('Failed hosts'),
baseUrl: hostsBaseUrl,
}),
message: data.message,
key: FAILURE,
})
addToast(
failedHostsToastParams({ ...response.data.error, key: HOST_BUILD_KEY })
)
);
};
const handleSave = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { translate as __ } from '../../../../common/I18n';
import { APIActions } from '../../../../redux/API';
import { foremanUrl } from '../../../../common/helpers';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { actionTypeGenerator } from '../../../redux/API/APIActionTypeGenerator';
import { translate as __ } from '../../../common/I18n';
import { urlWithSearch } from '../../../common/urlHelpers';
import { foremanUrl } from '../../../common/helpers';

export const searchLink = ({ query, message, baseUrl }) => {

Check failure on line 6 in webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/helpers.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 14)

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`

Check failure on line 6 in webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/helpers.js

View workflow job for this annotation

GitHub Actions / test (13, 2.7, 18)

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`

Check failure on line 6 in webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/helpers.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 14)

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`

Check failure on line 6 in webpack/assets/javascripts/react_app/components/HostsIndex/BulkActions/helpers.js

View workflow job for this annotation

GitHub Actions / test (13, 3.0, 18)

Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`
return {
children: message,
href: urlWithSearch(baseUrl, query),
};
};

export const failedHostsToastParams = ({
message,
failed_host_ids: failedHostIds,
key,
}) => {
const { FAILURE } = actionTypeGenerator(key);
const toastParams = {
type: 'danger',
message,
key: FAILURE,
};
if (failedHostIds) {
const query = `id ^ (${failedHostIds.join(',')})`;
toastParams.link = searchLink({
query,
message: __('Failed hosts'),
baseUrl: foremanUrl('new/hosts'),
});
}

return toastParams;
};

0 comments on commit 1fab291

Please sign in to comment.