Update React-Directory new features and fix issue #931 (#937)

* Add OrderBy and new propertie

* update docs

* Update README.md

* Fix misspelling
This commit is contained in:
joaojmendes 2019-08-13 09:07:43 +01:00 committed by Vesa Juvonen
parent ee2c492867
commit 883342f7a7
49 changed files with 483 additions and 255 deletions

View File

@ -12,7 +12,7 @@ import {
import * as strings from 'BirthdaysWebPartStrings'; import * as strings from 'BirthdaysWebPartStrings';
import Birdthays from './components/Birthdays'; import Birthdays from './components/Birthdays';
import { IBirthdaysProps } from './components/IBirthdaysProps'; import { IBirthdaysProps } from './components/IBirthdaysProps';
import { MSGraphClient } from '@microsoft/sp-http'; import { MSGraphClient } from '@microsoft/sp-http';
@ -100,7 +100,7 @@ export default class BirthdaysWebPart extends BaseClientSideWebPart<IBirthdaysWe
public render(): void { public render(): void {
const element: React.ReactElement<IBirthdaysProps> = React.createElement( const element: React.ReactElement<IBirthdaysProps> = React.createElement(
Birdthays, Birthdays,
{ {
title: this.properties.title, title: this.properties.title,
numberUpcomingDays: this.properties.numberUpcomingDays, numberUpcomingDays: this.properties.numberUpcomingDays,

0
samples/react-directory/.editorconfig Normal file → Executable file
View File

0
samples/react-directory/.gitignore vendored Normal file → Executable file
View File

0
samples/react-directory/.yo-rc.json Normal file → Executable file
View File

6
samples/react-directory/README.md Normal file → Executable file
View File

@ -6,6 +6,12 @@
## ##
![directory](/samples/react-directory/assets/react-directory7.png)
![directory](/samples/react-directory/assets/react-directory8.png)
![directory](/samples/react-directory/assets/react-directory9.png)
![directory](/samples/react-directory/assets/react-directory.jpg) ![directory](/samples/react-directory/assets/react-directory.jpg)
![directory](/samples/react-directory/assets/react-directory-teams1.jpg) ![directory](/samples/react-directory/assets/react-directory-teams1.jpg)

View File

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View File

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 136 KiB

View File

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 119 KiB

0
samples/react-directory/assets/react-directory.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 140 KiB

0
samples/react-directory/assets/react-directory2.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 158 KiB

After

Width:  |  Height:  |  Size: 158 KiB

0
samples/react-directory/assets/react-directory21.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 428 KiB

After

Width:  |  Height:  |  Size: 428 KiB

0
samples/react-directory/assets/react-directory3.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 133 KiB

0
samples/react-directory/assets/react-directory5.jpg Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 161 KiB

After

Width:  |  Height:  |  Size: 161 KiB

0
samples/react-directory/assets/react-directory6.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 442 KiB

After

Width:  |  Height:  |  Size: 442 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

0
samples/react-directory/azure-pipelines.yml Normal file → Executable file
View File

0
samples/react-directory/config/config.json Normal file → Executable file
View File

0
samples/react-directory/config/copy-assets.json Normal file → Executable file
View File

View File

0
samples/react-directory/config/jest.config.json Normal file → Executable file
View File

0
samples/react-directory/config/package-solution.json Normal file → Executable file
View File

0
samples/react-directory/config/serve.json Normal file → Executable file
View File

0
samples/react-directory/config/write-manifests.json Normal file → Executable file
View File

0
samples/react-directory/gulpfile.js vendored Normal file → Executable file
View File

0
samples/react-directory/package-lock.json generated Normal file → Executable file
View File

0
samples/react-directory/package.json Normal file → Executable file
View File

View File

13
samples/react-directory/src/SPServices/spservices.ts Normal file → Executable file
View File

@ -53,19 +53,18 @@ user:string */
} }
} }
public async searchUsers(searchString: string) { public async searchUsers(searchString: string, searchFirstName:boolean) {
const s = `LastName:${searchString}* OR FirstName:${searchString}* OR Department:${searchString}`; const _search = !searchFirstName ? `LastName:${searchString}*` : `FirstName:${searchString}*` ;
const searchProperties: string[] = ["FirstName", "LastName", "PreferredName", "WorkEmail", "PictureURL", "WorkPhone", "MobilePhone", "JobTitle", "Department", "Skills", "PastProjects"]; const searchProperties: string[] = ["FirstName", "LastName", "PreferredName", "WorkEmail", "OfficeNumber","PictureURL", "WorkPhone", "MobilePhone", "JobTitle", "Department", "Skills", "PastProjects", "BaseOfficeLocation", "SPS-UserType","GroupId"];
try { try {
if (!searchString) return undefined; if (!searchString) return undefined;
let users = await sp.searchWithCaching(<SearchQuery>{ let users = await sp.searchWithCaching(<SearchQuery>{
Querytext: s, Querytext: _search,
RowLimit: 500, RowLimit:500,
EnableInterleaving: true, EnableInterleaving: true,
SelectProperties: searchProperties, SelectProperties: searchProperties,
SourceId: 'b09a7990-05ea-4af9-81ef-edfab16c4e31', SourceId: 'b09a7990-05ea-4af9-81ef-edfab16c4e31',
SortList: [{ "Property": "LastName", "Direction": SortDirection.Ascending }] SortList: [{ "Property": "LastName", "Direction": SortDirection.Ascending }],
}); });
return users; return users;

0
samples/react-directory/src/index.ts Normal file → Executable file
View File

View File

@ -21,7 +21,8 @@
"description": { "default": "Search Directory" }, "description": { "default": "Search Directory" },
"officeFabricIconFontName": "ProfileSearch", "officeFabricIconFontName": "ProfileSearch",
"properties": { "properties": {
"title": "Directory" "title": "Directory",
"searchFirstName": 0
} }
}] }]
} }

View File

@ -1,30 +1,34 @@
import * as React from 'react'; import * as React from "react";
import * as ReactDom from 'react-dom'; import * as ReactDom from "react-dom";
import { Version } from '@microsoft/sp-core-library'; import { Version } from "@microsoft/sp-core-library";
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base'; import { BaseClientSideWebPart } from "@microsoft/sp-webpart-base";
import { DisplayMode } from '@microsoft/sp-core-library'; import { DisplayMode } from "@microsoft/sp-core-library";
import { import {
IPropertyPaneConfiguration, IPropertyPaneConfiguration,
PropertyPaneTextField PropertyPaneTextField,
} from '@microsoft/sp-property-pane'; PropertyPaneToggle,
IPropertyPaneToggleProps
import * as strings from 'DirectoryWebPartStrings'; } from "@microsoft/sp-property-pane";
import Directory from './components/Directory';
import { IDirectoryProps } from './components/IDirectoryProps';
import * as strings from "DirectoryWebPartStrings";
import Directory from "./components/Directory";
import { IDirectoryProps } from "./components/IDirectoryProps";
export interface IDirectoryWebPartProps { export interface IDirectoryWebPartProps {
title: string; title: string;
searchFirstName: boolean;
} }
export default class DirectoryWebPart extends BaseClientSideWebPart<IDirectoryWebPartProps> { export default class DirectoryWebPart extends BaseClientSideWebPart<
IDirectoryWebPartProps
> {
public render(): void { public render(): void {
const element: React.ReactElement<IDirectoryProps> = React.createElement( const element: React.ReactElement<IDirectoryProps> = React.createElement(
Directory, Directory,
{ {
title: this.properties.title, title: this.properties.title,
context: this.context, context: this.context,
searchFirstName: this.properties.searchFirstName,
displayMode: this.displayMode, displayMode: this.displayMode,
updateProperty: (value: string) => { updateProperty: (value: string) => {
this.properties.title = value; this.properties.title = value;
@ -40,7 +44,7 @@ export default class DirectoryWebPart extends BaseClientSideWebPart<IDirectoryWe
} }
protected get dataVersion(): Version { protected get dataVersion(): Version {
return Version.parse('1.0'); return Version.parse("1.0");
} }
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration { protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
@ -54,8 +58,12 @@ export default class DirectoryWebPart extends BaseClientSideWebPart<IDirectoryWe
{ {
groupName: strings.BasicGroupName, groupName: strings.BasicGroupName,
groupFields: [ groupFields: [
PropertyPaneTextField('title', { PropertyPaneTextField("title", {
label: strings.TitleFieldLabel label: strings.TitleFieldLabel
}),
PropertyPaneToggle("searchFirstName", {
checked: false,
label: "Search on First Name ?"
}) })
] ]
} }

View File

@ -1,23 +1,32 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss'; @import "~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss";
.directory { .directory {
.dropDownSortBy {
margin-top: 35px;
margin-bottom: 15px;
}
.searchBox {
width: "100%";
vertical-align: "middle";
margin-bottom: 25;
}
.noUsers {
margin-left: "auto";
margin-right: "auto";
text-align: "center";
padding-top: 40px;
}
.pivotItem { .pivotItem {
overflow-wrap: break-word; overflow-wrap: break-word;
} }
.pivotItem:hover { .pivotItem:hover {
border-style: solid; border-style: solid;
border-width: 1.2; border-width: 1.2;
border-color: $ms-color-themeDark; border-color: $ms-color-themeDark;
} }
.container { .container {
max-width: 700px; max-width: 700px;
margin: 0px auto; margin: 0px auto;
@ -68,7 +77,8 @@
// Basic Button // Basic Button
outline: transparent; outline: transparent;
position: relative; position: relative;
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif; font-family: "Segoe UI WestEuropean", "Segoe UI", -apple-system,
BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
font-size: $ms-font-size-m; font-size: $ms-font-size-m;
font-weight: $ms-font-weight-regular; font-weight: $ms-font-weight-regular;

View File

@ -1,12 +1,12 @@
import * as React from 'react'; import * as React from "react";
import styles from './Directory.module.scss'; import styles from "./Directory.module.scss";
import { IDirectoryProps } from './IDirectoryProps'; import { IDirectoryProps } from "./IDirectoryProps";
import { escape } from '@microsoft/sp-lodash-subset'; import { escape } from "@microsoft/sp-lodash-subset";
import { PersonaCard } from './PersonaCard/PersonaCard'; import { PersonaCard } from "./PersonaCard/PersonaCard";
import { spservices } from '../../../SPServices/spservices'; import { spservices } from "../../../SPServices/spservices";
import { IDirectoryState } from './IDirectoryState'; import { IDirectoryState } from "./IDirectoryState";
import { DisplayMode } from '@microsoft/sp-core-library'; import { DisplayMode } from "@microsoft/sp-core-library";
import * as strings from 'DirectoryWebPartStrings'; import * as strings from "DirectoryWebPartStrings";
import { import {
Spinner, Spinner,
SpinnerSize, SpinnerSize,
@ -18,19 +18,57 @@ import {
Pivot, Pivot,
PivotItem, PivotItem,
PivotLinkFormat, PivotLinkFormat,
PivotLinkSize PivotLinkSize,
} Dropdown,
from 'office-ui-fabric-react'; DropdownMenuItemType,
import { IProfileProperties } from '../../../SPServices/IProfileProperties'; IDropdownStyles,
import { PeoplePickerEntity, Search, SearchResult } from '@pnp/sp'; IDropdownOption
} from "office-ui-fabric-react";
import { IProfileProperties } from "../../../SPServices/IProfileProperties";
import { PeoplePickerEntity, Search, SearchResult } from "@pnp/sp";
import { WebPartTitle } from "@pnp/spfx-controls-react/lib/WebPartTitle"; import { WebPartTitle } from "@pnp/spfx-controls-react/lib/WebPartTitle";
import { Root } from '@pnp/graph'; import { Root } from "@pnp/graph";
import { IUserProperties } from './PersonaCard/IUserProperties'; import { IUserProperties } from "./PersonaCard/IUserProperties";
const az: string[] = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
export default class Directory extends React.Component<IDirectoryProps, IDirectoryState> {
const az: string[] = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z"
];
const orderOptions: IDropdownOption[] = [
{ key: "FirstName", text: "First Name" },
{ key: "LastName", text: "Last Name" },
{ key: "Department", text: "Department" },
{ key: "Location", text: "Location" },
{ key: "JobTitle", text: "Job Title" }
];
export default class Directory extends React.Component<
IDirectoryProps,
IDirectoryState
> {
private _services: spservices = null; private _services: spservices = null;
constructor(props: IDirectoryProps) { constructor(props: IDirectoryProps) {
@ -39,39 +77,53 @@ export default class Directory extends React.Component<IDirectoryProps, IDirecto
this.state = { this.state = {
users: [], users: [],
isLoading: true, isLoading: true,
errorMessage: '', errorMessage: "",
hasError: false, hasError: false,
indexSelectedKey: 'A', indexSelectedKey: "A",
searchString: '' searchString: "LastName"
}; };
this._services = new spservices(this.props.context); this._services = new spservices(this.props.context);
// Register event handlers // Register event handlers
this._searchUsers = this._searchUsers.bind(this); this._searchUsers = this._searchUsers.bind(this);
this._selectedIndex = this._selectedIndex.bind(this); this._selectedIndex = this._selectedIndex.bind(this);
this._sortPeople = this._sortPeople.bind(this);
} }
/** /**
* *
* *
* @memberof Directory * @memberof Directory
*/ */
public async componentDidMount() { public async componentDidMount() {
await this._searchUsers('A'); await this._searchUsers("A");
} }
private async _searchUsers(searchText: string) { private async _searchUsers(searchText: string) {
searchText = searchText ? searchText : 'A'; searchText = searchText.trim().length > 0 ? searchText : "A";
this.setState({ isLoading: true, indexSelectedKey: searchText.substring(0, 1).toLocaleUpperCase() }); this.setState({
isLoading: true,
indexSelectedKey: searchText.substring(0, 1).toLocaleUpperCase(),
searchString: "LastName"
});
try { try {
const users = await this._services.searchUsers(searchText); const users = await this._services.searchUsers(
this.setState({ users: users && users.PrimarySearchResults ? users.PrimarySearchResults : null, isLoading: false, errorMessage: '', hasError: false }); searchText,
this.props.searchFirstName
);
this.setState({
users:
users && users.PrimarySearchResults
? users.PrimarySearchResults
: null,
isLoading: false,
errorMessage: "",
hasError: false
});
} catch (error) { } catch (error) {
this.setState({ errorMessage: error.message, hasError: true }); this.setState({ errorMessage: error.message, hasError: true });
} }
} }
/** /**
@ -81,11 +133,105 @@ export default class Directory extends React.Component<IDirectoryProps, IDirecto
* @param {IDirectoryState} prevState * @param {IDirectoryState} prevState
* @memberof Directory * @memberof Directory
*/ */
public componentDidUpdate(prevProps: IDirectoryProps, prevState: IDirectoryState): void { public async componentDidUpdate(
prevProps: IDirectoryProps,
prevState: IDirectoryState
) {
if (
this.props.title != prevProps.title ||
this.props.searchFirstName != prevProps.searchFirstName
) {
await this._searchUsers("A");
}
} }
/**
*
*
* @private
* @param {string} sortField
* @memberof Directory
*/
private async _sortPeople(sortField: string) {
let _users = this.state.users;
_users = _users.sort((a: any, b: any) => {
switch (sortField) {
// Sorte by FirstName
case "FirstName":
const aFirstName = a.FirstName ? a.FirstName : "";
const bFirstName = b.FirstName ? b.FirstName : "";
if (aFirstName.toUpperCase() < bFirstName.toUpperCase()) {
return -1;
}
if (aFirstName.toUpperCase() > bFirstName.toUpperCase()) {
return 1;
}
return 0;
break;
// Sort by LastName
case "LastName":
const aLastName = a.LastName ? a.LastName : "";
const bLastName = b.LastName ? b.LastName : "";
if (aLastName.toUpperCase() < bLastName.toUpperCase()) {
return -1;
}
if (aLastName.toUpperCase() > bLastName.toUpperCase()) {
return 1;
}
return 0;
break;
// Sort by Location
case "Location":
const aBaseOfficeLocation = a.BaseOfficeLocation
? a.BaseOfficeLocation
: "";
const bBaseOfficeLocation = b.BaseOfficeLocation
? b.BaseOfficeLocation
: "";
if (
aBaseOfficeLocation.toUpperCase() <
bBaseOfficeLocation.toUpperCase()
) {
return -1;
}
if (
aBaseOfficeLocation.toUpperCase() >
bBaseOfficeLocation.toUpperCase()
) {
return 1;
}
return 0;
break;
// Sort by JobTitle
case "JobTitle":
const aJobTitle = a.JobTitle ? a.JobTitle : "";
const bJobTitle = b.JobTitle ? b.JobTitle : "";
if (aJobTitle.toUpperCase() < bJobTitle.toUpperCase()) {
return -1;
}
if (aJobTitle.toUpperCase() > bJobTitle.toUpperCase()) {
return 1;
}
return 0;
break;
// Sort by Department
case "Department":
const aDepartment = a.Department ? a.Department : "";
const bDepartment = b.Department ? b.Department : "";
if (aDepartment.toUpperCase() < bDepartment.toUpperCase()) {
return -1;
}
if (aDepartment.toUpperCase() > bDepartment.toUpperCase()) {
return 1;
}
return 0;
break;
default:
break;
}
});
this.setState({ users: _users, searchString: sortField });
}
/** /**
* *
* *
@ -95,7 +241,6 @@ export default class Directory extends React.Component<IDirectoryProps, IDirecto
* @memberof Directory * @memberof Directory
*/ */
private _selectedIndex(item?: PivotItem, ev?: React.MouseEvent<HTMLElement>) { private _selectedIndex(item?: PivotItem, ev?: React.MouseEvent<HTMLElement>) {
this._searchUsers(item.props.itemKey); this._searchUsers(item.props.itemKey);
} }
/** /**
@ -105,76 +250,112 @@ export default class Directory extends React.Component<IDirectoryProps, IDirecto
* @memberof Directory * @memberof Directory
*/ */
public render(): React.ReactElement<IDirectoryProps> { public render(): React.ReactElement<IDirectoryProps> {
const color = this.props.context.microsoftTeams ? 'white' : ''; const color = this.props.context.microsoftTeams ? "white" : "";
const diretoryGrid =
this.state.users && this.state.users.length > 0
? this.state.users.map((user: any) => {
return (
<PersonaCard
context={this.props.context}
profileProperties={{
DisplayName: user.PreferredName,
Title: user.JobTitle,
PictureUrl: user.PictureURL,
Email: user.WorkEmail,
Department: user.Department,
WorkPhone: user.WorkPhone,
Location: user.OfficeNumber
? user.OfficeNumber
: user.BaseOfficeLocation
}}
/>
);
})
: [];
return ( return (
<div className={styles.directory}> <div className={styles.directory}>
<WebPartTitle displayMode={this.props.displayMode} <WebPartTitle
displayMode={this.props.displayMode}
title={this.props.title} title={this.props.title}
updateProperty={this.props.updateProperty} /> updateProperty={this.props.updateProperty}
/>
<div style={{ width: '100%', verticalAlign: 'middle', marginBottom: 40 }}> <div className={styles.searchBox}>
<SearchBox <SearchBox
placeholder={strings.SearchPlaceHolder} placeholder={strings.SearchPlaceHolder}
styles={{ root: { minWidth: 180, width: 360, marginLeft: 'auto', marginRight: 'auto', marginBottom: 25 } }} styles={{
root: {
minWidth: 180,
maxWidth: 300,
marginLeft: "auto",
marginRight: "auto",
marginBottom: 25
}
}}
onSearch={this._searchUsers} onSearch={this._searchUsers}
onClear={() => { this._searchUsers('A'); }} onClear={() => {
onChange={this._searchUsers} /> this._searchUsers("A");
}}
onChange={this._searchUsers}
/>
<div> <div>
<Pivot <Pivot
styles={{ root: { paddingLeft: 10, paddingRight: 10, whiteSpace: 'normal', textAlign: 'center' } }} styles={{
root: {
paddingLeft: 10,
paddingRight: 10,
whiteSpace: "normal",
textAlign: "center"
}
}}
linkFormat={PivotLinkFormat.tabs} linkFormat={PivotLinkFormat.tabs}
selectedKey={this.state.indexSelectedKey} selectedKey={this.state.indexSelectedKey}
onLinkClick={this._selectedIndex} onLinkClick={this._selectedIndex}
linkSize={PivotLinkSize.normal}> linkSize={PivotLinkSize.normal}
{ >
az.map((index) => { {az.map((index: string) => {
return ( return (
<PivotItem <PivotItem headerText={index} itemKey={index} key={index} />
headerText={index} );
itemKey={index} })}
key={index} >
</PivotItem>
);
})
}
</Pivot> </Pivot>
</div> </div>
</div> </div>
{ {!this.state.users || this.state.users.length == 0 ? (
!this.state.users || this.state.users.length == 0 ? <div className={styles.noUsers}>
<div style={{ marginLeft: 'auto', marginRight: 'auto', textAlign: 'center' }}> <Icon
<Icon iconName={'ProfileSearch'} style={{ fontSize: '54px', color: color }} /> iconName={"ProfileSearch"}
<Label> style={{ fontSize: "54px", color: color }}
<span style={{ marginLeft: 5, fontSize: '26px', color: color }}>{strings.DirectoryMessage}</span> />
</Label> <Label>
</div> <span style={{ marginLeft: 5, fontSize: "26px", color: color }}>
: {strings.DirectoryMessage}
this.state.isLoading ? </span>
<Spinner size={SpinnerSize.large} label={'searching ...'}></Spinner> </Label>
: </div>
this.state.hasError ? ) : this.state.isLoading ? (
<MessageBar messageBarType={MessageBarType.error}>{this.state.errorMessage}</MessageBar> <Spinner size={SpinnerSize.large} label={"searching ..."} />
: ) : this.state.hasError ? (
this.state.users.map((user: any) => { <MessageBar messageBarType={MessageBarType.error}>
return ( {this.state.errorMessage}
<PersonaCard </MessageBar>
context={this.props.context} ) : (
profileProperties={{ <div className={styles.dropDownSortBy}>
DisplayName: user.PreferredName, <Dropdown
Title: user.JobTitle, placeholder={strings.DropDownPlaceHolderMessage}
PictureUrl: user.PictureURL, label={strings.DropDownPlaceLabelMessage}
Email: user.WorkEmail, options={orderOptions}
Department: user.Department, selectedKey={this.state.searchString}
WorkPhone: user.WorkPhone onChange={(ev: any, value: IDropdownOption) => {
}}> this._sortPeople(value.key.toString());
</PersonaCard> }}
); styles={{ dropdown: { width: 200 } }}
}) />
} <div>{diretoryGrid}</div>
</div>
)}
</div> </div>
); );
} }

View File

@ -1,8 +1,9 @@
import { WebPartContext } from "@microsoft/sp-webpart-base"; import { WebPartContext } from "@microsoft/sp-webpart-base";
import { DisplayMode } from '@microsoft/sp-core-library'; import { DisplayMode } from "@microsoft/sp-core-library";
export interface IDirectoryProps { export interface IDirectoryProps {
title: string; title: string;
displayMode: DisplayMode; displayMode: DisplayMode;
context: WebPartContext; context: WebPartContext;
searchFirstName: boolean;
updateProperty: (value: string) => void; updateProperty: (value: string) => void;
} }

View File

@ -1,10 +1,10 @@
import { IProfileProperties} from './../../../SPServices/IProfileProperties'; import { IProfileProperties } from "./../../../SPServices/IProfileProperties";
import { PeoplePickerEntity, SearchResult, SearchResults } from '@pnp/pnpjs'; import { PeoplePickerEntity, SearchResult, SearchResults } from "@pnp/pnpjs";
export interface IDirectoryState { export interface IDirectoryState {
users:any; users: any;
isLoading: boolean; isLoading: boolean;
errorMessage:string; errorMessage: string;
hasError:boolean; hasError: boolean;
indexSelectedKey: string; indexSelectedKey: string;
searchString:string; searchString: string;
} }

View File

@ -1,9 +1,9 @@
import { WebPartContext } from "@microsoft/sp-webpart-base"; import { WebPartContext } from "@microsoft/sp-webpart-base";
import { ApplicationCustomizerContext } from "@microsoft/sp-application-base"; import { ApplicationCustomizerContext } from "@microsoft/sp-application-base";
import {IUserProperties} from './IUserProperties'; import { IUserProperties } from "./IUserProperties";
import { PeoplePickerEntity, SearchResult , SearchResults} from '@pnp/pnpjs'; import { PeoplePickerEntity, SearchResult, SearchResults } from "@pnp/pnpjs";
export interface IPersonaCardProps { export interface IPersonaCardProps {
context: WebPartContext | ApplicationCustomizerContext; context: WebPartContext | ApplicationCustomizerContext;
profileProperties : IUserProperties; profileProperties: IUserProperties;
} }

View File

@ -1,4 +1,4 @@
export interface IPersonaCardState { export interface IPersonaCardState {
livePersonaCard: any; livePersonaCard: any;
pictureUrl:string; pictureUrl: string;
} }

View File

@ -4,6 +4,7 @@ export interface IUserProperties {
PictureUrl: string; PictureUrl: string;
Title: string; Title: string;
DisplayName: string; DisplayName: string;
Email:string; Email: string;
WorkPhone?: string; WorkPhone?: string;
Location?: string;
} }

View File

@ -1,17 +1,19 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss'; @import "~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss";
.personaContainer { .personaContainer {
display:inline-block; display: inline-block;
margin-top: 15px; margin-top: 15px;
margin-right: 15px; margin-right: 15px;
width: 350px;
min-width: 300; min-width: 300;
vertical-align: top; vertical-align: top;
} }
.documentCard { .documentCard {
border-color: $ms-color-themeDark; border-color: $ms-color-themeDark;
border-top-width: 5px; border-top-width: 5px;
width: 100%, width: 100%;
max-width: 350px;
height: 120px;
} }
.persona { .persona {
padding: 15px; padding: 15px;
@ -21,5 +23,5 @@ vertical-align: top;
background-color: $ms-color-themeDark; background-color: $ms-color-themeDark;
height: 5px; height: 5px;
margin-top: 10; margin-top: 10;
width: 100%; width: 100%;
} }

View File

@ -1,8 +1,15 @@
import * as React from 'react'; import * as React from "react";
import styles from './PersonaCard.module.scss'; import styles from "./PersonaCard.module.scss";
import { IPersonaCardProps } from './IPersonaCardProps'; import { IPersonaCardProps } from "./IPersonaCardProps";
import { IPersonaCardState } from './IPersonaCardState'; import { IPersonaCardState } from "./IPersonaCardState";
import { Version, Environment, EnvironmentType, ServiceScope, Log, Text } from "@microsoft/sp-core-library"; import {
Version,
Environment,
EnvironmentType,
ServiceScope,
Log,
Text
} from "@microsoft/sp-core-library";
import { SPComponentLoader } from "@microsoft/sp-loader"; import { SPComponentLoader } from "@microsoft/sp-loader";
import { import {
@ -16,15 +23,17 @@ import {
IDocumentCardStyles, IDocumentCardStyles,
DocumentCardType, DocumentCardType,
Icon Icon
} } from "office-ui-fabric-react";
from 'office-ui-fabric-react';
const EXP_SOURCE: string = "SPFxDirectory"; const EXP_SOURCE: string = "SPFxDirectory";
const LIVE_PERSONA_COMPONENT_ID: string = "914330ee-2df2-4f6e-a858-30c23a812408"; const LIVE_PERSONA_COMPONENT_ID: string =
"914330ee-2df2-4f6e-a858-30c23a812408";
//const PROFILE_IMAGE_URL: string = 'https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email={0}&UA=0&size=HR96x96&sc=1564597822258'; //const PROFILE_IMAGE_URL: string = 'https://outlook.office365.com/owa/service.svc/s/GetPersonaPhoto?email={0}&UA=0&size=HR96x96&sc=1564597822258';
export class PersonaCard extends React.Component<IPersonaCardProps, IPersonaCardState> { export class PersonaCard extends React.Component<
IPersonaCardProps,
IPersonaCardState
> {
constructor(props: IPersonaCardProps) { constructor(props: IPersonaCardProps) {
super(props); super(props);
this.state = { livePersonaCard: undefined, pictureUrl: undefined }; this.state = { livePersonaCard: undefined, pictureUrl: undefined };
@ -35,13 +44,14 @@ export class PersonaCard extends React.Component<IPersonaCardProps, IPersonaCard
* @memberof PersonaCard * @memberof PersonaCard
*/ */
public async componentDidMount() { public async componentDidMount() {
const sharedLibrary = await this._loadSPComponentById(
const sharedLibrary = await this.loadSPComponentById(LIVE_PERSONA_COMPONENT_ID); LIVE_PERSONA_COMPONENT_ID
);
const livePersonaCard: any = sharedLibrary.LivePersonaCard; const livePersonaCard: any = sharedLibrary.LivePersonaCard;
this.setState( {livePersonaCard: livePersonaCard }); console.log(livePersonaCard);
this.setState({ livePersonaCard: livePersonaCard });
} }
/** /**
* *
* *
@ -49,10 +59,10 @@ export class PersonaCard extends React.Component<IPersonaCardProps, IPersonaCard
* @param {IPersonaCardState} prevState * @param {IPersonaCardState} prevState
* @memberof PersonaCard * @memberof PersonaCard
*/ */
public componentDidUpdate(prevProps: IPersonaCardProps, prevState: IPersonaCardState): void { public componentDidUpdate(
prevProps: IPersonaCardProps,
} prevState: IPersonaCardState
): void {}
/** /**
* *
@ -62,24 +72,22 @@ export class PersonaCard extends React.Component<IPersonaCardProps, IPersonaCard
* @memberof PersonaCard * @memberof PersonaCard
*/ */
private _LivePersonaCard() { private _LivePersonaCard() {
return React.createElement(
return React.createElement(this.state.livePersonaCard, { this.state.livePersonaCard,
className: '', {
clientScenario: "PeopleWebPart", serviceScope: this.props.context.serviceScope,
disableHover: false, upn: this.props.profileProperties.Email,
hostAppPersonaInfo: { onCardOpen: () => {
PersonaType: "User" console.log("LivePersonaCard Open");
},
onCardClose: () => {
console.log("LivePersonaCard Close");
}
}, },
serviceScope: this.props.context.serviceScope, this._PersonaCard()
upn: this.props.profileProperties.Email, );
onCardOpen: () => {
},
onCardClose: () => {
}
}, this._PersonaCard());
} }
/** /**
* *
* *
@ -89,8 +97,10 @@ export class PersonaCard extends React.Component<IPersonaCardProps, IPersonaCard
*/ */
private _PersonaCard(): JSX.Element { private _PersonaCard(): JSX.Element {
return ( return (
<DocumentCard className={styles.documentCard} type={DocumentCardType.normal} style={{maxWidth: 350}}> <DocumentCard
className={styles.documentCard}
type={DocumentCardType.normal}
>
<div className={styles.persona}> <div className={styles.persona}>
<Persona <Persona
text={this.props.profileProperties.DisplayName} text={this.props.profileProperties.DisplayName}
@ -99,43 +109,51 @@ export class PersonaCard extends React.Component<IPersonaCardProps, IPersonaCard
imageUrl={this.props.profileProperties.PictureUrl} imageUrl={this.props.profileProperties.PictureUrl}
size={PersonaSize.size72} size={PersonaSize.size72}
imageShouldFadeIn={false} imageShouldFadeIn={false}
imageShouldStartVisible={true}> imageShouldStartVisible={true}
<Label> >
{ {this.props.profileProperties.WorkPhone ? (
this.props.profileProperties.WorkPhone ? <div>
<div> <Icon iconName="Phone" style={{ fontSize: "12px" }} />
<Icon iconName='Phone' style={{ fontSize: '12px' }}/> <span style={{ marginLeft: 5, fontSize: "12px" }}>
<span style={{ marginLeft: 5, fontSize: '12px' }}> {this.props.profileProperties.WorkPhone}</span> {" "}
</div> {this.props.profileProperties.WorkPhone}
: </span>
'' </div>
} ) : (
""
</Label> )}
{this.props.profileProperties.Location ? (
<div>
<Icon iconName="Poi" style={{ fontSize: "12px" }} />
<span style={{ marginLeft: 5, fontSize: "12px" }}>
{" "}
{this.props.profileProperties.Location}
</span>
</div>
) : (
""
)}
</Persona> </Persona>
</div> </div>
</DocumentCard> </DocumentCard>
); );
} }
/** /**
* Load SPFx component by id, SPComponentLoader is used to load the SPFx components * Load SPFx component by id, SPComponentLoader is used to load the SPFx components
* @param componentId - componentId, guid of the component library * @param componentId - componentId, guid of the component library
*/ */
private async loadSPComponentById(componentId: string): Promise<any> { private async _loadSPComponentById(componentId: string): Promise<any> {
try { try {
const component: any = await SPComponentLoader.loadComponentById(componentId); const component: any = await SPComponentLoader.loadComponentById(
componentId
);
return component; return component;
} catch (error) { } catch (error) {
Promise.reject(error); Promise.reject(error);
Log.error(EXP_SOURCE, error, this.props.context.serviceScope); Log.error(EXP_SOURCE, error, this.props.context.serviceScope);
} }
} }
/** /**
* *
* *
@ -143,15 +161,11 @@ export class PersonaCard extends React.Component<IPersonaCardProps, IPersonaCard
* @memberof PersonaCard * @memberof PersonaCard
*/ */
public render(): React.ReactElement<IPersonaCardProps> { public render(): React.ReactElement<IPersonaCardProps> {
return ( return (
<div className={styles.personaContainer}> <div className={styles.personaContainer}>
{ {this.state.livePersonaCard
this.state.livePersonaCard ? ? this._LivePersonaCard()
this._LivePersonaCard() : this._PersonaCard()}
:
this._PersonaCard()
}
</div> </div>
); );
} }

2
samples/react-directory/src/webparts/directory/loc/en-us.js vendored Normal file → Executable file
View File

@ -1,5 +1,7 @@
define([], function() { define([], function() {
return { return {
DropDownPlaceLabelMessage: "Sort People by ",
DropDownPlaceHolderMessage: "Sort by",
SearchPlaceHolder: "Search for People", SearchPlaceHolder: "Search for People",
"PropertyPaneDescription": "Search People from Organization Directory", "PropertyPaneDescription": "Search People from Organization Directory",
"BasicGroupName": "Properties", "BasicGroupName": "Properties",

3
samples/react-directory/src/webparts/directory/loc/mystrings.d.ts vendored Normal file → Executable file
View File

@ -1,9 +1,12 @@
declare interface IDirectoryWebPartStrings { declare interface IDirectoryWebPartStrings {
DropDownPlaceLabelMessage: string;
DropDownPlaceHolderMessage: string;
SearchPlaceHolder: string; SearchPlaceHolder: string;
PropertyPaneDescription: string; PropertyPaneDescription: string;
BasicGroupName: string; BasicGroupName: string;
TitleFieldLabel: string; TitleFieldLabel: string;
DirectoryMessage: string; DirectoryMessage: string;
} }
declare module 'DirectoryWebPartStrings' { declare module 'DirectoryWebPartStrings' {

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

0
samples/react-directory/tools/pre-version.js vendored Normal file → Executable file
View File

0
samples/react-directory/tsconfig.json Normal file → Executable file
View File

0
samples/react-directory/tslint.json Normal file → Executable file
View File