import * as ReactDOM from 'react-dom' ; import * as string from 'CopyMoveItemsCommandSetStrings' ; import { override } from '@microsoft/decorators' ; import { Log } from '@microsoft/sp-core-library' ; import { BaseListViewCommandSet , Command , IListViewCommandSetListViewUpdatedParameters , IListViewCommandSetExecuteEventParameters } from '@microsoft/sp-listview-extensibility' ; import * as strings from 'CopyMoveItemsCommandSetStrings' ; import { ICommandInfo } from './Models/ICommandInfo' ; import { sp } from "@pnp/sp" ; import AppBaseDialog , { IAppDialogProps } from './components/AppBaseDialog' ; /**
 * If your command set uses the ClientSideComponentProperties JSON input,
 * it will be deserialized into the BaseExtension.properties object.
 * You can define an interface to describe it.
 */ export interface ICopyMoveItemsCommandSetProperties { } const LOG_SOURCE = 'CopyMoveItemsCommandSet' ; export default class CopyMoveItemsCommandSet extends BaseListViewCommandSet < ICopyMoveItemsCommandSetProperties > { private appDialog : AppBaseDialog = null ; @ override public onInit ( ) { Log . info ( LOG_SOURCE , 'Initialized CopyMoveItemsCommandSet' ) ; sp . setup ( this . context ) ; return Promise . resolve ( ) ; } @ override public onListViewUpdated ( event ) { const commandOne = this . tryGetCommand ( strings . CopyMoveCommand ) ; commandOne . visible = true ; } private _closeDialog ( ) { this . appDialog . close ( ) ; } @ override public onExecute ( event ) { switch ( event . itemId ) { case strings . CopyMoveCommand : let itemIds = [ ] ; if ( event . selectedRows . length > 0 ) { event . selectedRows . map ( row => { itemIds . push ( row . getValueByName ( "ID" ) ) ; } ) ; } let data = { List : { Title : this . context . pageContext . list . title , Url : this . context . pageContext . list . serverRelativeUrl , Id : this . context . pageContext . list . id . toString ( ) } , Site : { Id : this . context . pageContext . site . id . toString ( ) , AbsUrl : this . context . pageContext . site . absoluteUrl , SerUrl : this . context . pageContext . site . serverRelativeUrl } , Web : { Id : this . context . pageContext . web . id . toString ( ) , AbsUrl : this . context . pageContext . web . absoluteUrl , SerUrl : this . context . pageContext . web . serverRelativeUrl } , User : { DisplayName : this . context . pageContext . user . displayName , Email : this . context . pageContext . user . email , LoginName : this . context . pageContext . user . loginName } , Fields : event . selectedRows . length > 0 ? event . selectedRows [ 0 ] . fields : undefined , ItemIds : itemIds } ; this . appDialog = new AppBaseDialog ( { } ) ; this . appDialog . data = data ; this . appDialog . show ( ) ; this . appDialog . closeDialog = this . _closeDialog . bind ( this ) ; break ; default : throw new Error ( strings . UnkCmd ) ; } } }