store: move status polling to redux
Updating a composes status is no longer done from the ImagesTable component. Instead the composeGetStatus thunk is used to make the api call and dispatch the COMPOSE_UPDATED_STATUS action. The polling still occurs from the component.
This commit is contained in:
parent
29b684599b
commit
1f962b44ae
4 changed files with 29 additions and 10 deletions
|
|
@ -14,9 +14,6 @@ import { ExternalLinkAltIcon, PlusCircleIcon } from '@patternfly/react-icons';
|
|||
import ImageBuildStatus from './ImageBuildStatus';
|
||||
import Release from './Release';
|
||||
import Upload from './Upload';
|
||||
|
||||
import api from '../../api.js';
|
||||
|
||||
class ImagesTable extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
|
@ -54,17 +51,14 @@ class ImagesTable extends Component {
|
|||
}
|
||||
|
||||
pollComposeStatuses() {
|
||||
let { composeUpdated, composes } = this.props;
|
||||
let { composes } = this.props;
|
||||
Object.entries(composes.byId).map(([ id, compose ]) => {
|
||||
/* Skip composes that have been complete */
|
||||
if (compose.image_status.status === 'success' || compose.image_status.status === 'failure') {
|
||||
return;
|
||||
}
|
||||
|
||||
api.getComposeStatus(id).then(response => {
|
||||
const newCompose = Object.assign({}, compose, { image_status: response.image_status });
|
||||
composeUpdated(newCompose);
|
||||
});
|
||||
this.props.composeGetStatus(id);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -145,13 +139,13 @@ function mapStateToProps(state) {
|
|||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
composeUpdated: (compose) => dispatch(actions.composeUpdated(compose)),
|
||||
composeGetStatus: (id) => dispatch(actions.composeGetStatus(id)),
|
||||
};
|
||||
}
|
||||
|
||||
ImagesTable.propTypes = {
|
||||
composes: PropTypes.object,
|
||||
composeUpdated: PropTypes.func,
|
||||
composeGetStatus: PropTypes.func,
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ImagesTable);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue