Commit a3c7db1d authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'move_partial_result_to_error_event' into 'master'

Move the partial success condition out of the success transition

See merge request gitlab-org/gitlab!42768
parents 92bd5024 9ce53c97
...@@ -8,10 +8,11 @@ export const setEndpoints = ({ commit }, endpoints) => { ...@@ -8,10 +8,11 @@ export const setEndpoints = ({ commit }, endpoints) => {
commit(types.SET_ENDPOINT, endpoints.networkPoliciesEndpoint); commit(types.SET_ENDPOINT, endpoints.networkPoliciesEndpoint);
}; };
const commitReceivePoliciesError = (commit, payload) => { const commitReceivePoliciesError = (commit, data) => {
const error = const error =
payload?.error || s__('NetworkPolicies|Something went wrong, unable to fetch policies'); data?.error || s__('NetworkPolicies|Something went wrong, unable to fetch policies');
commit(types.RECEIVE_POLICIES_ERROR, error); const policies = data?.payload?.length ? data.payload : [];
commit(types.RECEIVE_POLICIES_ERROR, policies);
createFlash(error); createFlash(error);
}; };
...@@ -25,10 +26,8 @@ export const fetchPolicies = ({ state, commit }, environmentId) => { ...@@ -25,10 +26,8 @@ export const fetchPolicies = ({ state, commit }, environmentId) => {
return axios return axios
.get(state.policiesEndpoint, params) .get(state.policiesEndpoint, params)
.then(({ data }) => commit(types.RECEIVE_POLICIES_SUCCESS, data)) .then(({ data }) => commit(types.RECEIVE_POLICIES_SUCCESS, data))
.catch(({ response: { data } }) => { .catch(({ response }) => {
const payload = data?.payload?.length ? data.payload : []; commitReceivePoliciesError(commit, response?.data);
commit(types.RECEIVE_POLICIES_SUCCESS, payload);
commitReceivePoliciesError(commit, data);
}); });
}; };
......
import * as types from './mutation_types'; import * as types from './mutation_types';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
const setPolicies = (state, policies) => {
state.policies = policies.map(policy => convertObjectPropsToCamelCase(policy));
};
export default { export default {
[types.SET_ENDPOINT](state, endpoint) { [types.SET_ENDPOINT](state, endpoint) {
state.policiesEndpoint = endpoint; state.policiesEndpoint = endpoint;
...@@ -10,11 +14,12 @@ export default { ...@@ -10,11 +14,12 @@ export default {
state.errorLoadingPolicies = false; state.errorLoadingPolicies = false;
}, },
[types.RECEIVE_POLICIES_SUCCESS](state, policies) { [types.RECEIVE_POLICIES_SUCCESS](state, policies) {
state.policies = policies.map(policy => convertObjectPropsToCamelCase(policy)); setPolicies(state, policies);
state.isLoadingPolicies = false; state.isLoadingPolicies = false;
state.errorLoadingPolicies = false; state.errorLoadingPolicies = false;
}, },
[types.RECEIVE_POLICIES_ERROR](state) { [types.RECEIVE_POLICIES_ERROR](state, policies = []) {
setPolicies(state, policies);
state.isLoadingPolicies = false; state.isLoadingPolicies = false;
state.errorLoadingPolicies = true; state.errorLoadingPolicies = true;
}, },
......
...@@ -107,11 +107,7 @@ describe('Network Policy actions', () => { ...@@ -107,11 +107,7 @@ describe('Network Policy actions', () => {
actions.fetchPolicies, actions.fetchPolicies,
environmentId, environmentId,
state, state,
[ [{ type: types.REQUEST_POLICIES }, { type: types.RECEIVE_POLICIES_ERROR, payload: [] }],
{ type: types.REQUEST_POLICIES },
{ type: types.RECEIVE_POLICIES_SUCCESS, payload: [] },
{ type: types.RECEIVE_POLICIES_ERROR, payload: 'foo' },
],
[], [],
).then(() => { ).then(() => {
expect(createFlash).toHaveBeenCalled(); expect(createFlash).toHaveBeenCalled();
...@@ -132,8 +128,7 @@ describe('Network Policy actions', () => { ...@@ -132,8 +128,7 @@ describe('Network Policy actions', () => {
state, state,
[ [
{ type: types.REQUEST_POLICIES }, { type: types.REQUEST_POLICIES },
{ type: types.RECEIVE_POLICIES_SUCCESS, payload: [policy] }, { type: types.RECEIVE_POLICIES_ERROR, payload: [policy] },
{ type: types.RECEIVE_POLICIES_ERROR, payload: 'foo' },
], ],
[], [],
).then(() => { ).then(() => {
...@@ -155,7 +150,7 @@ describe('Network Policy actions', () => { ...@@ -155,7 +150,7 @@ describe('Network Policy actions', () => {
[ [
{ {
type: types.RECEIVE_POLICIES_ERROR, type: types.RECEIVE_POLICIES_ERROR,
payload: s__('NetworkPolicies|Something went wrong, unable to fetch policies'), payload: [],
}, },
], ],
[], [],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment