Merge branch '17585-Redesign-navigation-of-files-in-collections' into main
[arvados-workbench2.git] / src / views / ssh-key-panel / ssh-key-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 { openSshKeyCreateDialog, openPublicKeyDialog } from 'store/auth/auth-action-ssh';
9 import { openSshKeyContextMenu } from 'store/context-menu/context-menu-actions';
10 import { SshKeyPanelRoot, SshKeyPanelRootDataProps, SshKeyPanelRootActionProps } from 'views/ssh-key-panel/ssh-key-panel-root';
11
12 const mapStateToProps = (state: RootState): SshKeyPanelRootDataProps => {
13     const sshKeys = state.auth.sshKeys.filter((key) => {
14       return key.authorizedUserUuid === (state.auth.user ? state.auth.user.uuid : null);
15     });
16
17     return {
18         sshKeys: sshKeys,
19         hasKeys: sshKeys!.length > 0
20     };
21 };
22
23 const mapDispatchToProps = (dispatch: Dispatch): SshKeyPanelRootActionProps => ({
24     openSshKeyCreateDialog: () => {
25         dispatch<any>(openSshKeyCreateDialog());
26     },
27     openRowOptions: (event, sshKey) => {
28         dispatch<any>(openSshKeyContextMenu(event, sshKey));
29     },
30     openPublicKeyDialog: (name: string, publicKey: string) => {
31         dispatch<any>(openPublicKeyDialog(name, publicKey));
32     }
33 });
34
35 export const SshKeyPanel = connect(mapStateToProps, mapDispatchToProps)(SshKeyPanelRoot);