Added react-group-members;
Displays a list of persona cards that looks like the default personas Imported this from my old collection of SPFX modules.
This commit is contained in:
parent
89611797cc
commit
846239b32a
|
@ -0,0 +1,33 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Build generated files
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
release
|
||||||
|
solution
|
||||||
|
temp
|
||||||
|
*.sppkg
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# OSX
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Visual Studio files
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
.vs
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
|
||||||
|
# Resx Generated Code
|
||||||
|
*.resx.ts
|
||||||
|
|
||||||
|
# Styles Generated Code
|
||||||
|
*.scss.ts
|
|
@ -0,0 +1,16 @@
|
||||||
|
!dist
|
||||||
|
config
|
||||||
|
|
||||||
|
gulpfile.js
|
||||||
|
|
||||||
|
release
|
||||||
|
src
|
||||||
|
temp
|
||||||
|
|
||||||
|
tsconfig.json
|
||||||
|
tslint.json
|
||||||
|
|
||||||
|
*.log
|
||||||
|
|
||||||
|
.yo-rc.json
|
||||||
|
.vscode
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"@microsoft/generator-sharepoint": {
|
||||||
|
"plusBeta": false,
|
||||||
|
"isCreatingSolution": true,
|
||||||
|
"version": "1.14.0",
|
||||||
|
"libraryName": "react-group-members",
|
||||||
|
"libraryId": "0b0829f6-4e41-4bf2-9cbe-fd67fca2d34c",
|
||||||
|
"environment": "spo",
|
||||||
|
"packageManager": "npm",
|
||||||
|
"solutionName": "react-group-members",
|
||||||
|
"solutionShortDescription": "react-group-members description",
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"componentType": "webpart"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
# react-group-members
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
Uses the MS Graph client to list the members of a group(s) and displays Person Cards, think of it as an automated People Profile native control. Utilizes PnP Property Controls and PnP Placeholder.
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
|
||||||
|
![SPFx 1.14.0](https://img.shields.io/badge/SPFx-1.14.0-green.svg)
|
||||||
|
![Node.js v14 | v12 | v10](https://img.shields.io/badge/Node.js-v14%20%7C%20v12%20%7C%20v10-green.svg)
|
||||||
|
![SharePoint Online](https://img.shields.io/badge/SharePoint-Online-yellow.svg)
|
||||||
|
![Workbench Hosted: Does not work with local workbench](https://img.shields.io/badge/Workbench-Hosted-yellow.svg "Does not work with local workbench")
|
||||||
|
![Compatible with Remote Containers](https://img.shields.io/badge/Remote%20Containers-Compatible-green.svg)
|
||||||
|
|
||||||
|
|
||||||
|
## Applies to
|
||||||
|
|
||||||
|
- [SharePoint Framework](https://aka.ms/spfx)
|
||||||
|
- [Microsoft 365 tenant](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||||
|
|
||||||
|
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
> Any special pre-requisites?
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
Solution|Author(s)
|
||||||
|
--------|---------
|
||||||
|
react-group-members | [Nick Brown](https://github.com/techienickb)
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
Version|Date|Comments
|
||||||
|
-------|----|--------
|
||||||
|
1.0|March 30, 2022|Initial release
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
|
||||||
|
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Minimal Path to Awesome
|
||||||
|
|
||||||
|
- Clone this repository
|
||||||
|
- in the command line run:
|
||||||
|
- `npm install`
|
||||||
|
- `gulp build`
|
||||||
|
- `gulp bundle --ship`
|
||||||
|
- `gulp package-solution --ship`
|
||||||
|
- Add to AppCatalog and deploy
|
||||||
|
|
||||||
|
> This sample can also be opened with [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview). Visit https://aka.ms/spfx-devcontainer for further instructions.
|
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||||
|
"version": "2.0",
|
||||||
|
"bundles": {
|
||||||
|
"group-members-web-part": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"entrypoint": "./lib/webparts/groupMembers/GroupMembersWebPart.js",
|
||||||
|
"manifest": "./src/webparts/groupMembers/GroupMembersWebPart.manifest.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"externals": {},
|
||||||
|
"localizedResources": {
|
||||||
|
"GroupMembersWebPartStrings": "lib/webparts/groupMembers/loc/{locale}.js",
|
||||||
|
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js",
|
||||||
|
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||||
|
"workingDir": "./release/assets/",
|
||||||
|
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||||
|
"container": "react-group-members",
|
||||||
|
"accessKey": "<!-- ACCESS KEY -->"
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
|
"solution": {
|
||||||
|
"name": "react-group-members-client-side-solution",
|
||||||
|
"id": "0b0829f6-4e41-4bf2-9cbe-fd67fca2d34c",
|
||||||
|
"title": "Group Members",
|
||||||
|
"version": "1.0.0.0",
|
||||||
|
"includeClientSideAssets": true,
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"developer": {
|
||||||
|
"name": "Nick Brown",
|
||||||
|
"websiteUrl": "https://nbdev.uk",
|
||||||
|
"privacyUrl": "",
|
||||||
|
"termsOfUseUrl": "",
|
||||||
|
"mpnId": "Undefined-1.14.0"
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"shortDescription": {
|
||||||
|
"default": "List members of a group in people cards"
|
||||||
|
},
|
||||||
|
"longDescription": {
|
||||||
|
"default": "Loads the members of an AAD group and then displays that in a people card"
|
||||||
|
},
|
||||||
|
"screenshotPaths": [],
|
||||||
|
"videoUrl": "",
|
||||||
|
"categories": []
|
||||||
|
},
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"title": "List members of a group in the People control view",
|
||||||
|
"description": "Loads the members of an AAD group and then displays that in a people card. Automated people profiles based on a group",
|
||||||
|
"id": "a3238ad2-9b27-4970-88a7-cad9bbf08142",
|
||||||
|
"version": "1.0.0.0"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"webApiPermissionRequests": [
|
||||||
|
{
|
||||||
|
"resource": "Microsoft Graph",
|
||||||
|
"scope": "GroupMember.Read.All"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"zippedPackage": "solution/react-group-members.sppkg"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||||
|
"port": 4321,
|
||||||
|
"https": true,
|
||||||
|
"initialPage": "https://enter-your-SharePoint-site/_layouts/workbench.aspx"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||||
|
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const build = require('@microsoft/sp-build-web');
|
||||||
|
|
||||||
|
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||||
|
|
||||||
|
var getTasks = build.rig.getTasks;
|
||||||
|
build.rig.getTasks = function () {
|
||||||
|
var result = getTasks.call(build.rig);
|
||||||
|
|
||||||
|
result.set('serve', result.get('serve-deprecated'));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
build.initialize(require('gulp'));
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"name": "react-group-members",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "gulp bundle",
|
||||||
|
"clean": "gulp clean",
|
||||||
|
"test": "gulp test"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@microsoft/microsoft-graph-types": "^2.16.0",
|
||||||
|
"@microsoft/sp-core-library": "1.14.0",
|
||||||
|
"@microsoft/sp-lodash-subset": "1.14.0",
|
||||||
|
"@microsoft/sp-office-ui-fabric-core": "1.14.0",
|
||||||
|
"@microsoft/sp-property-pane": "1.14.0",
|
||||||
|
"@microsoft/sp-webpart-base": "1.14.0",
|
||||||
|
"@pnp/spfx-controls-react": "3.7.2",
|
||||||
|
"@pnp/spfx-property-controls": "3.6.0",
|
||||||
|
"office-ui-fabric-react": "^7.184.0",
|
||||||
|
"react": "16.13.1",
|
||||||
|
"react-dom": "16.13.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@microsoft/rush-stack-compiler-3.9": "^0.4.48",
|
||||||
|
"@microsoft/sp-build-web": "1.14.0",
|
||||||
|
"@microsoft/sp-module-interfaces": "1.14.0",
|
||||||
|
"@microsoft/sp-tslint-rules": "1.14.0",
|
||||||
|
"@types/react": "16.9.51",
|
||||||
|
"@types/react-dom": "16.9.8",
|
||||||
|
"@types/webpack-env": "1.13.1",
|
||||||
|
"ajv": "~5.2.2",
|
||||||
|
"gulp": "~4.0.2"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,23 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||||
|
"id": "64de6274-1a65-4ef7-a44e-2d8ce48e14ff",
|
||||||
|
"alias": "GroupMembersWebPart",
|
||||||
|
"componentType": "WebPart",
|
||||||
|
"version": "*",
|
||||||
|
"manifestVersion": 2,
|
||||||
|
"requiresCustomScript": false,
|
||||||
|
"supportedHosts": ["SharePointWebPart", "TeamsPersonalApp", "TeamsTab", "SharePointFullPage"],
|
||||||
|
"supportsThemeVariants": true,
|
||||||
|
|
||||||
|
"preconfiguredEntries": [{
|
||||||
|
"groupId": "5c03119e-3074-46fd-976b-c60198311f70",
|
||||||
|
"group": { "default": "Other" },
|
||||||
|
"title": { "default": "Group Members" },
|
||||||
|
"description": { "default": "Group Members description" },
|
||||||
|
"officeFabricIconFontName": "Group",
|
||||||
|
"properties": {
|
||||||
|
"groups": [],
|
||||||
|
"ignorePeople": []
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
}
|
|
@ -0,0 +1,118 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import * as ReactDom from 'react-dom';
|
||||||
|
import { Version } from '@microsoft/sp-core-library';
|
||||||
|
import { IPropertyPaneConfiguration } from '@microsoft/sp-property-pane';
|
||||||
|
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||||
|
import { IReadonlyTheme } from '@microsoft/sp-component-base';
|
||||||
|
|
||||||
|
import * as strings from 'GroupMembersWebPartStrings';
|
||||||
|
import GroupMembers from './components/GroupMembers';
|
||||||
|
import { IGroupMembersProps } from './components/IGroupMembersProps';
|
||||||
|
import { IPropertyFieldGroupOrPerson, PrincipalType, PropertyFieldPeoplePicker } from '@pnp/spfx-property-controls';
|
||||||
|
|
||||||
|
export interface IGroupMembersWebPartProps {
|
||||||
|
groups: IPropertyFieldGroupOrPerson[];
|
||||||
|
ignorePeople: IPropertyFieldGroupOrPerson[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class GroupMembersWebPart extends BaseClientSideWebPart<IGroupMembersWebPartProps> {
|
||||||
|
|
||||||
|
private _isDarkTheme: boolean = false;
|
||||||
|
private _environmentMessage: string = '';
|
||||||
|
|
||||||
|
protected onInit(): Promise<void> {
|
||||||
|
this._environmentMessage = this._getEnvironmentMessage();
|
||||||
|
|
||||||
|
return super.onInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): void {
|
||||||
|
const element: React.ReactElement<IGroupMembersProps> = React.createElement(
|
||||||
|
GroupMembers,
|
||||||
|
{
|
||||||
|
groups: this.properties.groups,
|
||||||
|
ignorePeople: this.properties.ignorePeople,
|
||||||
|
context: this.context,
|
||||||
|
isDarkTheme: this._isDarkTheme,
|
||||||
|
environmentMessage: this._environmentMessage,
|
||||||
|
hasTeamsContext: !!this.context.sdks.microsoftTeams,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ReactDom.render(element, this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getEnvironmentMessage(): string {
|
||||||
|
if (!!this.context.sdks.microsoftTeams) { // running in Teams
|
||||||
|
return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentTeams : strings.AppTeamsTabEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.context.isServedFromLocalhost ? strings.AppLocalEnvironmentSharePoint : strings.AppSharePointEnvironment;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onThemeChanged(currentTheme: IReadonlyTheme | undefined): void {
|
||||||
|
if (!currentTheme) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._isDarkTheme = !!currentTheme.isInverted;
|
||||||
|
const {
|
||||||
|
semanticColors
|
||||||
|
} = currentTheme;
|
||||||
|
this.domElement.style.setProperty('--bodyText', semanticColors.bodyText);
|
||||||
|
this.domElement.style.setProperty('--link', semanticColors.link);
|
||||||
|
this.domElement.style.setProperty('--linkHovered', semanticColors.linkHovered);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected onDispose(): void {
|
||||||
|
ReactDom.unmountComponentAtNode(this.domElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected get dataVersion(): Version {
|
||||||
|
return Version.parse('1.0');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||||
|
return {
|
||||||
|
pages: [
|
||||||
|
{
|
||||||
|
header: {
|
||||||
|
description: ""
|
||||||
|
},
|
||||||
|
groups: [
|
||||||
|
{
|
||||||
|
groupName: "",
|
||||||
|
groupFields: [
|
||||||
|
PropertyFieldPeoplePicker('groups', {
|
||||||
|
label: "Select a group, please don't select a person",
|
||||||
|
initialData: this.properties.groups,
|
||||||
|
allowDuplicate: false,
|
||||||
|
principalType: [PrincipalType.SharePoint, PrincipalType.Security],
|
||||||
|
onPropertyChange: this.onPropertyPaneFieldChanged,
|
||||||
|
context: this.context,
|
||||||
|
properties: this.properties,
|
||||||
|
onGetErrorMessage: null,
|
||||||
|
deferredValidationTime: 0,
|
||||||
|
key: 'groups'
|
||||||
|
}),
|
||||||
|
PropertyFieldPeoplePicker('ignorePeople', {
|
||||||
|
label: "Select any users you wish to ignore",
|
||||||
|
initialData: this.properties.ignorePeople,
|
||||||
|
allowDuplicate: false,
|
||||||
|
principalType: [PrincipalType.Users],
|
||||||
|
onPropertyChange: this.onPropertyPaneFieldChanged,
|
||||||
|
context: this.context,
|
||||||
|
properties: this.properties,
|
||||||
|
onGetErrorMessage: null,
|
||||||
|
deferredValidationTime: 0,
|
||||||
|
key: 'ignorePeople'
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,21 @@
|
||||||
|
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||||
|
|
||||||
|
.groupMembers {
|
||||||
|
color: "[theme:bodyText, default: #323130]";
|
||||||
|
color: var(--bodyText);
|
||||||
|
&.teams {
|
||||||
|
font-family: $ms-font-family-fallbacks;
|
||||||
|
}
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 4px;
|
||||||
|
|
||||||
|
.personaCard {
|
||||||
|
width: 250px;
|
||||||
|
border-radius: 2px;
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
|
.personaCard:hover {
|
||||||
|
background-color: #f3f3f3;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
import styles from './GroupMembers.module.scss';
|
||||||
|
import { IGroupMembersProps } from './IGroupMembersProps';
|
||||||
|
import { escape } from '@microsoft/sp-lodash-subset';
|
||||||
|
import { IPropertyFieldGroupOrPerson } from '@pnp/spfx-property-controls';
|
||||||
|
import { MSGraphClient } from '@microsoft/sp-http';
|
||||||
|
import * as MicrosoftGraph from "@microsoft/microsoft-graph-types";
|
||||||
|
import { PersonaSize } from 'office-ui-fabric-react';
|
||||||
|
import SPFxPeopleCard, { IPeopleCardProps } from './SPFxPeopleCard';
|
||||||
|
import { Placeholder } from '@pnp/spfx-controls-react';
|
||||||
|
|
||||||
|
|
||||||
|
export default class GroupMembers extends React.Component<IGroupMembersProps, {}> {
|
||||||
|
|
||||||
|
public state = { people: [] };
|
||||||
|
|
||||||
|
public componentDidMount() {
|
||||||
|
this.load(this.props.groups, this.props.ignorePeople);
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentWillReceiveProps(nextProps: Readonly<IGroupMembersProps>, nextContext: any): void {
|
||||||
|
this.load(nextProps.groups, nextProps.ignorePeople);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected load = (groups: IPropertyFieldGroupOrPerson[], ignorePeople: IPropertyFieldGroupOrPerson[]): void => {
|
||||||
|
this.setState({ people: [] });
|
||||||
|
this.props.context.msGraphClientFactory.getClient().then((client: MSGraphClient): void => {
|
||||||
|
groups.forEach(g => {
|
||||||
|
client.api(`/groups/${g.id.split('|')[2]}/members`).top(999).get((err, res: any) => {
|
||||||
|
if (res !== null) {
|
||||||
|
let r: MicrosoftGraph.User[] = res.value;
|
||||||
|
if (!ignorePeople) ignorePeople = [];
|
||||||
|
let p: IPeopleCardProps[] = r.filter(u => ignorePeople.filter(i => i.email.toLowerCase() === u.mail.toLowerCase()).length === 0).map(r1 => (
|
||||||
|
{
|
||||||
|
primaryText: r1.displayName,
|
||||||
|
secondaryText: r1.jobTitle,
|
||||||
|
email: r1.mail ?? r1.userPrincipalName,
|
||||||
|
serviceScope: this.props.context.serviceScope,
|
||||||
|
class: styles.personaCard,
|
||||||
|
size: PersonaSize.size40
|
||||||
|
} ));
|
||||||
|
this.setState({ people: this.state.people.concat(p).sort((a, b) => a.primaryText.localeCompare(b.primaryText)) });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public render(): React.ReactElement<IGroupMembersProps> {
|
||||||
|
const { people } = this.state;
|
||||||
|
const { hasTeamsContext } = this.props;
|
||||||
|
|
||||||
|
if (people.length === 0) return (
|
||||||
|
<Placeholder iconName='Edit' iconText='Select the group(s) to use' description='Please configure the group(s) to use' buttonLabel='Configure' onConfigure={() => this.props.context.propertyPane.open()} />
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<section className={`${styles.groupMembers} ${hasTeamsContext ? styles.teams : ''}`}>
|
||||||
|
{ people.map(p => (<SPFxPeopleCard {...p} />)) }
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { WebPartContext } from "@microsoft/sp-webpart-base";
|
||||||
|
import { IPropertyFieldGroupOrPerson } from "@pnp/spfx-property-controls";
|
||||||
|
|
||||||
|
export interface IGroupMembersProps {
|
||||||
|
groups: IPropertyFieldGroupOrPerson[];
|
||||||
|
ignorePeople: IPropertyFieldGroupOrPerson[];
|
||||||
|
context: WebPartContext;
|
||||||
|
isDarkTheme: boolean;
|
||||||
|
environmentMessage: string;
|
||||||
|
hasTeamsContext: boolean;
|
||||||
|
}
|
|
@ -0,0 +1,196 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import { SPComponentLoader } from "@microsoft/sp-loader";
|
||||||
|
import { ServiceScope, Log, Text } from "@microsoft/sp-core-library";
|
||||||
|
import { Persona, PersonaSize, IPersonaProps, PersonaInitialsColor } from "@microsoft/office-ui-fabric-react-bundle";
|
||||||
|
|
||||||
|
export interface IPeopleCardProps {
|
||||||
|
primaryText: string;
|
||||||
|
secondaryText?: string;
|
||||||
|
tertiaryText?: string;
|
||||||
|
optionalText?: string;
|
||||||
|
moreDetail?: HTMLElement | string;
|
||||||
|
email: string;
|
||||||
|
serviceScope: ServiceScope;
|
||||||
|
class: string;
|
||||||
|
size: PersonaSize;
|
||||||
|
initialsColor?: PersonaInitialsColor;
|
||||||
|
onCardOpenCallback?: Function;
|
||||||
|
onCardCloseCallback?: Function;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPeopleCardState {
|
||||||
|
pictureUrl: string;
|
||||||
|
personaCard: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
const EXP_SOURCE: string = "SPFxPeopleCardComponent";
|
||||||
|
|
||||||
|
const MD5_MODULE_ID: string = "8494e7d7-6b99-47b2-a741-59873e42f16f";
|
||||||
|
const LIVE_PERSONA_COMPONENT_ID: string = "914330ee-2df2-4f6e-a858-30c23a812408";
|
||||||
|
const DEFAULT_PERSONA_IMG_HASH: string = "7ad602295f8386b7615b582d87bcc294";
|
||||||
|
const PROFILE_IMAGE_URL: string = '/_layouts/15/userphoto.aspx?size={0}&accountname={1}';
|
||||||
|
|
||||||
|
export default class SPFxPeopleCard extends React.PureComponent<IPeopleCardProps, IPeopleCardState>{
|
||||||
|
|
||||||
|
constructor(props: any, context: any) {
|
||||||
|
super(props, context);
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
pictureUrl: null,
|
||||||
|
personaCard: null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentDidMount(): any {
|
||||||
|
const size = this.getPersonaSize();
|
||||||
|
const personaImgUrl = Text.format(PROFILE_IMAGE_URL, size, this.props.email);
|
||||||
|
|
||||||
|
this.getImageBase64(personaImgUrl).then((url: string) => {
|
||||||
|
this.getMd5HashForUrl(url).then((newHash)=>{
|
||||||
|
Log.info(EXP_SOURCE, `${url} h- ${newHash}`);
|
||||||
|
if (newHash !== DEFAULT_PERSONA_IMG_HASH) {
|
||||||
|
this.setState({ pictureUrl: "data:image/png;base64," + url });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
this.loadSPComponentById(LIVE_PERSONA_COMPONENT_ID).then((sharedLibrary: any) => {
|
||||||
|
const livePersonaCard: any = sharedLibrary.LivePersonaCard;
|
||||||
|
this.setState({ personaCard: livePersonaCard });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPersonaSize(){
|
||||||
|
let size = 'M';
|
||||||
|
if(this.props.size <= 3){
|
||||||
|
size = 'S';
|
||||||
|
}else if(this.props.size <= 6 && this.props.size > 5){
|
||||||
|
size = 'M';
|
||||||
|
}
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
private getMoreDetailElement(){
|
||||||
|
if(React.isValidElement(this.props.moreDetail)){
|
||||||
|
return React.createElement('div',
|
||||||
|
{
|
||||||
|
className: 'more-persona-details'
|
||||||
|
}, this.props.moreDetail);
|
||||||
|
}else{
|
||||||
|
return React.createElement('div',
|
||||||
|
{
|
||||||
|
className: 'more-persona-details',
|
||||||
|
dangerouslySetInnerHTML: { __html: this.props.moreDetail}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display default OfficeUIFabric Persona card if SPFx LivePersonaCard not loaded
|
||||||
|
*/
|
||||||
|
private defaultContactCard() {
|
||||||
|
return React.createElement<IPersonaProps>(Persona, {
|
||||||
|
primaryText: this.props.primaryText,
|
||||||
|
secondaryText: this.props.secondaryText,
|
||||||
|
tertiaryText: this.props.tertiaryText,
|
||||||
|
optionalText: this.props.optionalText,
|
||||||
|
imageUrl: this.state.pictureUrl,
|
||||||
|
initialsColor: this.props.initialsColor ? this.props.initialsColor : "#808080",
|
||||||
|
className: this.props.class,
|
||||||
|
size: this.props.size,
|
||||||
|
imageShouldFadeIn: false,
|
||||||
|
imageShouldStartVisible: true
|
||||||
|
}, this.getMoreDetailElement());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure SPFx LivePersona card from SPFx component loader
|
||||||
|
*/
|
||||||
|
private spfxLiverPersonaCard() {
|
||||||
|
return React.createElement(this.state.personaCard, {
|
||||||
|
className: 'people',
|
||||||
|
clientScenario: "PeopleWebPart",
|
||||||
|
disableHover: false,
|
||||||
|
hostAppPersonaInfo: {
|
||||||
|
PersonaType: "User"
|
||||||
|
},
|
||||||
|
serviceScope: this.props.serviceScope,
|
||||||
|
upn: this.props.email,
|
||||||
|
onCardOpen: () => {
|
||||||
|
if(this.props.onCardOpenCallback){
|
||||||
|
this.props.onCardOpenCallback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onCardClose: () => {
|
||||||
|
if(this.props.onCardCloseCallback){
|
||||||
|
this.props.onCardCloseCallback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, this.defaultContactCard());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get MD5Hash for the image url to verify whether user has default image or custom image
|
||||||
|
* @param url
|
||||||
|
*/
|
||||||
|
private getMd5HashForUrl(url: string) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.loadSPComponentById(MD5_MODULE_ID).then((library: any) => {
|
||||||
|
const md5Hash = library.Md5Hash;
|
||||||
|
if (md5Hash) {
|
||||||
|
const convertedHash = md5Hash(url);
|
||||||
|
resolve(convertedHash);
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
Log.error(EXP_SOURCE, error, this.props.serviceScope);
|
||||||
|
resolve(url);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private getImageBase64(pictureUrl: string) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let image = new Image();
|
||||||
|
image.addEventListener("load", () => {
|
||||||
|
let tempCanvas = document.createElement("canvas");
|
||||||
|
tempCanvas.width = image.width,
|
||||||
|
tempCanvas.height = image.height,
|
||||||
|
tempCanvas.getContext("2d").drawImage(image, 0, 0);
|
||||||
|
let base64Str;
|
||||||
|
try {
|
||||||
|
base64Str = tempCanvas.toDataURL("image/png");
|
||||||
|
} catch (e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
base64Str = base64Str.replace(/^data:image\/png;base64,/, "");
|
||||||
|
resolve(base64Str);
|
||||||
|
});
|
||||||
|
image.src = pictureUrl;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load SPFx component by id, SPComponentLoader is used to load the SPFx components
|
||||||
|
* @param componentId - componentId, guid of the component library
|
||||||
|
*/
|
||||||
|
private loadSPComponentById(componentId: string) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
SPComponentLoader.loadComponentById(componentId).then((component: any) => {
|
||||||
|
resolve(component);
|
||||||
|
}).catch((error) => {
|
||||||
|
Log.error(EXP_SOURCE, error, this.props.serviceScope);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(): JSX.Element {
|
||||||
|
return (
|
||||||
|
<div className={this.props.class}>
|
||||||
|
{
|
||||||
|
this.state.personaCard ? this.spfxLiverPersonaCard() : this.defaultContactCard()
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
define([], function() {
|
||||||
|
return {
|
||||||
|
"PropertyPaneDescription": "Description",
|
||||||
|
"BasicGroupName": "Group Name",
|
||||||
|
"DescriptionFieldLabel": "Description Field",
|
||||||
|
"AppLocalEnvironmentSharePoint": "The app is running on your local environment as SharePoint web part",
|
||||||
|
"AppLocalEnvironmentTeams": "The app is running on your local environment as Microsoft Teams app",
|
||||||
|
"AppSharePointEnvironment": "The app is running on SharePoint page",
|
||||||
|
"AppTeamsTabEnvironment": "The app is running in Microsoft Teams"
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,14 @@
|
||||||
|
declare interface IGroupMembersWebPartStrings {
|
||||||
|
PropertyPaneDescription: string;
|
||||||
|
BasicGroupName: string;
|
||||||
|
DescriptionFieldLabel: string;
|
||||||
|
AppLocalEnvironmentSharePoint: string;
|
||||||
|
AppLocalEnvironmentTeams: string;
|
||||||
|
AppSharePointEnvironment: string;
|
||||||
|
AppTeamsTabEnvironment: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'GroupMembersWebPartStrings' {
|
||||||
|
const strings: IGroupMembersWebPartStrings;
|
||||||
|
export = strings;
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
After Width: | Height: | Size: 542 B |
|
@ -0,0 +1,35 @@
|
||||||
|
{
|
||||||
|
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.9/includes/tsconfig-web.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "es5",
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"jsx": "react",
|
||||||
|
"declaration": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"outDir": "lib",
|
||||||
|
"inlineSources": false,
|
||||||
|
"strictNullChecks": false,
|
||||||
|
"noUnusedLocals": false,
|
||||||
|
"typeRoots": [
|
||||||
|
"./node_modules/@types",
|
||||||
|
"./node_modules/@microsoft"
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
"webpack-env"
|
||||||
|
],
|
||||||
|
"lib": [
|
||||||
|
"es5",
|
||||||
|
"dom",
|
||||||
|
"es2015.collection",
|
||||||
|
"es2015.promise"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts",
|
||||||
|
"src/**/*.tsx"
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"extends": "./node_modules/@microsoft/sp-tslint-rules/base-tslint.json",
|
||||||
|
"rules": {
|
||||||
|
"class-name": false,
|
||||||
|
"export-name": false,
|
||||||
|
"forin": false,
|
||||||
|
"label-position": false,
|
||||||
|
"member-access": true,
|
||||||
|
"no-arg": false,
|
||||||
|
"no-console": false,
|
||||||
|
"no-construct": false,
|
||||||
|
"no-duplicate-variable": true,
|
||||||
|
"no-eval": false,
|
||||||
|
"no-function-expression": true,
|
||||||
|
"no-internal-module": true,
|
||||||
|
"no-shadowed-variable": true,
|
||||||
|
"no-switch-case-fall-through": true,
|
||||||
|
"no-unnecessary-semicolons": true,
|
||||||
|
"no-unused-expression": true,
|
||||||
|
"no-with-statement": true,
|
||||||
|
"semicolon": true,
|
||||||
|
"trailing-comma": false,
|
||||||
|
"typedef": false,
|
||||||
|
"typedef-whitespace": false,
|
||||||
|
"use-named-parameter": true,
|
||||||
|
"variable-name": false,
|
||||||
|
"whitespace": false
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue