Merge branch '21128-toolbar-context-menu'
[arvados-workbench2.git] / src / store / progress-indicator / with-progress.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { connect } from 'react-redux';
7 import { RootState } from 'store/store';
8
9 export type WithProgressStateProps = {
10     working: boolean;
11 };
12
13 export const withProgress = (id: string) =>
14     (component: React.ComponentType<WithProgressStateProps>) =>
15         connect(mapStateToProps(id))(component);
16
17 export const mapStateToProps = (id: string) => (state: RootState): WithProgressStateProps => {
18     const progress = state.progressIndicator.find(p => p.id === id);
19     return { working: progress ? progress.working : false };
20 };