Skip to content

Commit

Permalink
refactor(redux): discovery-8 middleware, hooks, restructure (quipucor…
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcabrera committed Jun 23, 2022
1 parent a24543d commit 3db83c2
Show file tree
Hide file tree
Showing 21 changed files with 1,839 additions and 31 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"!src/**/.*/**",
"!src/components/app.js",
"!src/index.js",
"!src/setupTests.js",
"!src/components/app.js",
"!src/components/**/index.js",
"!src/common/index.js",
"!src/redux/index.js",
"!src/redux/store.js",
"!src/redux/middleware/**",
"!src/redux/actions/index.js",
"!src/redux/common/index.js",
"!src/redux/hooks/index.js",
"!src/redux/reducers/index.js",
"!src/redux/selectors/index.js"
],
Expand Down
1 change: 1 addition & 0 deletions src/common/__tests__/__snapshots__/helpers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Object {
"UI_SENTENCE_START_NAME": "The Quipucords tool",
"UI_SHORT_NAME": "Quipucords",
"UI_VERSION": "0.0.0.0000000",
"aggregatedError": [Function],
"copyClipboard": [Function],
"createViewQueryObject": [Function],
"devModeNormalizeCount": [Function],
Expand Down
25 changes: 25 additions & 0 deletions src/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ import moment from 'moment';
import _get from 'lodash/get';
import _set from 'lodash/set';

/**
* Fill for AggregatedError
*
* @param {Array|*} errors An array of errors
* @param {string|*} message
* @param {object} options
* @param {string} options.name
* @returns {Error|window.AggregateError<Error>}
*/
const aggregatedError = (errors, message, { name = 'AggregateError' } = {}) => {
const { AggregateError, Error } = window;
let err;

if (AggregateError) {
err = new AggregateError(errors, message);
} else {
err = new Error(message);
err.name = name;
err.errors = (Array.isArray(errors) && errors) || [errors];
err.isEmulated = true;
}
return err;
};

const copyClipboard = text => {
let successful;

Expand Down Expand Up @@ -315,6 +339,7 @@ const UI_SHORT_NAME = process.env.REACT_APP_UI_SHORT_NAME;
const UI_VERSION = process.env.REACT_APP_UI_VERSION;

const helpers = {
aggregatedError,
copyClipboard,
devModeNormalizeCount,
downloadData,
Expand Down
3 changes: 3 additions & 0 deletions src/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { helpers } from './helpers';

export { helpers as default, helpers };
2 changes: 1 addition & 1 deletion src/redux/actions/credentialsActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { credentialsTypes } from '../constants';
import credentialsService from '../../services/credentialsService';
import { credentialsService } from '../../services';

const addCredential = data => dispatch =>
dispatch({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/actions/factsActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { factsTypes } from '../constants';
import factsService from '../../services/factsService';
import { factsService } from '../../services';

const addFacts = data => dispatch =>
dispatch({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/actions/reportsActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { reportsTypes } from '../constants';
import reportsService from '../../services/reportsService';
import { reportsService } from '../../services';

const getReportsDownload = id => dispatch =>
dispatch({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/actions/scansActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { scansTypes } from '../constants';
import scansService from '../../services/scansService';
import { scansService } from '../../services';

const addScan = data => dispatch =>
dispatch({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/actions/sourcesActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { sourcesTypes } from '../constants';
import sourcesService from '../../services/sourcesService';
import { sourcesService } from '../../services';

const addSource =
(data, query = {}) =>
Expand Down
2 changes: 1 addition & 1 deletion src/redux/actions/statusActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { statusTypes } from '../constants';
import statusService from '../../services/statusService';
import { statusService } from '../../services';

const getStatus = () => dispatch =>
dispatch({
Expand Down
2 changes: 1 addition & 1 deletion src/redux/actions/userActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { userTypes } from '../constants';
import userService from '../../services/userService';
import { userService } from '../../services';

const authorizeUser = () => dispatch =>
dispatch({
Expand Down
3 changes: 3 additions & 0 deletions src/redux/common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { reduxHelpers } from './reduxHelpers';

export { reduxHelpers as default, reduxHelpers };
Loading

0 comments on commit 3db83c2

Please sign in to comment.