X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/46bb6c3da94118dabc77a01429900b0ecdd70343..38d27e9783f7f760cee84cc225e86144069848c4:/src/views/favorite-panel/favorite-panel.tsx

diff --git a/src/views/favorite-panel/favorite-panel.tsx b/src/views/favorite-panel/favorite-panel.tsx
index 40bf9a0c..82336b4a 100644
--- a/src/views/favorite-panel/favorite-panel.tsx
+++ b/src/views/favorite-panel/favorite-panel.tsx
@@ -2,18 +2,17 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
+import React from 'react';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
-import { DataExplorer } from "~/views-components/data-explorer/data-explorer";
+import { DataExplorer } from "views-components/data-explorer/data-explorer";
 import { connect, DispatchProp } from 'react-redux';
-import { DataColumns } from '~/components/data-table/data-table';
+import { DataColumns } from 'components/data-table/data-table';
 import { RouteComponentProps } from 'react-router';
-import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
-import { SortDirection } from '~/components/data-table/data-column';
-import { ResourceKind } from '~/models/resource';
-import { resourceLabel } from '~/common/labels';
-import { ArvadosTheme } from '~/common/custom-theme';
-import { FAVORITE_PANEL_ID } from "~/store/favorite-panel/favorite-panel-action";
+import { DataTableFilterItem } from 'components/data-table-filters/data-table-filters';
+import { SortDirection } from 'components/data-table/data-column';
+import { ResourceKind } from 'models/resource';
+import { ArvadosTheme } from 'common/custom-theme';
+import { FAVORITE_PANEL_ID } from "store/favorite-panel/favorite-panel-action";
 import {
     ProcessStatus,
     ResourceFileSize,
@@ -21,19 +20,26 @@ import {
     ResourceName,
     ResourceOwner,
     ResourceType
-} from '~/views-components/data-explorer/renderers';
-import { FavoriteIcon } from '~/components/icon/icon';
-import { Dispatch } from 'redux';
-import { openContextMenu, resourceKindToContextMenuKind } from '~/store/context-menu/context-menu-actions';
-import { loadDetailsPanel } from '~/store/details-panel/details-panel-action';
-import { navigateTo } from '~/store/navigation/navigation-action';
-import { ContainerRequestState } from "~/models/container-request";
-import { FavoritesState } from '../../store/favorites/favorites-reducer';
-import { RootState } from '~/store/store';
-import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
-import { createTree } from '~/models/tree';
-import { getInitialResourceTypeFilters } from '../../store/resource-type-filters/resource-type-filters';
-// TODO: clean up code
+} from 'views-components/data-explorer/renderers';
+import { FavoriteIcon } from 'components/icon/icon';
+import {
+    openContextMenu,
+    resourceUuidToContextMenuKind
+} from 'store/context-menu/context-menu-actions';
+import { loadDetailsPanel } from 'store/details-panel/details-panel-action';
+import { navigateTo } from 'store/navigation/navigation-action';
+import { ContainerRequestState } from "models/container-request";
+import { FavoritesState } from 'store/favorites/favorites-reducer';
+import { RootState } from 'store/store';
+import { DataTableDefaultView } from 'components/data-table-default-view/data-table-default-view';
+import { createTree } from 'models/tree';
+import { getSimpleObjectTypeFilters } from 'store/resource-type-filters/resource-type-filters';
+import { getResource, ResourcesState } from 'store/resources/resources';
+import { GroupContentsResource } from 'services/groups-service/groups-service';
+import { GroupClass, GroupResource } from 'models/group';
+import { getProperty } from 'store/properties/properties';
+import { PROJECT_PANEL_CURRENT_UUID } from 'store/project-panel/project-panel-action';
+
 type CssRules = "toolbar" | "button";
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
@@ -64,7 +70,7 @@ export const favoritePanelColumns: DataColumns<string> = [
         name: FavoritePanelColumnNames.NAME,
         selected: true,
         configurable: true,
-        sortDirection: SortDirection.ASC,
+        sortDirection: SortDirection.NONE,
         filters: createTree(),
         render: uuid => <ResourceName uuid={uuid} />
     },
