Solving Issue

This commit is contained in:
petkir 2020-07-18 12:44:47 +02:00
parent f7fa93c031
commit 2864c48d4e
4 changed files with 19123 additions and 70 deletions

View File

@ -1,11 +1,9 @@
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 { 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 * as strings from "DirectoryWebPartStrings"; import * as strings from "DirectoryWebPartStrings";
import { import {
Spinner, Spinner,
@ -20,15 +18,10 @@ import {
PivotLinkFormat, PivotLinkFormat,
PivotLinkSize, PivotLinkSize,
Dropdown, Dropdown,
DropdownMenuItemType,
IDropdownStyles,
IDropdownOption IDropdownOption
} from "office-ui-fabric-react"; } 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 { IUserProperties } from "./PersonaCard/IUserProperties";
const az: string[] = [ const az: string[] = [
"A", "A",
@ -68,7 +61,7 @@ const orderOptions: IDropdownOption[] = [
export default class Directory extends React.Component< export default class Directory extends React.Component<
IDirectoryProps, IDirectoryProps,
IDirectoryState IDirectoryState
> { > {
private _services: spservices = null; private _services: spservices = null;
constructor(props: IDirectoryProps) { constructor(props: IDirectoryProps) {
@ -80,7 +73,8 @@ export default class Directory extends React.Component<
errorMessage: "", errorMessage: "",
hasError: false, hasError: false,
indexSelectedKey: "A", indexSelectedKey: "A",
searchString: "LastName" searchString: "LastName",
searchText: ""
}; };
this._services = new spservices(this.props.context); this._services = new spservices(this.props.context);
@ -88,6 +82,7 @@ export default class Directory extends React.Component<
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); this._sortPeople = this._sortPeople.bind(this);
this._searchBoxChanged = this._searchBoxChanged.bind(this)
} }
/** /**
@ -104,27 +99,29 @@ export default class Directory extends React.Component<
* @param pictureUrl * @param pictureUrl
* @returns * @returns
*/ */
private getImageBase64(pictureUrl: string):Promise<string>{ private getImageBase64(pictureUrl: string): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let image = new Image(); let image = new Image();
image.addEventListener("load", () => { image.addEventListener("load", () => {
let tempCanvas = document.createElement("canvas"); let tempCanvas = document.createElement("canvas");
tempCanvas.width = image.width, tempCanvas.width = image.width,
tempCanvas.height = image.height, tempCanvas.height = image.height,
tempCanvas.getContext("2d").drawImage(image, 0, 0); tempCanvas.getContext("2d").drawImage(image, 0, 0);
let base64Str; let base64Str;
try { try {
base64Str = tempCanvas.toDataURL("image/png"); base64Str = tempCanvas.toDataURL("image/png");
} catch (e) { } catch (e) {
return ""; return "";
} }
resolve(base64Str); resolve(base64Str);
}); });
image.src = pictureUrl; image.src = pictureUrl;
}); });
} }
private _searchBoxChanged(newvalue: string): void {
this.setState({ searchText: newvalue }, () => this._searchUsers(newvalue));
}
private async _searchUsers(searchText: string) { private async _searchUsers(searchText: string) {
searchText = searchText.trim().length > 0 ? searchText : "A"; searchText = searchText.trim().length > 0 ? searchText : "A";
@ -140,15 +137,15 @@ export default class Directory extends React.Component<
this.props.searchFirstName this.props.searchFirstName
); );
if (users && users.PrimarySearchResults.length > 0){ if (users && users.PrimarySearchResults.length > 0) {
for (let index = 0; index < users.PrimarySearchResults.length; index++) { for (let index = 0; index < users.PrimarySearchResults.length; index++) {
let user:any = users.PrimarySearchResults[index] ; let user: any = users.PrimarySearchResults[index];
if (user.PictureURL){ if (user.PictureURL) {
user = { ...user, PictureURL: await this.getImageBase64(`/_layouts/15/userphoto.aspx?size=M&accountname=${user.WorkEmail}`)}; user = { ...user, PictureURL: await this.getImageBase64(`/_layouts/15/userphoto.aspx?size=M&accountname=${user.WorkEmail}`) };
users.PrimarySearchResults[index] = user ; users.PrimarySearchResults[index] = user;
} }
} }
} }
this.setState({ this.setState({
users: users:
@ -279,7 +276,7 @@ export default class Directory extends React.Component<
* @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.setState({ searchText: "" }, () => this._searchUsers(item.props.itemKey));
} }
/** /**
* *
@ -293,23 +290,23 @@ export default class Directory extends React.Component<
const diretoryGrid = const diretoryGrid =
this.state.users && this.state.users.length > 0 this.state.users && this.state.users.length > 0
? this.state.users.map((user: any) => { ? this.state.users.map((user: any) => {
return ( return (
<PersonaCard <PersonaCard
context={this.props.context} context={this.props.context}
profileProperties={{ profileProperties={{
DisplayName: user.PreferredName, DisplayName: user.PreferredName,
Title: user.JobTitle, Title: user.JobTitle,
PictureUrl: user.PictureURL, PictureUrl: user.PictureURL,
Email: user.WorkEmail, Email: user.WorkEmail,
Department: user.Department, Department: user.Department,
WorkPhone: user.WorkPhone, WorkPhone: user.WorkPhone,
Location: user.OfficeNumber Location: user.OfficeNumber
? user.OfficeNumber ? user.OfficeNumber
: user.BaseOfficeLocation : user.BaseOfficeLocation
}} }}
/> />
); );
}) })
: []; : [];
return ( return (
@ -336,7 +333,8 @@ export default class Directory extends React.Component<
onClear={() => { onClear={() => {
this._searchUsers("A"); this._searchUsers("A");
}} }}
onChange={this._searchUsers} value={this.state.searchText}
onChange={this._searchBoxChanged}
/> />
<div> <div>
<Pivot <Pivot
@ -380,20 +378,20 @@ export default class Directory extends React.Component<
{this.state.errorMessage} {this.state.errorMessage}
</MessageBar> </MessageBar>
) : ( ) : (
<div className={styles.dropDownSortBy}> <div className={styles.dropDownSortBy}>
<Dropdown <Dropdown
placeholder={strings.DropDownPlaceHolderMessage} placeholder={strings.DropDownPlaceHolderMessage}
label={strings.DropDownPlaceLabelMessage} label={strings.DropDownPlaceLabelMessage}
options={orderOptions} options={orderOptions}
selectedKey={this.state.searchString} selectedKey={this.state.searchString}
onChange={(ev: any, value: IDropdownOption) => { onChange={(ev: any, value: IDropdownOption) => {
this._sortPeople(value.key.toString()); this._sortPeople(value.key.toString());
}} }}
styles={{ dropdown: { width: 200 } }} styles={{ dropdown: { width: 200 } }}
/> />
<div>{diretoryGrid}</div> <div>{diretoryGrid}</div>
</div> </div>
)} )}
</div> </div>
); );
} }

View File

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

19055
samples/react-script-editor/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff