1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { connect } from 'react-redux';
7 import { DialogState } from './dialog-reducer';
9 export type WithDialog<T> = {
14 export const withDialog = (id: string) =>
15 <T>(component: React.ComponentType<WithDialog<T>>) =>
16 connect(mapStateToProps(id))(component);
18 export const mapStateToProps = (id: string) => <T>(state: { dialog: DialogState }): WithDialog<T> => {
19 const dialog = state.dialog[id];
20 return dialog ? dialog : { open: false };