diff --git a/samples/react-teams-tagging/README.md b/samples/react-teams-tagging/README.md index 05a8d034f..2d2a87935 100644 --- a/samples/react-teams-tagging/README.md +++ b/samples/react-teams-tagging/README.md @@ -91,4 +91,4 @@ This sample illustrates the following concepts on top of the SharePoint Framewor * Using async / await for the async calls * Office UI fabric components - + diff --git a/samples/react-teams-tagging/src/webparts/teamsTagging/components/ITeamsTaggingState.ts b/samples/react-teams-tagging/src/webparts/teamsTagging/components/ITeamsTaggingState.ts index 64ce81d06..726976bc1 100644 --- a/samples/react-teams-tagging/src/webparts/teamsTagging/components/ITeamsTaggingState.ts +++ b/samples/react-teams-tagging/src/webparts/teamsTagging/components/ITeamsTaggingState.ts @@ -1,7 +1,8 @@ import { ITeamInfo } from "./ITeamsTaggingProps"; +import { IPickerTerms } from "@pnp/spfx-controls-react/lib/TaxonomyPicker"; export interface ITeamsTaggingState { - selectedTags: string[]; - savedTags: string[]; similarTeams: ITeamInfo[]; -} + tags: IPickerTerms; + tagsUpdatedResult: string; +} \ No newline at end of file diff --git a/samples/react-teams-tagging/src/webparts/teamsTagging/components/TeamsTagging.module.scss b/samples/react-teams-tagging/src/webparts/teamsTagging/components/TeamsTagging.module.scss index ee5634a92..055ad25a6 100644 --- a/samples/react-teams-tagging/src/webparts/teamsTagging/components/TeamsTagging.module.scss +++ b/samples/react-teams-tagging/src/webparts/teamsTagging/components/TeamsTagging.module.scss @@ -9,7 +9,7 @@ .row { @include ms-Grid-row; - @include ms-fontColor-white; + // @include ms-fontColor-white; background-color: $ms-color-themeDark; padding: 20px; } diff --git a/samples/react-teams-tagging/src/webparts/teamsTagging/components/TeamsTagging.tsx b/samples/react-teams-tagging/src/webparts/teamsTagging/components/TeamsTagging.tsx index 2472c629d..3beb8673c 100644 --- a/samples/react-teams-tagging/src/webparts/teamsTagging/components/TeamsTagging.tsx +++ b/samples/react-teams-tagging/src/webparts/teamsTagging/components/TeamsTagging.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import styles from './TeamsTagging.module.scss'; import { ITeamsTaggingProps, ITeamInfo } from './ITeamsTaggingProps'; -import { TaxonomyPicker, IPickerTerms } from "@pnp/spfx-controls-react/lib/TaxonomyPicker"; +import { TaxonomyPicker, IPickerTerms, IPickerTerm } from "@pnp/spfx-controls-react/lib/TaxonomyPicker"; import { ITeamsTaggingState } from './ITeamsTaggingState'; import { DefaultButton } from "office-ui-fabric-react"; import { Guid } from '@microsoft/sp-core-library'; @@ -9,6 +9,8 @@ import { HttpClientResponse, GraphHttpClient, IGraphHttpClientOptions } from '@m export default class TeamsTagging extends React.Component { + private readonly separator: string = "__"; + constructor(props: ITeamsTaggingProps) { super(props); @@ -17,13 +19,13 @@ export default class TeamsTagging extends React.Component { + private async _getTeamTags(): Promise { const groupId: Guid = this.props.context.pageContext.site.group.id; const response: HttpClientResponse = await this.props.context.graphHttpClient.get( @@ -32,16 +34,16 @@ export default class TeamsTagging extends React.Component { - const tag1 = this.state.savedTags[0]; + const tag1: string = this._serializeIPickerTerm(this.state.tags[0]); const response: HttpClientResponse = await this.props.context.graphHttpClient.get( `v1.0/groups/?$filter=inheritscloud_TeamsTagging/tag1 eq '${tag1}'&$select=id,displayName,inheritscloud_TeamsTagging`, @@ -50,14 +52,16 @@ export default class TeamsTagging extends React.Component { - let tags: string[] = []; - if (team.inheritscloud_TeamsTagging.tag1) tags.push(team.inheritscloud_TeamsTagging.tag1); - if (team.inheritscloud_TeamsTagging.tag2) tags.push(team.inheritscloud_TeamsTagging.tag2); - if (team.inheritscloud_TeamsTagging.tag3) tags.push(team.inheritscloud_TeamsTagging.tag3); + let tags: IPickerTerms = []; + + if (team.inheritscloud_TeamsTagging.tag1) tags.push(this._toIPickerTerm(team.inheritscloud_TeamsTagging.tag1)); + if (team.inheritscloud_TeamsTagging.tag2) tags.push(this._toIPickerTerm(team.inheritscloud_TeamsTagging.tag2)); + if (team.inheritscloud_TeamsTagging.tag3) tags.push(this._toIPickerTerm(team.inheritscloud_TeamsTagging.tag3)); + const similarTeam: ITeamInfo = { id: team.id, name: team.displayName, - tags: tags + tags: tags.map((t: IPickerTerm) => t.name) }; return similarTeam; }); @@ -71,7 +75,7 @@ export default class TeamsTagging extends React.Component { console.log(value); this.setState({ - savedTags: value + tags: value }); }); } public render(): React.ReactElement { - let tags: any = Getting Team tags from Graph API ...; - - if (this.state.savedTags.length > 0) { - tags = Team tags: - {this.state.savedTags.map(t => {t})} - ; - } let similarTeams: any; if (this.state.similarTeams.length > 0) { similarTeams = Similar teams: - {this.state.similarTeams.map(t => {t.name})} + {this.state.similarTeams.map(t => {t.name} ({t.tags.map(tag => {tag}, )}) )} ; } @@ -132,22 +129,23 @@ export default class TeamsTagging extends React.Component - {tags} - - + + isTermSetSelectable={false} + initialValues={this.state.tags} /> + + {this.state.tagsUpdatedResult} @@ -169,11 +167,24 @@ export default class TeamsTagging extends React.Component t.name); - this.setState({ - selectedTags: tags + tags: terms }); } + + private _toIPickerTerm(input: string): IPickerTerm + { + const parts: string[] = input.split(this.separator); + const pickerTerm: IPickerTerm = { + key: parts[0], + name: parts[1], + path: parts[2], + termSet: parts[3] + }; + return pickerTerm; + } + + private _serializeIPickerTerm(term: IPickerTerm): string { + return `${term.key}${this.separator}${term.name}${this.separator}${term.path}${this.separator}${term.termSet}`; + } }
{this.state.tagsUpdatedResult}