17782: Removes the last linter warnings.
[arvados-workbench2.git] / src / store / dialog / with-dialog.ts
index 42ae73e4a46ddabfe3959bd6b7db99ce725969de..ea96ca0d7621b1959c38e3fb5bc25eaaded59a98 100644 (file)
@@ -2,32 +2,37 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
+import React from 'react';
 import { connect } from 'react-redux';
 import { DialogState } from './dialog-reducer';
 import { Dispatch } from 'redux';
 import { dialogActions } from './dialog-actions';
 
-export type WithDialog<T> = {
+export type WithDialogStateProps<T> = {
     open: boolean;
-    data?: T;
+    data: T;
 };
 
-export type WithDialogActions = {
+export type WithDialogDispatchProps = {
     closeDialog: () => void;
 };
 
+export type WithDialogProps<T> = WithDialogStateProps<T> & WithDialogDispatchProps;
 export const withDialog = (id: string) =>
-    <T>(component: React.ComponentType<WithDialog<T> & WithDialogActions>) =>
+    // TODO: How to make compiler happy with & P instead of & any?
+    // eslint-disable-next-line
+    <T, P>(component: React.ComponentType<WithDialogProps<T> & any>) =>
         connect(mapStateToProps(id), mapDispatchToProps(id))(component);
 
-export const mapStateToProps = (id: string) => <T>(state: { dialog: DialogState }): WithDialog<T> => {
+const emptyData = {};
+
+export const mapStateToProps = (id: string) => <T>(state: { dialog: DialogState }): WithDialogStateProps<T> => {
     const dialog = state.dialog[id];
-    return dialog ? dialog : { open: false };
+    return dialog ? dialog : { open: false, data: emptyData };
 };
 
-export const mapDispatchToProps = (id: string) => (dispatch: Dispatch): WithDialogActions => ({
+export const mapDispatchToProps = (id: string) => (dispatch: Dispatch): WithDialogDispatchProps => ({
     closeDialog: () => {
         dispatch(dialogActions.CLOSE_DIALOG({ id }));
     }
-});
\ No newline at end of file
+});