Merge remote-tracking branch 'origin/main' into 18368-notification-banner
[arvados-workbench2.git] / src / views / search-results-panel / search-results-panel.tsx
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 { navigateTo } from 'store/navigation/navigation-action';
8 import { openSearchResultsContextMenu } from 'store/context-menu/context-menu-actions';
9 import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
10 import { SearchResultsPanelView } from 'views/search-results-panel/search-results-panel-view';
11 import { RootState } from 'store/store';
12 import { SearchBarAdvancedFormData } from 'models/search-bar';
13 import { User } from "models/user";
14 import { Config } from 'common/config';
15 import { Session } from "models/session";
16
17 export interface SearchResultsPanelDataProps {
18     data: SearchBarAdvancedFormData;
19     user: User;
20     sessions: Session[];
21     remoteHostsConfig: { [key: string]: Config };
22     localCluster: string;
23 }
24
25 export interface SearchResultsPanelActionProps {
26     onItemClick: (item: string) => void;
27     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
28     onDialogOpen: (ownerUuid: string) => void;
29     onItemDoubleClick: (item: string) => void;
30 }
31
32 export type SearchResultsPanelProps = SearchResultsPanelDataProps & SearchResultsPanelActionProps;
33
34 const mapStateToProps = (rootState: RootState) => {
35     return {
36         user: rootState.auth.user,
37         sessions: rootState.auth.sessions,
38         remoteHostsConfig: rootState.auth.remoteHostsConfig,
39         localCluster: rootState.auth.localCluster,
40     };
41 };
42
43 const mapDispatchToProps = (dispatch: Dispatch): SearchResultsPanelActionProps => ({
44     onContextMenu: (event, resourceUuid) => {
45         dispatch<any>(openSearchResultsContextMenu(event, resourceUuid));
46     },
47     onDialogOpen: (ownerUuid: string) => { return; },
48     onItemClick: (resourceUuid: string) => {
49         dispatch<any>(loadDetailsPanel(resourceUuid));
50     },
51     onItemDoubleClick: uuid => {
52         dispatch<any>(navigateTo(uuid));
53     }
54 });
55
56 export const SearchResultsPanel = connect(mapStateToProps, mapDispatchToProps)(SearchResultsPanelView);