store: add get all composes api call

The ImagesTable will now trigger a thunk to fetch all of users composes
on load. The response of the /composes api call does not include status
so we currently only fetch the first 10 composes and fetch the status
for each of them.
This commit is contained in:
Jacob Kozol 2021-04-21 16:13:12 +02:00 committed by Sanne Raymaekers
parent 1f962b44ae
commit 9b08788fd2
3 changed files with 23 additions and 0 deletions

View file

@ -43,6 +43,7 @@ class ImagesTable extends Component {
}
componentDidMount() {
this.props.composeGetAll();
this.interval = setInterval(() => this.pollComposeStatuses(), 8000);
}
@ -139,12 +140,14 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return {
composeGetAll: () => dispatch(actions.composeGetAll()),
composeGetStatus: (id) => dispatch(actions.composeGetStatus(id)),
};
}
ImagesTable.propTypes = {
composes: PropTypes.object,
composeGetAll: PropTypes.func,
composeGetStatus: PropTypes.func,
};

View file

@ -11,6 +11,16 @@ async function composeImage(body) {
return request.data;
}
async function getComposes(limit, offset) {
const params = new URLSearchParams({
limit,
offset,
});
let path = '/composes?' + params.toString();
const request = await axios.get(IMAGE_BUILDER_API.concat(path));
return request.data;
}
async function getComposeStatus(id) {
let path = '/composes/' + id;
const request = await axios.get(IMAGE_BUILDER_API.concat(path));
@ -36,6 +46,7 @@ async function getVersion() {
export default {
composeImage,
getComposes,
getComposeStatus,
getPackages,
getVersion,

View file

@ -45,6 +45,14 @@ export const composeGetStatus = (id) => async dispatch => {
dispatch(composeUpdatedStatus(id, request.image_status));
};
export const composeGetAll = () => async dispatch => {
// only search for the first 10 composes for now
const request = await api.getComposes(10, 0);
request.data.map(compose => {
dispatch(composeAdded(compose));
dispatch(composeGetStatus(compose.id));
});
};
function setRelease({ arch, distro }) {
return {
@ -123,6 +131,7 @@ function setSubscribeNow(subscribeNow) {
}
export default {
composeGetAll,
composeStart,
composeUpdated,
composeGetStatus,