Skip to content

Commit

Permalink
EPMRPP-90359 || Code Review fix - 1
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazarQSO committed May 15, 2024
1 parent a5bac6e commit 619c5f0
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 51 deletions.
7 changes: 1 addition & 6 deletions app/src/controllers/organizations/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@
* limitations under the License.
*/

import { FETCH_ORGANIZATIONS, FETCH_ORGANIZATIONS_SUCCESS } from './constants';
import { FETCH_ORGANIZATIONS } from './constants';

export const fetchOrganizationsAction = () => ({
type: FETCH_ORGANIZATIONS,
});

export const fetchOrganizationsSuccessAction = (organizations) => ({
type: FETCH_ORGANIZATIONS_SUCCESS,
payload: organizations,
});
3 changes: 1 addition & 2 deletions app/src/controllers/organizations/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

export const ORGANIZATIONS_INITIAL_STATE = {};
export const NAMESPACE = 'organizations';

export const FETCH_ORGANIZATIONS = 'fetchOrganizations';
export const FETCH_ORGANIZATIONS_SUCCESS = 'fetchOrganizationsSuccess';
6 changes: 3 additions & 3 deletions app/src/controllers/organizations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

export { FETCH_ORGANIZATIONS, FETCH_ORGANIZATIONS_SUCCESS } from './constants';
export { fetchOrganizationsAction, fetchOrganizationsSuccessAction } from './actionCreators';
export { FETCH_ORGANIZATIONS } from './constants';
export { fetchOrganizationsAction } from './actionCreators';
export { organizationsReducer } from './reducer';
export { organizationsInfoSelector, organizationsInfoLoadingSelector } from './selectors';
export { organizationsListSelector, organizationsListLoadingSelector } from './selectors';
export { organizationsSagas } from './sagas';
36 changes: 5 additions & 31 deletions app/src/controllers/organizations/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,11 @@
*/

import { combineReducers } from 'redux';
import {} from 'controllers/filter/constants';
import {
ORGANIZATIONS_INITIAL_STATE,
FETCH_ORGANIZATIONS_SUCCESS,
FETCH_ORGANIZATIONS,
} from './constants';

export const organizationsInfoReducer = (
state = ORGANIZATIONS_INITIAL_STATE,
{ type = '', payload = {} },
) => {
switch (type) {
case FETCH_ORGANIZATIONS_SUCCESS:
return { ...state, ...payload };
default:
return state;
}
};

export const organizationsLoadingReducer = (state = false, { type = '' }) => {
switch (type) {
case FETCH_ORGANIZATIONS:
return true;
case FETCH_ORGANIZATIONS_SUCCESS:
return false;
default:
return state;
}
};
import { fetchReducer } from 'controllers/fetch';
import { loadingReducer } from 'controllers/loading';
import { NAMESPACE } from './constants';

export const organizationsReducer = combineReducers({
info: organizationsInfoReducer,
infoLoading: organizationsLoadingReducer,
list: fetchReducer(NAMESPACE, { contentPath: 'content' }),
listLoading: loadingReducer(NAMESPACE),
});
9 changes: 4 additions & 5 deletions app/src/controllers/organizations/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
* limitations under the License.
*/

import { takeEvery, all, put, call } from 'redux-saga/effects';
import { takeEvery, all, put } from 'redux-saga/effects';
import { URLS } from 'common/urls';
import { showDefaultErrorNotification } from 'controllers/notification';
import { FETCH_ORGANIZATIONS } from './constants';
import { fetchOrganizationsSuccessAction } from './actionCreators';
import { fetchDataAction } from 'controllers/fetch';
import { FETCH_ORGANIZATIONS, NAMESPACE } from './constants';

function* fetchOrganizations() {
try {
const organizations = yield call(fetch, URLS.organizationList());
yield put(fetchOrganizationsSuccessAction(organizations?.content || []));
yield put(fetchDataAction(NAMESPACE)(URLS.organizationList()));
} catch (error) {
yield put(showDefaultErrorNotification(error));
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/controllers/organizations/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

const organizationsSelector = (state) => state.organizations || {};

export const organizationsInfoSelector = (state) => organizationsSelector(state).info || {};
export const organizationsListSelector = (state) => organizationsSelector(state).list || [];

export const organizationsInfoLoadingSelector = (state) => organizationsSelector(state).infoLoading;
export const organizationsListLoadingSelector = (state) => organizationsSelector(state).listLoading;
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import PropTypes from 'prop-types';
import classNames from 'classnames/bind';
import { connect } from 'react-redux';
import { loadingSelector, projectsSelector } from 'controllers/administrate/projects';
import { organizationsInfoSelector } from 'controllers/organizations';
import { organizationsListSelector } from 'controllers/organizations';
import { SpinningPreloader } from 'components/preloaders/spinningPreloader';
import { ProjectPanel } from './projectPanel';
import styles from './projectsPanelView.scss';

const cx = classNames.bind(styles);

@connect((state) => ({
organizations: organizationsInfoSelector(state),
organizations: organizationsListSelector(state),
projects: projectsSelector(state),
loading: loadingSelector(state),
}))
Expand Down

0 comments on commit 619c5f0

Please sign in to comment.