From 127ad26e4b1985a792dbf1fe9f8635030d017388 Mon Sep 17 00:00:00 2001 From: Tobias Maestrini Date: Sun, 25 Feb 2024 15:24:36 +0100 Subject: [PATCH] add additional properties to set target site and target lists --- .../src/webparts/myTools/MyToolsWebPart.ts | 56 ++++++++++++++++++- .../webparts/myTools/models/IMyToolsProps.ts | 3 + 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/samples/react-personal-tools-list/src/webparts/myTools/MyToolsWebPart.ts b/samples/react-personal-tools-list/src/webparts/myTools/MyToolsWebPart.ts index f001e8675..7e5f82e45 100644 --- a/samples/react-personal-tools-list/src/webparts/myTools/MyToolsWebPart.ts +++ b/samples/react-personal-tools-list/src/webparts/myTools/MyToolsWebPart.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import * as React from 'react'; import * as ReactDom from 'react-dom'; import { Version } from '@microsoft/sp-core-library'; @@ -11,10 +12,13 @@ import { IReadonlyTheme } from '@microsoft/sp-component-base'; import * as strings from 'MyToolsWebPartStrings'; import MyTools from './components/MyTools'; import { IMyToolsProps } from './models'; +import { IPropertyFieldSite, PropertyFieldListPicker, PropertyFieldListPickerOrderBy, PropertyFieldSitePicker } from '@pnp/spfx-property-controls'; export interface IMyToolsWebPartProps { wpTitle: string; + wpSites: IPropertyFieldSite[]; + wpLists: { personalToolsList: { id: string, title: string, url: string }, availableToolsList: { id: string, title: string, url: string } }; twoColumns: boolean; } @@ -28,6 +32,8 @@ export default class MyToolsWebPart extends BaseClientSideWebPart 0) ? this.properties.wpSites[0] : undefined, + wpLists: this.properties.wpLists, isDarkTheme: this._isDarkTheme, context: this.context, environmentMessage: this._environmentMessage, @@ -46,8 +52,6 @@ export default class MyToolsWebPart extends BaseClientSideWebPart { if (!!this.context.sdks.microsoftTeams) { // running in Teams, office.com or Outlook return this.context.sdks.microsoftTeams.teamsJs.app.getContext() @@ -115,7 +119,7 @@ export default class MyToolsWebPart extends BaseClientSideWebPart 0 ? this.properties.wpSites : [{ url: this.context.pageContext.web.serverRelativeUrl, title: this.context.pageContext.web.title }], + context: this.context as any, + deferredValidationTime: 500, + multiSelect: false, + onPropertyChange: this.onPropertyPaneFieldChanged, + properties: this.properties, + key: 'wpSites' + }), + PropertyFieldListPicker('wpLists.personalToolsList', { + label: "Select the 'Personal tools' list", + selectedList: this.properties.wpLists?.personalToolsList, + includeHidden: false, + baseTemplate: 100, + orderBy: PropertyFieldListPickerOrderBy.Title, + includeListTitleAndUrl: true, + disabled: (this.properties.wpSites && this.properties.wpSites.length > 0) ? false : true, + onPropertyChange: this.onPropertyPaneFieldChanged.bind(this), + properties: this.properties, + context: this.context as any, + multiSelect: false, + webAbsoluteUrl: (this.properties.wpSites && this.properties.wpSites.length > 0) ? this.properties.wpSites[0].url : this.context.pageContext.web.absoluteUrl, + deferredValidationTime: 0, + key: 'wpLists.personalToolsList' + }), + PropertyFieldListPicker('wpLists.availableToolsList', { + label: "Select the 'Available tools' list", + selectedList: this.properties.wpLists?.availableToolsList, + includeHidden: false, + baseTemplate: 100, + orderBy: PropertyFieldListPickerOrderBy.Title, + includeListTitleAndUrl: true, + disabled: (this.properties.wpSites && this.properties.wpSites.length > 0) ? false : true, + onPropertyChange: this.onPropertyPaneFieldChanged.bind(this), + properties: this.properties, + context: this.context as any, + multiSelect: false, + webAbsoluteUrl: (this.properties.wpSites && this.properties.wpSites.length > 0) ? this.properties.wpSites[0].url : this.context.pageContext.web.absoluteUrl, + deferredValidationTime: 0, + key: 'wpLists.availableToolsList' + }), + ] } ] } diff --git a/samples/react-personal-tools-list/src/webparts/myTools/models/IMyToolsProps.ts b/samples/react-personal-tools-list/src/webparts/myTools/models/IMyToolsProps.ts index 6b5cdb02f..3705d32f8 100644 --- a/samples/react-personal-tools-list/src/webparts/myTools/models/IMyToolsProps.ts +++ b/samples/react-personal-tools-list/src/webparts/myTools/models/IMyToolsProps.ts @@ -1,7 +1,10 @@ import { WebPartContext } from "@microsoft/sp-webpart-base"; +import { IPropertyFieldSite } from "@pnp/spfx-property-controls"; export interface IMyToolsProps { wpTitle: string; + wpSite?: IPropertyFieldSite; + wpLists?: { personalToolsList: { id: string, title: string, url: string }, availableToolsList: { id: string, title: string, url: string } }; isDarkTheme: boolean; context: WebPartContext; environmentMessage: string;