import { CREATE_LABEL, LIST_LABELS, REMOVE_LABEL, UPDATE_LABEL } from "../app/actionTypes";
import { insert, remove, update } from "../utils/reducers";

export const initialState = {
    documents: []
};

export default function labelsReducer(state = initialState, action) {
    switch (action.type) {
        case LIST_LABELS.SUCCEEDED:
            return { ...state, documents: action.data };

        case CREATE_LABEL.SUCCEEDED:
            return insert(state, action);

        case UPDATE_LABEL.SUCCEEDED:
            return update(state, action);

        case REMOVE_LABEL.SUCCEEDED:
            return remove(state, action);

        default:
            return state;
    }
}

import { CREATE_LABEL, LIST_LABELS, REMOVE_LABEL, UPDATE_LABEL } from "../app/actionTypes";
import { insert, remove, update } from "../utils/reducers";

export const initialState = {
    documents: null
};

export default function labelsReducer(state = initialState, action) {
    switch (action.type) {
        case LIST_LABELS.SUCCEEDED:
            return { ...state, documents: action.data };

        case CREATE_LABEL.SUCCEEDED:
            return insert(state, action);

        case UPDATE_LABEL.SUCCEEDED:
            return update(state, action);

        case REMOVE_LABEL.SUCCEEDED:
            return remove(state, action);

        default:
            return state;
    }
}

Use `null` as label documents initial state value
Use `null` as label documents initial state value

The initial redux state was `[]` which does not work with Virtool's loading convention where `null` means the resource hasn't been retrieved from the API yet.