15088: Improves federated linking logic and UI
[arvados-workbench2.git] / src / views / link-account-panel / link-account-panel.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { RootState } from '~/store/store';
6 import { Dispatch } from 'redux';
7 import { connect } from 'react-redux';
8 import { startLinking, cancelLinking, linkAccount, linkAccountPanelActions } from '~/store/link-account-panel/link-account-panel-actions';
9 import { LinkAccountType } from '~/models/link-account';
10 import {
11     LinkAccountPanelRoot,
12     LinkAccountPanelRootDataProps,
13     LinkAccountPanelRootActionProps
14 } from '~/views/link-account-panel/link-account-panel-root';
15
16 const mapStateToProps = (state: RootState): LinkAccountPanelRootDataProps => {
17     return {
18         remoteHosts: state.auth.remoteHosts,
19         hasRemoteHosts: Object.keys(state.auth.remoteHosts).length > 1,
20         selectedCluster: state.linkAccountPanel.selectedCluster,
21         localCluster: state.auth.localCluster,
22         targetUser: state.linkAccountPanel.targetUser,
23         userToLink: state.linkAccountPanel.userToLink,
24         status: state.linkAccountPanel.status,
25         error: state.linkAccountPanel.error
26     };
27 };
28
29 const mapDispatchToProps = (dispatch: Dispatch): LinkAccountPanelRootActionProps => ({
30     startLinking: (type: LinkAccountType) => dispatch<any>(startLinking(type)),
31     cancelLinking: () => dispatch<any>(cancelLinking()),
32     linkAccount: () => dispatch<any>(linkAccount()),
33     setSelectedCluster: (selectedCluster: string) => dispatch<any>(linkAccountPanelActions.SET_SELECTED_CLUSTER({selectedCluster}))
34 });
35
36 export const LinkAccountPanel = connect(mapStateToProps, mapDispatchToProps)(LinkAccountPanelRoot);