Skip to content

Commit

Permalink
Fixes pnp#5353:Property pane bug + add multiple permissions to display
Browse files Browse the repository at this point in the history
  • Loading branch information
D'Andrea Nello committed Nov 28, 2024
1 parent f55ceba commit 15aa42b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ISpSecurityWebPartProps> {
private _sp: SPFI = null;
Expand Down Expand Up @@ -70,18 +70,22 @@ export default class SpSecurityWebPart extends BaseClientSideWebPart<ISpSecurity
return perms;
}

private onPropertyChange(propertyPath: string, newValue: unknown): void {
private onPropertyChange(propertyPath: string, oldValue: ISelectedPermission[], newValue: ISelectedPermission[]): void {
switch (propertyPath) {
case "SelectedPermissions":
this.properties.selectedPermissions = newValue as ISpSecurityWebPartProps['selectedPermissions'];
case "SelectedPermissions": {
const updatedPermissions = newValue.map(newPerm => {
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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ const SpSecurity: React.FC<ISpSecurityProps> = (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) {
Expand All @@ -130,7 +131,7 @@ const SpSecurity: React.FC<ISpSecurityProps> = (props) => {
const renderListTitle = (item: SPList): JSX.Element => {
const iconName = item.itemCount > 0 ? 'FabricFormLibrary' : 'FabricFolder';
return (
<div className={styles.itemTitle} onClick={() => expandCollapseList(item)}>
<div className={styles.itemTitle} onClick={(event) => expandCollapseList(item, event)}>
<Icon iconName={iconName} className={styles.themecolor} />
<span>&nbsp;{item.title}</span>
</div>
Expand All @@ -141,7 +142,7 @@ const SpSecurity: React.FC<ISpSecurityProps> = (props) => {
const style = { marginLeft: `${item.level * 20}px` };
const iconName = item.itemCount > 0 ? 'FabricFormLibrary' : 'FabricFolder';
return (
<div className={styles.itemTitle} onClick={() => expandCollapseList(item)}>
<div className={styles.itemTitle} onClick={(event) => expandCollapseList(item, event)}>
<Icon iconName={iconName} style={style} className={styles.themecolor} />
<span>&nbsp;{item.title}</span>
</div>
Expand All @@ -160,8 +161,8 @@ const SpSecurity: React.FC<ISpSecurityProps> = (props) => {
};

const addUserColumns = (
columns: IColumn[],
users: SPSiteUser[],
columns: IColumn[],
users: SPSiteUser[],
effectivePermissions: ISelectedPermission[]
): IColumn[] => {
for (const user of users) {
Expand Down Expand Up @@ -252,11 +253,12 @@ const SpSecurity: React.FC<ISpSecurityProps> = (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,
Expand All @@ -266,20 +268,36 @@ const SpSecurity: React.FC<ISpSecurityProps> = (props) => {
state.securityInfo.adGroups
)) {
return (
<Icon
iconName={selectedPermission.iconName}
style={{ color: selectedPermission.color }}
onClick={() => expandCollapseList(item)}
/>
<div key={selectedPermission.permission} style={{ display: 'block' }} onClick={(event) => expandCollapseList(item, event)}>
{icons}
<Icon
iconName={selectedPermission.iconName}
style={{ color: selectedPermission.color}}
/>
</div>
);
}
}


return null;
});

return (
<Icon iconName={item.iconName} onClick={() => expandCollapseList(item)} />
<div style={{ display: 'block' } } onClick={(event) => expandCollapseList(item, event)}>
{icons}
<div style={{ display: 'block' }}>
<Icon iconName={item.iconName}/>
</div>
</div>
);
};


if (!state.securityInfoLoaded) {
return (
<div>
<Spinner label={'Fetching security information, please wait...'} />
</div>
);
}
if (!state.securityInfoLoaded) {
return (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,16 @@ export default class PropertyFieldSelectedPermissionsHost extends React.Componen
<SelectedPermissionsPanel
isOpen={this.state.openPanel}
onPropertyChange={(prop: string, oldval: ISelectedPermission[], newval: ISelectedPermission[]) => {
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}
/>
</div>
/> </div>
);
}
}

0 comments on commit 15aa42b

Please sign in to comment.