From 15aa42ba6f9c51e6d199f27eac55d598c0aa8b81 Mon Sep 17 00:00:00 2001 From: D'Andrea Nello Date: Thu, 28 Nov 2024 20:23:49 +0100 Subject: [PATCH 1/2] Fixes #5353:Property pane bug + add multiple permissions to display --- .../webparts/spSecurity/SpSecurityWebPart.ts | 14 +++-- .../spSecurity/components/SpSecurity.tsx | 52 +++++++++++++------ .../PropertyFieldSelectedPermissionsHost.tsx | 11 ++-- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/samples/react-securitygrid/src/webparts/spSecurity/SpSecurityWebPart.ts b/samples/react-securitygrid/src/webparts/spSecurity/SpSecurityWebPart.ts index 2ea5204a9c..09dda075c5 100644 --- a/samples/react-securitygrid/src/webparts/spSecurity/SpSecurityWebPart.ts +++ b/samples/react-securitygrid/src/webparts/spSecurity/SpSecurityWebPart.ts @@ -12,7 +12,7 @@ import * as ReactDom from "react-dom"; import { ISpSecurityProps } from "./components/ISpSecurityProps"; import SpSecurity from "./components/SpSecurity"; import { PropertyFieldSelectedPermissions } from "./containers/PropertyFieldSelectedPermissions"; -import { ISpSecurityWebPartProps } from "./ISpSecurityWebPartProps"; +import { ISelectedPermission, ISpSecurityWebPartProps } from "./ISpSecurityWebPartProps"; export default class SpSecurityWebPart extends BaseClientSideWebPart { private _sp: SPFI = null; @@ -70,18 +70,22 @@ export default class SpSecurityWebPart extends BaseClientSideWebPart { + const existingPermission = this.properties.selectedPermissions.find(permission => permission.permission === newPerm.permission); + return existingPermission ? { ...existingPermission, ...newPerm } : newPerm; + }); + this.properties.selectedPermissions = updatedPermissions; this.context.propertyPane.refresh(); this.render(); break; + } default: break; } } - protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { return { pages: [ diff --git a/samples/react-securitygrid/src/webparts/spSecurity/components/SpSecurity.tsx b/samples/react-securitygrid/src/webparts/spSecurity/components/SpSecurity.tsx index 12d93df997..85314035a4 100644 --- a/samples/react-securitygrid/src/webparts/spSecurity/components/SpSecurity.tsx +++ b/samples/react-securitygrid/src/webparts/spSecurity/components/SpSecurity.tsx @@ -107,7 +107,8 @@ const SpSecurity: React.FC = (props) => { setState({ ...state }); }; - const expandCollapseList = (item: SPList | SPListItem): void => { + const expandCollapseList = (item: SPList | SPListItem, event: React.MouseEvent): void => { + event.stopPropagation(); if (item.itemCount === 0) return; if (item.isExpanded) { @@ -130,7 +131,7 @@ const SpSecurity: React.FC = (props) => { const renderListTitle = (item: SPList): JSX.Element => { const iconName = item.itemCount > 0 ? 'FabricFormLibrary' : 'FabricFolder'; return ( -
expandCollapseList(item)}> +
expandCollapseList(item, event)}>  {item.title}
@@ -141,7 +142,7 @@ const SpSecurity: React.FC = (props) => { const style = { marginLeft: `${item.level * 20}px` }; const iconName = item.itemCount > 0 ? 'FabricFormLibrary' : 'FabricFolder'; return ( -
expandCollapseList(item)}> +
expandCollapseList(item, event)}>  {item.title}
@@ -160,8 +161,8 @@ const SpSecurity: React.FC = (props) => { }; const addUserColumns = ( - columns: IColumn[], - users: SPSiteUser[], + columns: IColumn[], + users: SPSiteUser[], effectivePermissions: ISelectedPermission[] ): IColumn[] => { for (const user of users) { @@ -252,11 +253,12 @@ const SpSecurity: React.FC = (props) => { column: IColumn, effectivePermissions: ISelectedPermission[] ): JSX.Element => { + const user = find(state.securityInfo.siteUsers, (su) => su.upn.toString() === column.key); - - for (const selectedPermission of effectivePermissions) { + + const icons = effectivePermissions.map((selectedPermission) => { const permissionKey = selectedPermission.permission as keyof typeof SPPermission; - + if (user && Helpers.doesUserHavePermission( item, user, @@ -266,20 +268,36 @@ const SpSecurity: React.FC = (props) => { state.securityInfo.adGroups )) { return ( - expandCollapseList(item)} - /> +
expandCollapseList(item, event)}> + {icons} + +
); } - } - + + return null; + }); + return ( - expandCollapseList(item)} /> +
expandCollapseList(item, event)}> + {icons} +
+ +
+
); }; - + + if (!state.securityInfoLoaded) { + return ( +
+ +
+ ); + } if (!state.securityInfoLoaded) { return (
diff --git a/samples/react-securitygrid/src/webparts/spSecurity/containers/PropertyFieldSelectedPermissionsHost.tsx b/samples/react-securitygrid/src/webparts/spSecurity/containers/PropertyFieldSelectedPermissionsHost.tsx index 7dd24c00cb..9184cddc02 100644 --- a/samples/react-securitygrid/src/webparts/spSecurity/containers/PropertyFieldSelectedPermissionsHost.tsx +++ b/samples/react-securitygrid/src/webparts/spSecurity/containers/PropertyFieldSelectedPermissionsHost.tsx @@ -114,13 +114,16 @@ export default class PropertyFieldSelectedPermissionsHost extends React.Componen { - this.setState({ SelectedPermissions: [...newval] }); - this.props.onPropertyChange("SelectedPermissions", this.props.SelectedPermissions, newval); + const updatedPermissions = newval.map(newPerm => { + const existingPermission = this.state.SelectedPermissions.find(permission => permission.permission === newPerm.permission); + return existingPermission ? { ...existingPermission, ...newPerm } : newPerm; + }); + this.setState({ SelectedPermissions: updatedPermissions }); + this.props.onPropertyChange("SelectedPermissions", this.props.SelectedPermissions, updatedPermissions); }} closePanel={() => { this.onClosePanel(); }} SelectedPermissions={this.props.SelectedPermissions} - /> -
+ />
); } } From 46c2093069da57a2d4ea134ae4db387c9365e525 Mon Sep 17 00:00:00 2001 From: D'Andrea Nello Date: Thu, 28 Nov 2024 20:28:33 +0100 Subject: [PATCH 2/2] Updated readme + package.json with version --- samples/react-securitygrid/README.md | 1 + samples/react-securitygrid/package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/samples/react-securitygrid/README.md b/samples/react-securitygrid/README.md index 328a113a4f..3caf9a9074 100644 --- a/samples/react-securitygrid/README.md +++ b/samples/react-securitygrid/README.md @@ -97,6 +97,7 @@ This is a port of an Angular 1.3 SharePoint hosted App at https://github.com/rus Version|Date|Comments -------|----|-------- +1.0.7.0|Nov 28, 2024 | Property pane didn't refresh fixed, added multiple permissions display 1.0.6.0|Oct 20, 2024 | Upgrade to SPFx 1.20 1.0.5.0|March 6, 2021 | Added webApiPermission request 1.0.0.4|February 22, 2021 | Added support for AD groups diff --git a/samples/react-securitygrid/package.json b/samples/react-securitygrid/package.json index f94a5afa2e..8f01062234 100644 --- a/samples/react-securitygrid/package.json +++ b/samples/react-securitygrid/package.json @@ -1,7 +1,7 @@ { "main": "lib/index.js", "name": "spsecurity-webpart-3", - "version": "1.0.5", + "version": "1.0.7", "private": true, "engines": { "node": ">=16.13.0 <17.0.0 || >=18.17.1 <19.0.0"