@@ -79,12 +85,12 @@ export const favoritePanelColumns: DataColumns<string> = [
         name: FavoritePanelColumnNames.TYPE,
         selected: true,
         configurable: true,
-        filters: getInitialResourceTypeFilters(),
+        filters: getSimpleObjectTypeFilters(),
         render: uuid => <ResourceType uuid={uuid} />
     },
     {
         name: FavoritePanelColumnNames.OWNER,
-        selected: true,
+        selected: false,
         configurable: true,
         filters: createTree(),
         render: uuid => <ResourceOwner uuid={uuid} />
@@ -100,61 +106,79 @@ export const favoritePanelColumns: DataColumns<string> = [
         name: FavoritePanelColumnNames.LAST_MODIFIED,
         selected: true,
         configurable: true,
-        sortDirection: SortDirection.NONE,
+        sortDirection: SortDirection.DESC,
         filters: createTree(),
         render: uuid => <ResourceLastModifiedDate uuid={uuid} />
     }
 ];
 
 interface FavoritePanelDataProps {
+    currentItemId: any;
     favorites: FavoritesState;
+    resources: ResourcesState;
+    userUuid: string;
 }
 
 interface FavoritePanelActionProps {
     onItemClick: (item: string) => void;
-    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
     onDialogOpen: (ownerUuid: string) => void;
     onItemDoubleClick: (item: string) => void;
 }
-const mapStateToProps = ({ favorites }: RootState): FavoritePanelDataProps => ({
-    favorites
-});
-
-const mapDispatchToProps = (dispatch: Dispatch): FavoritePanelActionProps => ({
-    onContextMenu: (event, resourceUuid) => {
-        const kind = resourceKindToContextMenuKind(resourceUuid);
-        if (kind) {
-            dispatch<any>(openContextMenu(event, {
-                name: '',
-                uuid: resourceUuid,
-                ownerUuid: '',
-                kind: ResourceKind.NONE,
-                menuKind: kind
-            }));
-        }
-        dispatch<any>(loadDetailsPanel(resourceUuid));
-    },
-    onDialogOpen: (ownerUuid: string) => { return; },
-    onItemClick: (resourceUuid: string) => {
-        dispatch<any>(loadDetailsPanel(resourceUuid));
-    },
-    onItemDoubleClick: uuid => {
-        dispatch<any>(navigateTo(uuid));
-    }
+const mapStateToProps = (state : RootState): FavoritePanelDataProps => ({
+    favorites: state.favorites,
+    resources: state.resources,
+    userUuid: state.auth.user!.uuid,
+    currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
 });
 
 type FavoritePanelProps = FavoritePanelDataProps & FavoritePanelActionProps & DispatchProp
     & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
 
 export const FavoritePanel = withStyles(styles)(
-    connect(mapStateToProps, mapDispatchToProps)(
+    connect(mapStateToProps)(
         class extends React.Component<FavoritePanelProps> {
+
+            handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
+                const { resources } = this.props;
+                const resource = getResource<GroupContentsResource>(resourceUuid)(resources);
+
+                let readonly = false;
+                const project = getResource<GroupResource>(this.props.currentItemId)(resources);
+
+                if (project && project.groupClass === GroupClass.FILTER) {
+                    readonly = true;
+                }
+
+                const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid, readonly));
+
+                if (menuKind&& resource) {
+                    this.props.dispatch<any>(openContextMenu(event, {
+                        name: resource.name,
+                        uuid: resource.uuid,
+                        ownerUuid: resource.ownerUuid,
+                        isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
+                        kind: resource.kind,
+                        menuKind,
+                        description: resource.description,
+                    }));
+                }
+                this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
+            }
+
+            handleRowDoubleClick = (uuid: string) => {
+                this.props.dispatch<any>(navigateTo(uuid));
+            }
+
+            handleRowClick = (uuid: string) => {
+                this.props.dispatch<any>(loadDetailsPanel(uuid));
+            }
+
             render() {
                 return <DataExplorer
                     id={FAVORITE_PANEL_ID}
-                    onRowClick={this.props.onItemClick}
-                    onRowDoubleClick={this.props.onItemDoubleClick}
-                    onContextMenu={this.props.onContextMenu}
+                    onRowClick={this.handleRowClick}
+                    onRowDoubleClick={this.handleRowDoubleClick}
+                    onContextMenu={this.handleContextMenu}
                     contextMenuColumn={true}
                     dataTableDefaultView={
                         <DataTableDefaultView
