mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
fix deleting host breaking host table (#423)
This commit is contained in:
parent
54c2b0b8df
commit
e38a020050
4 changed files with 17 additions and 3 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -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 = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue