Skip to content

Commit

Permalink
EPMRPP-92499 || Incorrect behavior on get dashboards when not assigne…
Browse files Browse the repository at this point in the history
…d Admin or Manager opens a project by URL
  • Loading branch information
BlazarQSO committed Jul 16, 2024
1 parent edf5274 commit d837db6
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 7 deletions.
4 changes: 4 additions & 0 deletions app/src/controllers/dashboard/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ import {

function* fetchDashboards({ payload: params }) {
const projectKey = yield select(activeProjectKeySelector);
if (!projectKey) {
return;
}

const query = yield select(querySelector);

yield put(
Expand Down
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,
});
13 changes: 13 additions & 0 deletions app/src/controllers/user/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { getStorageItem, setStorageItem } from 'common/utils/storageUtils';
import { userAssignedSelector, urlOrganizationAndProjectSelector } from 'controllers/pages';
import { getLogTimeFormatFromStorage } from 'controllers/log/storageUtils';
import { setActiveOrganizationAction } from 'controllers/organizations/organization/actionCreators';
import { fetchDashboardsAction } from 'controllers/dashboard';
import { SIZE_KEY } from 'controllers/pagination';
import { fetchProjectAction } from 'controllers/project';
import {
assignToProjectSuccessAction,
assignToProjectErrorAction,
Expand Down Expand Up @@ -191,6 +194,16 @@ function* fetchUserWorker() {

yield put(setActiveProjectAction(activeProject));
yield put(setActiveProjectKeyAction(projectKey));

if (!isAssignedToTargetProject && assignmentNotRequired) {
yield put(
fetchDashboardsAction({
[SIZE_KEY]: 300,
}),
);
yield put(fetchProjectAction(projectKey));
}

yield put(setActiveOrganizationAction(activeOrganization));
const format = getLogTimeFormatFromStorage(user.userId);
yield put(setLogTimeFormatAction(format));
Expand Down
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
18 changes: 13 additions & 5 deletions app/src/routes/routesMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
userInfoSelector,
setActiveProjectAction,
setActiveProjectKeyAction,
activeProjectKeySelector,
notAssignedProjectKeySelector,
setNotAssignedProjectKeyAction,
fetchUserAction,
} from 'controllers/user';
import { fetchProjectAction } from 'controllers/project';
import {
Expand Down Expand Up @@ -319,14 +321,14 @@ const routesMap = {
[PROJECT_PLUGIN_PAGE]: '/:projectId/plugin/:pluginPage/:pluginRoute*',
};

export const onBeforeRouteChange = (dispatch, getState, { action }) => {
export const onBeforeRouteChange = async (dispatch, getState, { action }) => {
const {
type: nextPageType,
payload: { organizationSlug: hashOrganizationSlug, projectSlug: hashProjectSlug },
} = 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 +343,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,7 +359,13 @@ export const onBeforeRouteChange = (dispatch, getState, { action }) => {
dispatch(setActiveProjectKeyAction(projectKey));
dispatch(fetchProjectAction(projectKey));
dispatch(fetchOrganizationBySlugAction(hashOrganizationSlug));
dispatch(setNotAssignedProjectKeyAction(null));

organizationSlug = hashOrganizationSlug;
projectSlug = hashProjectSlug;
} else if (!projectKey) {
await dispatch(setActiveProjectKeyAction(null));
dispatch(fetchUserAction());
organizationSlug = hashOrganizationSlug;
projectSlug = hashProjectSlug;
} else if (
Expand Down

0 comments on commit d837db6

Please sign in to comment.