16971: Fixed project edit issues and added tests
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 24 Jun 2021 17:46:51 +0000 (19:46 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 24 Jun 2021 17:46:51 +0000 (19:46 +0200)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

cypress/integration/favorites.spec.js
src/views-components/context-menu/action-sets/project-action-set.ts
src/views/favorite-panel/favorite-panel.tsx
src/views/project-panel/project-panel.tsx

index 6e9091e1b76e63e3329df636af5279cabd9d47a1..506cd251e9db52d3afa8d21122790dfafebb44cb 100644 (file)
@@ -132,7 +132,46 @@ describe('Favorites tests', function () {
             });
     });
 
-    it('can view favourites in workflow', () => {
+    it.only('can edit project in favorites', () => {
+        cy.createProject({
+            owningUser: adminUser,
+            targetUser: activeUser,
+            projectName: 'mySharedWritableProject',
+            description: 'test 123123',
+            canWrite: true,
+            addToFavorites: true
+        });
+
+        cy.createCollection(adminUser.token, {
+            owner_uuid: activeUser.user.uuid,
+            name: `Test target collection ${Math.floor(Math.random() * 999999)}`,
+        }).as('testTargetCollection').then(function (testTargetCollection) {
+            cy.addToFavorites(activeUser.token, activeUser.user.uuid, testTargetCollection.uuid);
+        });
+
+        cy.getAll('@mySharedWritableProject', '@testTargetCollection')
+            .then(function ([mySharedWritableProject, testTargetCollection]) {
+                cy.loginAs(activeUser);
+
+                cy.get('[data-cy=side-panel-tree]').contains('My Favorites').click();
+
+                cy.get('main').contains(mySharedWritableProject.name).rightclick();
+                cy.get('[data-cy=context-menu]').contains('Edit project').click();
+                cy.get('[data-cy=form-dialog]').within(() => {
+                    cy.get('input[name=name]').should('have.value', mySharedWritableProject.name);
+                    cy.get('[data-cy=form-cancel-btn]').click();
+                });
+
+                cy.get('main').contains(testTargetCollection.name).rightclick();
+                cy.get('[data-cy=context-menu]').contains('Edit collection').click();
+                cy.get('[data-cy=form-dialog]').within(() => {
+                    cy.get('input[name=name]').should('have.value', testTargetCollection.name);
+                    cy.get('[data-cy=form-cancel-btn]').click();
+                });
+            });
+    });
+
+    it('can view favorites in workflow', () => {
         cy.createProject({
             owningUser: adminUser,
             targetUser: activeUser,
index 800f57d9f5ff13874d07b918c491a1ece4250c38..6d8aef74d134d1142c9eaf940f31d01dd20ab474 100644 (file)
@@ -73,6 +73,7 @@ export const filterGroupActionSet: ContextMenuActionSet = [
             icon: RenameIcon,
             name: "Edit project",
             execute: (dispatch, resource) => {
+                console.log(resource);
                 dispatch<any>(openProjectUpdateDialog(resource));
             }
         },
index 48a9e33029d679ec90a4ebe4d35ee966c7cbfad8..23b0c0056a1bc754462c687c75dea5fc3bc6d78b 100644 (file)
@@ -34,7 +34,11 @@ 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 { ResourcesState } from '~/store/resources/resources';
+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";
 
@@ -109,6 +113,7 @@ export const favoritePanelColumns: DataColumns<string> = [
 ];
 
 interface FavoritePanelDataProps {
+    currentItemId: any;
     favorites: FavoritesState;
     resources: ResourcesState;
     userUuid: string;
@@ -123,6 +128,7 @@ 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
@@ -133,14 +139,34 @@ export const FavoritePanel = withStyles(styles)(
         class extends React.Component<FavoritePanelProps> {
 
             handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
-                const menuKind = this.props.dispatch<any>(resourceUuidToContextMenuKind(resourceUuid));
-                if (menuKind) {
+                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: '',
+                    //     uuid: resourceUuid,
+                    //     ownerUuid: '',
+                    //     kind: ResourceKind.NONE,
+                    //     menuKind
+                    // }));
                     this.props.dispatch<any>(openContextMenu(event, {
-                        name: '',
-                        uuid: resourceUuid,
-                        ownerUuid: '',
-                        kind: ResourceKind.NONE,
-                        menuKind
+                        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));
index 35a7f9c16068e87296db695cf0b63f0e0fbae722..4327d1b7bf005ff0785f9f6e60504b3a94ccf5fd 100644 (file)
@@ -183,7 +183,8 @@ export const ProjectPanel = withStyles(styles)(
                         ownerUuid: resource.ownerUuid,
                         isTrashed: ('isTrashed' in resource) ? resource.isTrashed: false,
                         kind: resource.kind,
-                        menuKind
+                        menuKind,
+                        description: resource.description,
                     }));
                 }
                 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));