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) => {
commit(types.SET_ENDPOINT, endpoints.networkPoliciesEndpoint);
};
const commitReceivePoliciesError = (commit, payload) => {
const commitReceivePoliciesError = (commit, data) => {
const error =
payload?.error || s__('NetworkPolicies|Something went wrong, unable to fetch policies');
commit(types.RECEIVE_POLICIES_ERROR, error);
data?.error || s__('NetworkPolicies|Something went wrong, unable to fetch policies');
const policies = data?.payload?.length ? data.payload : [];
commit(types.RECEIVE_POLICIES_ERROR, policies);
createFlash(error);
};
......@@ -25,10 +26,8 @@ export const fetchPolicies = ({ state, commit }, environmentId) => {
return axios
.get(state.policiesEndpoint, params)
.then(({ data }) => commit(types.RECEIVE_POLICIES_SUCCESS, data))
.catch(({ response: { data } }) => {
const payload = data?.payload?.length ? data.payload : [];
commit(types.RECEIVE_POLICIES_SUCCESS, payload);
commitReceivePoliciesError(commit, data);
.catch(({ response }) => {
commitReceivePoliciesError(commit, response?.data);
});
};
......
import * as types from './mutation_types';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
const setPolicies = (state, policies) => {
state.policies = policies.map(policy => convertObjectPropsToCamelCase(policy));
};
export default {
[types.SET_ENDPOINT](state, endpoint) {
state.policiesEndpoint = endpoint;
......@@ -10,11 +14,12 @@ export default {
state.errorLoadingPolicies = false;
},
[types.RECEIVE_POLICIES_SUCCESS](state, policies) {
state.policies = policies.map(policy => convertObjectPropsToCamelCase(policy));
setPolicies(state, policies);
state.isLoadingPolicies = false;
state.errorLoadingPolicies = false;
},
[types.RECEIVE_POLICIES_ERROR](state) {
[types.RECEIVE_POLICIES_ERROR](state, policies = []) {
setPolicies(state, policies);
state.isLoadingPolicies = false;
state.errorLoadingPolicies = true;
},
......
......@@ -107,11 +107,7 @@ describe('Network Policy actions', () => {
actions.fetchPolicies,
environmentId,
state,
[
{ type: types.REQUEST_POLICIES },
{ type: types.RECEIVE_POLICIES_SUCCESS, payload: [] },
{ type: types.RECEIVE_POLICIES_ERROR, payload: 'foo' },
],
[{ type: types.REQUEST_POLICIES }, { type: types.RECEIVE_POLICIES_ERROR, payload: [] }],
[],
).then(() => {
expect(createFlash).toHaveBeenCalled();
......@@ -132,8 +128,7 @@ describe('Network Policy actions', () => {
state,
[
{ type: types.REQUEST_POLICIES },
{ type: types.RECEIVE_POLICIES_SUCCESS, payload: [policy] },
{ type: types.RECEIVE_POLICIES_ERROR, payload: 'foo' },
{ type: types.RECEIVE_POLICIES_ERROR, payload: [policy] },
],
[],
).then(() => {
......@@ -155,7 +150,7 @@ describe('Network Policy actions', () => {
[
{
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