Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
remove result configs when update result status to unregistered
Browse files Browse the repository at this point in the history
  • Loading branch information
makky3939 committed Dec 3, 2019
1 parent e2d92cf commit 2629480
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 675 deletions.
18 changes: 1 addition & 17 deletions frontend/src/actions/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ export const RESULT_FAILURE = 'RESULT_FAILURE';
export const RESULT_UPDATE_REQUEST = 'RESULT_UPDATE_REQUEST';
export const RESULT_UPDATE_SUCCESS = 'RESULT_UPDATE_SUCCESS';
export const RESULT_UPDATE_FAILURE = 'RESULT_UPDATE_FAILURE';
export const RESULT_DELETE_REQUEST = 'RESULT_DELETE_REQUEST';
export const RESULT_DELETE_SUCCESS = 'RESULT_DELETE_SUCCESS';
export const RESULT_DELETE_FAILURE = 'RESULT_DELETE_FAILURE';
export const RESULTS_PATCH_REQUEST = 'RESULTS_PATCH_REQUEST';
export const RESULTS_PATCH_SUCCESS = 'RESULTS_PATCH_SUCCESS';
export const RESULTS_PATCH_FAILURE = 'RESULTS_PATCH_FAILURE';
Expand Down Expand Up @@ -113,26 +110,13 @@ export const updateResult = (projectId, result = {}) => {
};
};

export const deleteResult = (projectId, resultId) => {
if (!Number.isInteger(resultId)) {
throw new Error('Result id is invalid.');
}
return {
[CALL_API]: {
types: [RESULT_DELETE_REQUEST, RESULT_DELETE_SUCCESS, RESULT_DELETE_FAILURE],
endpoint: `projects/${projectId}/results/${resultId}`,
method: 'DELETE',
},
};
};

export const patchResults = (projectId, results = []) => {
return {
[CALL_API]: {
types: [RESULTS_PATCH_REQUEST, RESULTS_PATCH_SUCCESS, RESULTS_PATCH_FAILURE],
endpoint: `projects/${projectId}/results`,
method: 'PATCH',
body: { results },
body: { projectId, results },
},
};
};
Expand Down
31 changes: 22 additions & 9 deletions frontend/src/reducers/configReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
GLOBAL_CONFIG_RESULT_NAME_ALIGNMENT_UPDATE,
GLOBAL_CONFIG_HIGHLIGHT_TABLE_AND_CHART,
} from '../actions/config';
import { RESULT_UPDATE_SUCCESS, RESULT_DELETE_SUCCESS } from '../actions/entities';
import { RESULT_UPDATE_SUCCESS, RESULTS_PATCH_SUCCESS } from '../actions/entities';
import { updatePartialState, removePartialState } from './utils';

const axisConfigReducer = (state = {}, action) => {
Expand Down Expand Up @@ -113,7 +113,7 @@ const axesConfigReducer = (state = defaultAxisConfig, action) => {
};

const resultsConfigReducer = (state = {}, action) => {
const { resultId } = action;
const { resultId, response } = action;
switch (action.type) {
case RESULTS_CONFIG_SELECT_UPDATE:
if (resultId) {
Expand Down Expand Up @@ -153,8 +153,18 @@ const resultsConfigReducer = (state = {}, action) => {
};
}
return state;
case RESULT_DELETE_SUCCESS:
return removePartialState(state, resultId);
case RESULTS_PATCH_SUCCESS:
if (response.results) {
let tmpState = state;
const targetResult = response.results.filter(
(result) => result.is_unregistered && result.is_unregistered === true
);
targetResult.forEach((result) => {
tmpState = removePartialState(tmpState, result.id);
});
return tmpState;
}
return state;
default:
return state;
}
Expand Down Expand Up @@ -229,18 +239,21 @@ const projectConfigReducer = combineReducers({
});

const projectsConfigReducer = (state = {}, action) => {
const { projectId } = action;
if (projectId) {
const { projectId: projectIdA, body = {} } = action;
const { projectId: projectIdB } = body;
const targetProjectId = projectIdA || projectIdB;
if (targetProjectId) {
switch (action.type) {
case PROJECT_CONFIG_RESET:
return updatePartialState(state, action, projectId, () =>
return updatePartialState(state, action, targetProjectId, () =>
projectConfigReducer(undefined, action)
);
case RESULTS_PATCH_SUCCESS:
return updatePartialState(state, action, targetProjectId, projectConfigReducer);
default:
return updatePartialState(state, action, projectId, projectConfigReducer);
return updatePartialState(state, action, targetProjectId, projectConfigReducer);
}
}

return state;
};

Expand Down
7 changes: 0 additions & 7 deletions frontend/src/reducers/entitiesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
RESULT_LIST_SUCCESS,
RESULT_SUCCESS,
RESULT_UPDATE_SUCCESS,
RESULT_DELETE_SUCCESS,
RESULTS_PATCH_SUCCESS,
COMMAND_CREATE_SUCCESS,
RESULT_LIST_CLEAR,
Expand Down Expand Up @@ -104,12 +103,6 @@ const resultsReducer = (state = {}, action) => {
};
}
return state;
case RESULT_DELETE_SUCCESS:
if (action.response && action.response.result) {
const { result } = action.response;
return removePartialState(state, result.id);
}
return state;
case RESULTS_PATCH_SUCCESS:
if (action.response && action.response.results) {
const { results } = action.response;
Expand Down
Loading

0 comments on commit 2629480

Please sign in to comment.