Skip to content

Commit 7514352

Browse files
HiltonGiesenowmsftbot[bot]AJIXuMuK
authored
Adding taxonomy tree to test harness (pnp#1269)
* Add `.github/fabricbot.json` * Adding Modern TaxonomyTree to Test Harness * Delete fabricbot.json Co-authored-by: msftbot[bot] <48340428+msftbot[bot]@users.noreply.github.com> Co-authored-by: Alex Terentiev <[email protected]>
1 parent 7bf34cb commit 7514352

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ import {
5252
import {
5353
DisplayMode,
5454
Environment,
55-
EnvironmentType
55+
EnvironmentType,
56+
Guid
5657
} from "@microsoft/sp-core-library";
58+
5759
import { SPHttpClient } from "@microsoft/sp-http";
5860
import { SPPermission } from "@microsoft/sp-page-context";
5961

@@ -187,6 +189,7 @@ import { EnhancedThemeProvider } from "../../../EnhancedThemeProvider";
187189
import { ControlsTestEnhancedThemeProvider, ControlsTestEnhancedThemeProviderFunctionComponent } from "./ControlsTestEnhancedThemeProvider";
188190
import { AdaptiveCardDesignerHost } from "../../../AdaptiveCardDesignerHost";
189191
import { ModernAudio, ModernAudioLabelPosition } from "../../../ModernAudio";
192+
import { SPTaxonomyService, TaxonomyTree } from "../../../ModernTaxonomyPicker";
190193

191194

192195
// Used to render document card
@@ -277,6 +280,8 @@ const toolbarFilters = [{
277280
*/
278281
export default class ControlsTest extends React.Component<IControlsTestProps, IControlsTestState> {
279282
private taxService: SPTermStorePickerService = null;
283+
private spTaxonomyService = new SPTaxonomyService(this.props.context);
284+
280285
private richTextValue: string = null;
281286
private theme = window["__themeState__"].theme;
282287
private pickerStylesSingle: Partial<IBasePickerStyles> = {
@@ -495,7 +500,10 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
495500
selectedTeam: [],
496501
selectedTeamChannels: [],
497502
errorMessage: "This field is required",
498-
selectedFilters: ["filter1"]
503+
selectedFilters: ["filter1"],
504+
termStoreInfo: null,
505+
termSetInfo: null,
506+
testTerms: [],
499507
};
500508

501509
this._onIconSizeChange = this._onIconSizeChange.bind(this);
@@ -507,15 +515,16 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
507515
/**
508516
* React componentDidMount lifecycle hook
509517
*/
510-
public componentDidMount() {
518+
public async componentDidMount() {
511519
const restApi = `${this.props.context.pageContext.web.absoluteUrl}/_api/web/GetFolderByServerRelativeUrl('Shared%20Documents')/files?$expand=ListItemAllFields`;
512-
this.props.context.spHttpClient.get(restApi, SPHttpClient.configurations.v1)
513-
.then(resp => { return resp.json(); })
514-
.then(items => {
515-
this.setState({
516-
items: items.value ? items.value : []
517-
});
518-
});
520+
const response = await this.props.context.spHttpClient.get(restApi, SPHttpClient.configurations.v1);
521+
const items = await response.json();
522+
523+
this.setState({
524+
items: items.value ? items.value : [],
525+
termStoreInfo: await this.spTaxonomyService.getTermStoreInfo(),
526+
termSetInfo: await this.spTaxonomyService.getTermSetInfo(Guid.parse("4bc86596-7caf-4e70-80c9-d9769e448988")),
527+
});
519528

520529
// // Get Authors in the SharePoint Document library -- For People Picker Testing
521530
// const restAuthorApi = `${this.props.context.pageContext.web.absoluteUrl}/_api/web/lists/GetByTitle('Documents')/Items?$select=Id, Author/EMail&$expand=Author/EMail`;
@@ -2379,6 +2388,24 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
23792388
/>
23802389
</div>
23812390

2391+
<div>
2392+
<h3>Modern Taxonomy Tree</h3>
2393+
{this.state.termStoreInfo && (
2394+
<TaxonomyTree
2395+
languageTag={this.state.termStoreInfo.defaultLanguageTag}
2396+
onLoadMoreData={this.spTaxonomyService.getTerms}
2397+
pageSize={50}
2398+
setTerms={(value) => this.setState({testTerms: value as any})}
2399+
termStoreInfo={this.state.termStoreInfo}
2400+
termSetInfo={this.state.termSetInfo}
2401+
terms={this.state.testTerms as any[]}
2402+
onRenderActionButton={() => <button>test button</button>}
2403+
hideDeprecatedTerms={false}
2404+
showIcons={true}
2405+
/>
2406+
)}
2407+
</div>
2408+
23822409
</div>
23832410
);
23842411
}

src/webparts/controlsTest/components/ControlsTest_SingleComponent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
143143
termPanelIsOpen: false,
144144
actionTermId: null,
145145
clickedActionTerm: null,
146+
termStoreInfo: null,
147+
termSetInfo: null,
148+
testTerms: [],
146149
};
147150

148151
this._onIconSizeChange = this._onIconSizeChange.bind(this);

src/webparts/controlsTest/components/IControlsTestProps.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
IReadonlyTheme,
99

1010
} from "@microsoft/sp-component-base";
11-
import { ITermInfo } from '@pnp/sp/taxonomy';
11+
import { ITermInfo, ITermSetInfo, ITermStoreInfo } from '@pnp/sp/taxonomy';
12+
1213
export interface IControlsTestProps {
1314
context: WebPartContext;
1415
description: string;
@@ -53,4 +54,7 @@ export interface IControlsTestState {
5354
actionTermId?: string;
5455
clickedActionTerm?: ITermInfo;
5556
selectedFilters?: string[];
57+
termStoreInfo: ITermStoreInfo;
58+
termSetInfo: ITermSetInfo;
59+
testTerms: ITermInfo[];
5660
}

0 commit comments

Comments
 (0)