X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3e05c931b42b1b690f43e179aaa9b45c84475ba0..5a5f30dbbfa1df4fd3dfade4cb5deab2a4ded56c:/src/views/groups-panel/groups-panel.tsx?ds=inline

diff --git a/src/views/groups-panel/groups-panel.tsx b/src/views/groups-panel/groups-panel.tsx
index ed865d92..3251c729 100644
--- a/src/views/groups-panel/groups-panel.tsx
+++ b/src/views/groups-panel/groups-panel.tsx
@@ -2,40 +2,38 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import withStyles from "@material-ui/core/styles/withStyles";
-import { DispatchProp, connect } from 'react-redux';
-import { RouteComponentProps } from 'react-router';
-import { StyleRulesCallback, WithStyles, Typography } from "@material-ui/core";
-
-import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
-import { DataColumns } from '~/components/data-table/data-table';
-import { RootState } from '~/store/store';
-import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
-import { ContainerRequestState } from '~/models/container-request';
-import { SortDirection } from '~/components/data-table/data-column';
-import { ResourceKind, Resource } from '~/models/resource';
-import { ResourceFileSize, ResourceLastModifiedDate, ProcessStatus, ResourceType, ResourceOwner } from '~/views-components/data-explorer/renderers';
-import { ProjectIcon } from '~/components/icon/icon';
-import { ResourceName } from '~/views-components/data-explorer/renderers';
-import { ResourcesState, getResource } from '~/store/resources/resources';
-import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
-import { resourceKindToContextMenuKind, openContextMenu } from '~/store/context-menu/context-menu-actions';
-import { ProjectResource } from '~/models/project';
-import { navigateTo } from '~/store/navigation/navigation-action';
-import { getProperty } from '~/store/properties/properties';
-import { PROJECT_PANEL_CURRENT_UUID } from '~/store/project-panel/project-panel-action';
-import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
-import { ArvadosTheme } from "~/common/custom-theme";
-import { createTree } from '~/models/tree';
-import { getInitialResourceTypeFilters } from '~/store/resource-type-filters/resource-type-filters';
-import { GROUPS_PANEL_ID } from '~/store/groups-panel/groups-panel-actions';
+import React from 'react';
+import { connect } from 'react-redux';
+import { Grid, Button, Typography, StyleRulesCallback, WithStyles, withStyles } from "@material-ui/core";
+import { DataExplorer } from "views-components/data-explorer/data-explorer";
+import { DataColumns } from 'components/data-table/data-table';
+import { SortDirection } from 'components/data-table/data-column';
+import { ResourceUuid } from 'views-components/data-explorer/renderers';
+import { AddIcon } from 'components/icon/icon';
+import { ResourceName } from 'views-components/data-explorer/renderers';
+import { createTree } from 'models/tree';
+import { GROUPS_PANEL_ID, openCreateGroupDialog } from 'store/groups-panel/groups-panel-actions';
 import { noop } from 'lodash/fp';
-import { GroupResource } from '~/models/group';
+import { ContextMenuKind } from 'views-components/context-menu/context-menu';
+import { getResource, ResourcesState, filterResources } from 'store/resources/resources';
+import { GroupResource } from 'models/group';
+import { RootState } from 'store/store';
+import { openContextMenu } from 'store/context-menu/context-menu-actions';
+import { ResourceKind } from 'models/resource';
+import { LinkClass, LinkResource } from 'models/link';
+import { ArvadosTheme } from 'common/custom-theme';
+
+type CssRules = "root";
+
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    root: {
+        width: '100%',
+    }
+});
 
 export enum GroupsPanelColumnNames {
     GROUP = "Name",
-    OWNER = "Owner",
+    UUID = "UUID",
     MEMBERS = "Members",
 }
 
@@ -49,31 +47,95 @@ export const groupsPanelColumns: DataColumns<string> = [
         render: uuid => <ResourceName uuid={uuid} />
     },
     {
-        name: GroupsPanelColumnNames.OWNER,
+        name: GroupsPanelColumnNames.UUID,
         selected: true,
         configurable: true,
         filters: createTree(),
-        render: uuid => <ResourceOwner uuid={uuid} />,
+        render: uuid => <ResourceUuid uuid={uuid} />,
     },
     {
         name: GroupsPanelColumnNames.MEMBERS,
         selected: true,
         configurable: true,
         filters: createTree(),
-        render: uuid => <span>0</span>,
+        render: uuid => <GroupMembersCount uuid={uuid} />,
     },
 ];
 
-export class GroupsPanel extends React.Component {
-
-    render() {
-        return (
-            <DataExplorer
-                id={GROUPS_PANEL_ID}
-                onRowClick={noop}
-                onRowDoubleClick={noop}
-                onContextMenu={noop}
-                contextMenuColumn={true} />
-        );
-    }
+const mapStateToProps = (state: RootState) => {
+    return {
+        resources: state.resources
+    };
+};
+
+const mapDispatchToProps = {
+    onContextMenu: openContextMenu,
+    onNewGroup: openCreateGroupDialog,
+};
+
+export interface GroupsPanelProps {
+    onNewGroup: () => void;
+    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
+    resources: ResourcesState;
 }
+
+export const GroupsPanel = withStyles(styles)(connect(
+    mapStateToProps, mapDispatchToProps
+)(
+    class GroupsPanel extends React.Component<GroupsPanelProps & WithStyles<CssRules>> {
+
+        render() {
+            return (
+                <div className={this.props.classes.root}><DataExplorer
+                    id={GROUPS_PANEL_ID}
+                    data-cy="groups-panel-data-explorer"
+                    onRowClick={noop}
+                    onRowDoubleClick={noop}
+                    onContextMenu={this.handleContextMenu}
+                    contextMenuColumn={true}
+                    hideColumnSelector
+                    actions={
+                        <Grid container justify='flex-end'>
+                            <Button
+                                data-cy="groups-panel-new-group"
+                                variant="contained"
+                                color="primary"
+                                onClick={this.props.onNewGroup}>
+                                <AddIcon /> New group
+                        </Button>
+                        </Grid>
+                    } /></div>
+            );
+        }
+
+        handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
+            const resource = getResource<GroupResource>(resourceUuid)(this.props.resources);
+            if (resource) {
+                this.props.onContextMenu(event, {
+                    name: resource.name,
+                    uuid: resource.uuid,
+                    description: resource.description,
+                    ownerUuid: resource.ownerUuid,
+                    kind: resource.kind,
+                    menuKind: ContextMenuKind.GROUPS
+                });
+            }
+        }
+    }));
+
+
+const GroupMembersCount = connect(
+    (state: RootState, props: { uuid: string }) => {
+
+        const permissions = filterResources((resource: LinkResource) =>
+            resource.kind === ResourceKind.LINK &&
+            resource.linkClass === LinkClass.PERMISSION &&
+            resource.headUuid === props.uuid
+        )(state.resources);
+
+        return {
+            children: permissions.length,
+        };
+
+    }
+)((props: {children: number}) => (<Typography children={props.children} />));
