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

EPMRPP-90359 || Create redux store for organization #3822

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion app/src/common/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export const URLS = {
apiKeys: (userId) => `${urlCommonBase}users/${userId}/api-keys`,
apiKeyById: (userId, apiKeyId) => `${urlCommonBase}users/${userId}/api-keys/${apiKeyId}`,

organizationsList: () => `${urlBase}organizations`,
organizationList: (name) => `${urlBase}organizations${getQueryParams({ name })}`,
organizationById: (organizationId) => `${urlBase}organizations/${organizationId}`,

projectByName: (projectKey) => `${urlBase}project/${projectKey}`,
project: (ids = []) => `${urlBase}project?ids=${ids.join(',')}`,
Expand Down
26 changes: 26 additions & 0 deletions app/src/controllers/organizations/actionCreators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

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

export const fetchOrganizationsSuccessAction = (organizations) => ({
type: FETCH_ORGANIZATIONS_SUCCESS,
payload: organizations,
});
20 changes: 20 additions & 0 deletions app/src/controllers/organizations/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export const ORGANIZATIONS_INITIAL_STATE = {};

export const FETCH_ORGANIZATIONS = 'fetchOrganizations';
export const FETCH_ORGANIZATIONS_SUCCESS = 'fetchOrganizationsSuccess';
21 changes: 21 additions & 0 deletions app/src/controllers/organizations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export { FETCH_ORGANIZATIONS, FETCH_ORGANIZATIONS_SUCCESS } from './constants';
export { fetchOrganizationsAction, fetchOrganizationsSuccessAction } from './actionCreators';
export { organizationsReducer } from './reducer';
export { organizationsInfoSelector, organizationsInfoLoadingSelector } from './selectors';
export { organizationsSagas } from './sagas';
51 changes: 51 additions & 0 deletions app/src/controllers/organizations/reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { combineReducers } from 'redux';
import {} from 'controllers/filter/constants';
AmsterGet marked this conversation as resolved.
Show resolved Hide resolved
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;
}
};

export const organizationsReducer = combineReducers({
info: organizationsInfoReducer,
AmsterGet marked this conversation as resolved.
Show resolved Hide resolved
infoLoading: organizationsLoadingReducer,
});
38 changes: 38 additions & 0 deletions app/src/controllers/organizations/sagas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

function* fetchOrganizations() {
try {
const organizations = yield call(fetch, URLS.organizationList());
yield put(fetchOrganizationsSuccessAction(organizations?.content || []));
} catch (error) {
yield put(showDefaultErrorNotification(error));
}
}

function* watchFetchOrganizations() {
yield takeEvery(FETCH_ORGANIZATIONS, fetchOrganizations);
}

export function* organizationsSagas() {
yield all([watchFetchOrganizations()]);
}
21 changes: 21 additions & 0 deletions app/src/controllers/organizations/selectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

export const organizationsInfoSelector = (state) => organizationsSelector(state).info || {};

export const organizationsInfoLoadingSelector = (state) => organizationsSelector(state).infoLoading;
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames/bind';
import { connect } from 'react-redux';
import { URLS } from 'common/urls';
import { fetch } from 'common/utils';
import { loadingSelector, projectsSelector } from 'controllers/administrate/projects';
import { organizationsInfoSelector } 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),
projects: projectsSelector(state),
loading: loadingSelector(state),
}))
export class ProjectsPanelView extends Component {
static propTypes = {
organizations: PropTypes.array,
projects: PropTypes.array,
loading: PropTypes.bool,
onMembers: PropTypes.func,
Expand All @@ -43,6 +44,7 @@ export class ProjectsPanelView extends Component {
};

static defaultProps = {
organizations: [],
projects: [],
loading: false,
onMembers: () => {},
Expand All @@ -52,21 +54,8 @@ export class ProjectsPanelView extends Component {
onDelete: () => {},
};

// TODO: The request for organizations is made together with the request for all projects.
// Create a store for organizations and drop a selector here that returns organizations.
constructor(props) {
super(props);
this.state = {
organizations: [],
};

fetch(URLS.organizationsList()).then((response) => {
this.setState({ organizations: response?.content || [] });
});
}

getPanelList = (projects) => {
const { organizations } = this.state;
const { organizations } = this.props;

return projects.map((project) => {
const { organizationId } = project;
Expand Down
2 changes: 2 additions & 0 deletions app/src/routes/routesMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import { fetchAllUsersAction } from 'controllers/administrate/allUsers/actionCre
import { fetchLogPageData } from 'controllers/log';
import { fetchHistoryPageInfoAction } from 'controllers/itemsHistory';
import { fetchProjectsAction } from 'controllers/administrate/projects';
import { fetchOrganizationsAction } from 'controllers/organizations';
import { startSetViewMode } from 'controllers/administrate/projects/actionCreators';
import { SIZE_KEY } from 'controllers/pagination';
import { setSessionItem, updateStorageItem } from 'common/utils/storageUtils';
Expand Down Expand Up @@ -127,6 +128,7 @@ const routesMap = {
path: '/administrate/projects',
thunk: (dispatch) => {
dispatch(fetchProjectsAction());
dispatch(fetchOrganizationsAction());
dispatch(startSetViewMode());
},
},
Expand Down
2 changes: 2 additions & 0 deletions app/src/store/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { administrateReducer } from 'controllers/administrate';
import { pluginsReducer } from 'controllers/plugins';
import { initialDataReadyReducer } from 'controllers/initialData';
import { uniqueErrorsReducer } from 'controllers/uniqueErrors';
import { organizationsReducer } from 'controllers/organizations';

export default {
appInfo: appInfoReducer,
Expand All @@ -45,6 +46,7 @@ export default {
form: formReducer,
modal: modalReducer,
user: userReducer,
organizations: organizationsReducer,
project: projectReducer,
notifications: notificationReducer,
screenLock: screenLockReducer,
Expand Down
2 changes: 2 additions & 0 deletions app/src/store/rootSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { historySagas } from 'controllers/itemsHistory';
import { logSagas } from 'controllers/log';
import { administrateSagas } from 'controllers/administrate';
import { userSagas } from 'controllers/user';
import { organizationsSagas } from 'controllers/organizations';
import { projectSagas } from 'controllers/project';
import { initialDataSagas } from 'controllers/initialData';
import { pageSagas } from 'controllers/pages';
Expand All @@ -52,6 +53,7 @@ const sagas = [
historySagas,
administrateSagas,
userSagas,
organizationsSagas,
projectSagas,
initialDataSagas,
pageSagas,
Expand Down
Loading