17426: Plugins can replace some of main UI
[arvados-workbench2.git] / src / plugins / example / index.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 // Example plugin.
6
7 import { PluginConfig } from '~/common/plugintypes';
8 import * as React from 'react';
9 import { Dispatch } from 'redux';
10 import { RootState } from '~/store/store';
11 import { push } from "react-router-redux";
12 import { Typography } from "@material-ui/core";
13 import { Route, matchPath } from "react-router";
14 import { RootStore } from '~/store/store';
15 import { activateSidePanelTreeItem } from '~/store/side-panel-tree/side-panel-tree-actions';
16 import { setSidePanelBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
17
18 const categoryName = "Plugin Example";
19 export const routePath = "/examplePlugin";
20
21 const ExamplePluginMainPanel = (props: {}) => {
22     return <Typography>
23         This is a example main panel plugin.
24     </Typography>;
25 };
26
27 export const register = (pluginConfig: PluginConfig) => {
28
29     pluginConfig.centerPanelList.push((elms) => {
30         elms.push(<Route path={routePath} component={ExamplePluginMainPanel} />);
31         return elms;
32     });
33
34     pluginConfig.navigateToHandlers.push((dispatch: Dispatch, getState: () => RootState, uuid: string) => {
35         if (uuid === categoryName) {
36             dispatch(push(routePath));
37             return true;
38         }
39         return false;
40     });
41
42     pluginConfig.sidePanelCategories.push((cats: string[]): string[] => { cats.push(categoryName); return cats; });
43
44     pluginConfig.locationChangeHandlers.push((store: RootStore, pathname: string): boolean => {
45         if (matchPath(pathname, { path: routePath, exact: true })) {
46             store.dispatch(activateSidePanelTreeItem(categoryName));
47             store.dispatch<any>(setSidePanelBreadcrumbs(categoryName));
48             return true;
49         }
50         return false;
51     });
52 };