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/epmrpp 91791 wrong organizations page is displayed #3904

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
* limitations under the License.
*/

import { FETCH_ORGANIZATION_BY_SLUG, PREPARE_ACTIVE_ORGANIZATION_PROJECTS } from './constants';
import {
FETCH_ORGANIZATION_BY_SLUG,
PREPARE_ACTIVE_ORGANIZATION_PROJECTS,
SET_ACTIVE_ORGANIZATION,
} from './constants';

export const prepareActiveOrganizationProjectsAction = (payload) => ({
type: PREPARE_ACTIVE_ORGANIZATION_PROJECTS,
Expand All @@ -25,3 +29,8 @@ export const fetchOrganizationBySlugAction = (payload) => ({
type: FETCH_ORGANIZATION_BY_SLUG,
payload,
});

export const setActiveOrganizationAction = (payload) => ({
type: SET_ACTIVE_ORGANIZATION,
payload,
});
2 changes: 2 additions & 0 deletions app/src/controllers/organizations/organization/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export const PROJECTS_NAMESPACE = 'projects';
export const PREPARE_ACTIVE_ORGANIZATION_PROJECTS = 'prepareActiveOrganizationProjects';

export const FETCH_ORGANIZATION_BY_SLUG = 'fetchOrganizationBySlug';

export const SET_ACTIVE_ORGANIZATION = 'setActiveOrganization';
1 change: 1 addition & 0 deletions app/src/controllers/organizations/organization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
export {
prepareActiveOrganizationProjectsAction,
fetchOrganizationBySlugAction,
setActiveOrganizationAction,
} from './actionCreators';
export { organizationReducer } from './reducer';
export { activeOrganizationSelector } from './selectors';
Expand Down
25 changes: 19 additions & 6 deletions app/src/controllers/organizations/organization/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,28 @@
import { combineReducers } from 'redux';
import { fetchReducer } from 'controllers/fetch';
import { loadingReducer } from 'controllers/loading';
import { queueReducers } from 'common/utils';
import { projectsReducer } from '../projects/reducer';
import { FETCH_ORGANIZATION_BY_SLUG } from './constants';
import { FETCH_ORGANIZATION_BY_SLUG, SET_ACTIVE_ORGANIZATION } from './constants';

const setActiveOrganizationReducer = (state = [], { type = '', payload = {} }) => {
switch (type) {
case SET_ACTIVE_ORGANIZATION:
return payload;
default:
return state;
}
};

export const organizationReducer = combineReducers({
activeOrganization: fetchReducer(FETCH_ORGANIZATION_BY_SLUG, {
contentPath: 'items',
getFirst: true,
initialState: null,
}),
activeOrganization: queueReducers(
fetchReducer(FETCH_ORGANIZATION_BY_SLUG, {
contentPath: 'items',
getFirst: true,
initialState: null,
}),
setActiveOrganizationReducer,
),
organizationLoading: loadingReducer(FETCH_ORGANIZATION_BY_SLUG),
projects: projectsReducer,
});
15 changes: 12 additions & 3 deletions app/src/controllers/user/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { PROJECT_MANAGER } from 'common/constants/projectRoles';
import { getStorageItem, setStorageItem } from 'common/utils/storageUtils';
import { urlOrganizationAndProjectSelector } from 'controllers/pages';
import { getLogTimeFormatFromStorage } from 'controllers/log/storageUtils';
import { setActiveOrganizationAction } from 'controllers/organizations/organization/actionCreators';
import {
assignToProjectSuccessAction,
assignToProjectErrorAction,
Expand Down Expand Up @@ -158,15 +159,23 @@ function* fetchUserWorker() {

if (!isAssignedToTargetProject && assignmentNotRequired) {
try {
const activeOrganization = yield call(
const activeOrganizationResponse = yield call(
fetch,
URLS.organizationList({ slug: targetOrganizationSlug }),
);
const id = activeOrganization?.items?.[0]?.id;

const activeOrganization = activeOrganizationResponse?.items?.[0];

// TODO: Fetch project by slug
const organizationProjects = yield call(fetch, URLS.organizationProjects(id));
const organizationProjects = yield call(
fetch,
URLS.organizationProjects(activeOrganization?.id),
);
projectKey = organizationProjects?.items?.find(({ slug }) => slug === targetProjectSlug)?.key;

if (activeOrganization) {
yield put(setActiveOrganizationAction(activeOrganization));
}
} catch (e) {} // eslint-disable-line no-empty
}

Expand Down
Loading