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

[RECHECK] EPMRPP-92499 || Incorrect behavior on get dashboards when not assigne… #3920

Open
wants to merge 3 commits into
base: feature/orgs
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions app/src/controllers/user/actionCreators.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
DELETE_USER_ACCOUNT,
SET_ACTIVE_PROJECT_KEY,
SET_LOG_TIME_FORMAT,
SET_NOT_ASSIGNED_PROJECT_KEY,
} from './constants';

export const fetchUserSuccessAction = (user) => ({
Expand Down Expand Up @@ -67,6 +68,11 @@ export const setActiveProjectKeyAction = (activeProjectKey) => ({
payload: activeProjectKey,
});

export const setNotAssignedProjectKeyAction = (notAssignedProjectKey) => ({
type: SET_NOT_ASSIGNED_PROJECT_KEY,
payload: notAssignedProjectKey,
});

export const addApiKeyAction = (name, successMessage, errorMessage, onSuccess) => ({
type: ADD_API_KEY,
payload: { name, successMessage, errorMessage, onSuccess },
Expand Down
1 change: 1 addition & 0 deletions app/src/controllers/user/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const FETCH_USER_ERROR = 'fetchUserError';
export const FETCH_USER_SUCCESS = 'fetchUserSuccess';
export const SET_ACTIVE_PROJECT = 'setActiveProject';
export const SET_ACTIVE_PROJECT_KEY = 'setActiveProjectKey';
export const SET_NOT_ASSIGNED_PROJECT_KEY = 'setNotAssignedProjectKey';
export const SET_START_TIME_FORMAT = 'setStartTimeFormat';
export const SET_LOG_TIME_FORMAT = 'setLogTimeFormat';
export const SET_PHOTO_TIME_STAMP = 'setPhotoTimeStamp';
Expand Down
2 changes: 2 additions & 0 deletions app/src/controllers/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export {
assignToProjectErrorAction,
assignToProjectSuccessAction,
unassignFromProjectAction,
setNotAssignedProjectKeyAction,
} from './actionCreators';
export { userReducer } from './reducer';
export {
Expand All @@ -60,5 +61,6 @@ export {
availableProjectsSelector,
activeProjectKeySelector,
assignedOrganizationsSelector,
notAssignedProjectKeySelector,
} from './selectors';
export { userSagas } from './sagas';
11 changes: 11 additions & 0 deletions app/src/controllers/user/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
DELETE_API_KEY_SUCCESS,
SET_ACTIVE_PROJECT_KEY,
SET_LOG_TIME_FORMAT,
SET_NOT_ASSIGNED_PROJECT_KEY,
} from './constants';

export const settingsReducer = (state = SETTINGS_INITIAL_STATE, { type = '', payload = {} }) => {
Expand All @@ -52,6 +53,15 @@ export const activeProjectKeyReducer = (state = '', { type, payload }) => {
}
};

export const notAssignedProjectKeyReducer = (state = '', { type, payload }) => {
switch (type) {
case SET_NOT_ASSIGNED_PROJECT_KEY:
return payload;
default:
return state;
}
};

export const activeProjectReducer = (state = '', { type = '', payload = {} }) => {
switch (type) {
case SET_ACTIVE_PROJECT:
Expand Down Expand Up @@ -123,6 +133,7 @@ export const userReducer = combineReducers({
info: userInfoReducer,
activeProject: activeProjectReducer,
activeProjectKey: activeProjectKeyReducer,
notAssignedProjectKey: notAssignedProjectKeyReducer,
settings: settingsReducer,
apiKeys: apiKeysReducer,
});
2 changes: 2 additions & 0 deletions app/src/controllers/user/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ export const availableProjectsSelector = createSelector(
export const apiKeysSelector = (state) => userSelector(state).apiKeys || [];

export const activeProjectKeySelector = (state) => userSelector(state).activeProjectKey;

export const notAssignedProjectKeySelector = (state) => userSelector(state).notAssignedProjectKey;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { ADMIN_PROJECTS_PAGE_EVENTS } from 'components/main/analytics/events';
import { SCREEN_XS_MAX_MEDIA } from 'common/constants/screenSizeVariables';
import { navigateToProjectAction } from 'controllers/organizations/projects';
import { setActiveProjectKeyAction } from 'controllers/user';
import { setNotAssignedProjectKeyAction } from 'controllers/user';
import { userAssignedSelector, PROJECT_PAGE } from 'controllers/pages';
import styles from './projectName.scss';

Expand All @@ -40,7 +40,7 @@ export const ProjectName = ({ project, disableAnalytics = false }) => {
return;
}

dispatch(setActiveProjectKeyAction(projectKey));
dispatch(setNotAssignedProjectKeyAction(projectKey));
dispatch(navigateToProjectAction({ project }));

if (!disableAnalytics) {
Expand Down
12 changes: 7 additions & 5 deletions app/src/routes/routesMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
userInfoSelector,
setActiveProjectAction,
setActiveProjectKeyAction,
activeProjectKeySelector,
notAssignedProjectKeySelector,
setNotAssignedProjectKeyAction,
} from 'controllers/user';
import { fetchProjectAction } from 'controllers/project';
import {
Expand Down Expand Up @@ -326,7 +327,7 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => {
} = action;

let { organizationSlug, projectSlug } = activeProjectSelector(getState());
const hashProjectKey = activeProjectKeySelector(getState());
const notAssignedProjectKey = notAssignedProjectKeySelector(getState());
const currentPageType = pageSelector(getState());
const authorized = isAuthorizedSelector(getState());
const userId = userInfoSelector(getState())?.userId;
Expand All @@ -341,13 +342,13 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => {
const isAdminNewPageType = !!adminPageNames[nextPageType];
const isAdminCurrentPageType = !!adminPageNames[currentPageType];

const projectKey = assignedProjectKey || (assignmentNotRequired && hashProjectKey);
const projectKey = assignedProjectKey || (assignmentNotRequired && notAssignedProjectKey);

const isChangedProject =
organizationSlug !== hashOrganizationSlug || projectSlug !== hashProjectSlug;

if (hashOrganizationSlug && (isChangedProject || isAdminCurrentPageType) && !isAdminNewPageType) {
if (hashProjectSlug && hasPermission) {
if (projectKey && hashProjectSlug && hasPermission) {
dispatch(
setActiveProjectAction({
organizationSlug: hashOrganizationSlug,
Expand All @@ -357,6 +358,7 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => {
dispatch(setActiveProjectKeyAction(projectKey));
dispatch(fetchProjectAction(projectKey));
dispatch(fetchOrganizationBySlugAction(hashOrganizationSlug));
dispatch(setNotAssignedProjectKeyAction(null));

organizationSlug = hashOrganizationSlug;
projectSlug = hashProjectSlug;
Expand All @@ -368,7 +370,7 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => {
dispatch(fetchOrganizationBySlugAction(hashOrganizationSlug));

organizationSlug = hashOrganizationSlug;
} else if (isChangedProject) {
} else if (isChangedProject || !projectKey) {
dispatch(
redirect({
...action,
Expand Down
Loading