Merge branch '19142-avoid-loading-unneeded-mounts' into main. Closes #19142
[arvados-workbench2.git] / src / views-components / file-remove-dialog / file-remove-dialog.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import { connect } from "react-redux";
7 import { ConfirmationDialog } from "components/confirmation-dialog/confirmation-dialog";
8 import { withDialog, WithDialogProps } from 'store/dialog/with-dialog';
9 import { RootState } from 'store/store';
10 import { removeCollectionFiles, FILE_REMOVE_DIALOG } from 'store/collection-panel/collection-panel-files/collection-panel-files-actions';
11
12 const mapStateToProps = (state: RootState, props: WithDialogProps<{ filePath: string }>) => ({
13     filePath: props.data.filePath
14 });
15
16 const mapDispatchToProps = (dispatch: Dispatch, props: WithDialogProps<{ filePath: string }>) => ({
17     onConfirm: (filePath: string) => {
18         props.closeDialog();
19         dispatch<any>(removeCollectionFiles([filePath]));
20     }
21 });
22
23 const mergeProps = (
24     stateProps: { filePath: string },
25     dispatchProps: { onConfirm: (filePath: string) => void },
26     props: WithDialogProps<{ filePath: string }>) => ({
27         onConfirm: () => dispatchProps.onConfirm(stateProps.filePath),
28         ...props
29     });
30
31 // TODO: Remove as any
32 export const [FileRemoveDialog] = [ConfirmationDialog]
33     .map(connect(mapStateToProps, mapDispatchToProps, mergeProps) as any)
34     .map(withDialog(FILE_REMOVE_DIALOG));