fix deleting host breaking host table (#423)

This commit is contained in:
Gabe Hernandez 2021-03-09 15:38:37 +00:00 committed by GitHub
parent 54c2b0b8df
commit e38a020050
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 3 deletions

View file

@ -1,5 +1,5 @@
import BaseConfig from 'redux/nodes/entities/base/base_config';
import { entitiesExceptID } from 'redux/nodes/entities/base/helpers';
import { entitiesExceptID, orderExceptId } from 'redux/nodes/entities/base/helpers';
class ReduxConfig extends BaseConfig {
get actions () {
@ -56,6 +56,7 @@ class ReduxConfig extends BaseConfig {
data: {
...entitiesExceptID(state.data, payload.data),
},
originalOrder: orderExceptId(state.originalOrder, payload.data),
};
}
case actionTypes.CREATE_FAILURE:

View file

@ -9,6 +9,7 @@ describe('ReduxConfig - reducer', () => {
data: {
[userStub.id]: userStub,
},
originalOrder: [userStub.id],
};
describe('creating an entity', () => {
@ -69,6 +70,7 @@ describe('ReduxConfig - reducer', () => {
loading: false,
errors: {},
data: {},
originalOrder: [],
});
});
});

View file

@ -6,6 +6,10 @@ export const entitiesExceptID = (entities, id) => {
});
};
export const orderExceptId = (originalOrder, id) => {
return originalOrder.filter(entitiesId => entitiesId !== id);
};
const formatServerErrors = (errors) => {
if (!errors || !errors.length) {
return {};
@ -35,4 +39,4 @@ export const formatErrorResponse = (errorResponse) => {
};
};
export default { entitiesExceptID, formatErrorResponse };
export default { entitiesExceptID, orderExceptId, formatErrorResponse };

View file

@ -1,4 +1,4 @@
import { entitiesExceptID, formatErrorResponse } from './helpers';
import { entitiesExceptID, orderExceptId, formatErrorResponse } from './helpers';
describe('reduxConfig - helpers', () => {
describe('#entitiesExceptID', () => {
@ -24,6 +24,13 @@ describe('reduxConfig - helpers', () => {
});
});
describe('#orderExceptId', () => {
it('returns a new orderId array with the deleted entityID no longer in this array', () => {
const originalOrder = [1, 2, 3, 4];
expect(orderExceptId(originalOrder, 3)).toEqual([1, 2, 4]);
});
});
describe('#formatErrorResponse', () => {
it('converts the error response to an object for redux state', () => {
const errors = [