store: add compose count

When we get composes we also get the count of total composes stored in
image-builder. We now store this quantity in our store.
This commit is contained in:
Jacob Kozol 2021-04-23 17:34:09 +02:00 committed by Sanne Raymaekers
parent 4f58f6202a
commit 82c0615aab
4 changed files with 38 additions and 0 deletions

View file

@ -45,12 +45,18 @@ export const composeGetStatus = (id) => async dispatch => {
dispatch(composeUpdatedStatus(id, request.image_status));
};
export const composesUpdatedCount = (count) => ({
type: types.COMPOSES_UPDATED_COUNT,
payload: { count }
});
export const composesGet = (limit, offset) => async dispatch => {
const request = await api.getComposes(limit, offset);
request.data.map(compose => {
dispatch(composeAdded(compose));
dispatch(composeGetStatus(compose.id));
});
dispatch(composesUpdatedCount(request.meta.count));
};
function setRelease({ arch, distro }) {

View file

@ -25,6 +25,7 @@ import types from '../types';
// };
const initialComposesState = {
count: 0,
allIds: [],
byId: {},
error: null,
@ -63,6 +64,11 @@ export function composes(state = initialComposesState, action) {
[action.payload.compose.id]: action.payload.compose,
}
};
case types.COMPOSES_UPDATED_COUNT:
return {
...state,
count: action.payload.count,
};
case types.COMPOSE_UPDATED_STATUS:
return {
...state,

View file

@ -1,6 +1,7 @@
const COMPOSE_ADDED = 'COMPOSE_ADDED';
const COMPOSE_FAILED = 'COMPOSE_FAILED';
const COMPOSE_UPDATED = 'COMPOSE_UPDATED';
const COMPOSES_UPDATED_COUNT = 'COMPOSES_UPDATED_COUNT';
const COMPOSE_UPDATED_STATUS = 'COMPOSE_UPDATED_STATUS';
const SET_RELEASE = 'SET_RELEASE';
const SET_UPLOAD_DESTINATIONS = 'SET_UPLOAD_DESTINATIONS';
@ -15,6 +16,7 @@ export default {
COMPOSE_ADDED,
COMPOSE_FAILED,
COMPOSE_UPDATED,
COMPOSES_UPDATED_COUNT,
COMPOSE_UPDATED_STATUS,
SET_RELEASE,
SET_UPLOAD_DESTINATIONS,

View file

@ -32,6 +32,7 @@ describe('composes', () => {
const state = {
allIds: [],
byId: {},
count: 1,
errors: null,
};
const result = composes(state, {
@ -43,6 +44,8 @@ describe('composes', () => {
.toEqual([ '77e4c693-0497-4b85-936d-b2a3ad69571b' ]);
expect(result.byId['77e4c693-0497-4b85-936d-b2a3ad69571b'])
.toEqual(compose);
expect(result.count)
.toEqual(1);
expect(result.error)
.toEqual(null);
});
@ -53,6 +56,7 @@ describe('composes', () => {
byId: {
'77e4c693-0497-4b85-936d-b2a3ad69571b': {},
},
count: 2,
error: null,
};
const result = composes(state, {
@ -64,6 +68,8 @@ describe('composes', () => {
.toEqual([ '77e4c693-0497-4b85-936d-b2a3ad69571b' ]);
expect(result.byId['77e4c693-0497-4b85-936d-b2a3ad69571b'])
.toEqual(compose);
expect(result.count)
.toEqual(2);
expect(result.error)
.toEqual(null);
});
@ -72,6 +78,7 @@ describe('composes', () => {
const state = {
allIds: [],
byId: {},
count: 0,
error: null,
};
const result = composes(state, {
@ -83,4 +90,21 @@ describe('composes', () => {
.toEqual('test error');
});
test('returns updated state for types.COMPOSES_UPDATED_COUNT', () => {
const state = {
allIds: [],
byId: {},
count: 0,
error: null,
};
const result = composes(state, {
type: types.COMPOSES_UPDATED_COUNT,
payload: { count: 1 }
});
expect(result.count)
.toEqual(1);
});
});