From 157db93bf58dba1f51999fa7f878753a23a709a6 Mon Sep 17 00:00:00 2001 From: NiklasWilhelm Date: Wed, 5 Oct 2022 22:20:14 +0200 Subject: [PATCH] moved to react.fc --- .../spSiteErDiagram/SpSiteErDiagramWebPart.ts | 15 ++-- .../components/ISpSiteErDiagramProps.ts | 8 --- .../components/SpSiteErDiagram.tsx | 70 ++++++++++--------- 3 files changed, 43 insertions(+), 50 deletions(-) delete mode 100644 samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/components/ISpSiteErDiagramProps.ts diff --git a/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/SpSiteErDiagramWebPart.ts b/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/SpSiteErDiagramWebPart.ts index 408929136..4c75a2433 100644 --- a/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/SpSiteErDiagramWebPart.ts +++ b/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/SpSiteErDiagramWebPart.ts @@ -9,8 +9,7 @@ import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base'; import { IReadonlyTheme } from '@microsoft/sp-component-base'; import * as strings from 'SpSiteErDiagramWebPartStrings'; -import SpSiteErDiagram from './components/SpSiteErDiagram'; -import { ISpSiteErDiagramProps } from './components/ISpSiteErDiagramProps'; +import SpSiteErDiagram, { ISpSiteDiagramProps } from './components/SpSiteErDiagram'; export interface ISpSiteErDiagramWebPartProps { description: string; @@ -23,15 +22,15 @@ export default class SpSiteErDiagramWebPart extends BaseClientSideWebPart = React.createElement( + const element: React.ReactElement = React.createElement( SpSiteErDiagram, { context: this.context, - description: this.properties.description, - isDarkTheme: this._isDarkTheme, - environmentMessage: this._environmentMessage, - hasTeamsContext: !!this.context.sdks.microsoftTeams, - userDisplayName: this.context.pageContext.user.displayName + //description: this.properties.description, + //isDarkTheme: this._isDarkTheme, + //environmentMessage: this._environmentMessage, + //hasTeamsContext: !!this.context.sdks.microsoftTeams, + //userDisplayName: this.context.pageContext.user.displayName } ); ReactDom.render(element, this.domElement); diff --git a/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/components/ISpSiteErDiagramProps.ts b/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/components/ISpSiteErDiagramProps.ts deleted file mode 100644 index ff99b6ffc..000000000 --- a/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/components/ISpSiteErDiagramProps.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface ISpSiteErDiagramProps { - context: any, - description: string; - isDarkTheme: boolean; - environmentMessage: string; - hasTeamsContext: boolean; - userDisplayName: string; -} diff --git a/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/components/SpSiteErDiagram.tsx b/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/components/SpSiteErDiagram.tsx index db39537ed..9607e3e30 100644 --- a/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/components/SpSiteErDiagram.tsx +++ b/samples/react-pnpjs-spsite-er-diagram/src/webparts/spSiteErDiagram/components/SpSiteErDiagram.tsx @@ -1,53 +1,55 @@ import * as React from 'react'; import styles from './SpSiteErDiagram.module.scss'; -import { ISpSiteErDiagramProps } from './ISpSiteErDiagramProps'; import { ReactDiagram } from 'gojs-react'; import getSPSiteData from './helpers/SPSiteData'; import { initDiagram } from './helpers/GoJSHelper'; import getGoJSNodesFromSPSiteData from './helpers/SPSiteDataToGoJSER'; import { ProgressIndicator } from 'office-ui-fabric-react'; -interface SpSiteDiagramState { - loadingProgress: number, - nodeDataArray: any[], - linkDataArray: any[] +export interface ISpSiteDiagramProps { + context: any } -export default class SpSiteErDiagram extends React.Component { +const SpSiteErDiagram: React.FC = (props: ISpSiteDiagramProps) => { + // State: Data + const [loadingProgress, setLoadingProgress] = React.useState(0); + const [nodeDataArray, setNodeDataArray] = React.useState([]); + const [linkDataArray, setLinkDataArray] = React.useState([]); + // State: Options + const [optionRelationOnly, setOptionRelationOnly] = React.useState(false); - constructor(props: any) { - super(props); - this.state = { loadingProgress: 0, nodeDataArray: [], linkDataArray: []}; - } - - public async componentDidMount() { + const loadDiagram = async () => { // Get SP SiteData for ER Diagram - let spSiteData = await getSPSiteData(this.props.context, true, (progress) => { - this.setState({ loadingProgress: progress }); - }); + let spSiteData = await getSPSiteData(props.context, true, (progress) => {setLoadingProgress(progress);}); console.log("SPSiteData", spSiteData); // Transform to GoJS Model let goJSNodes = getGoJSNodesFromSPSiteData(spSiteData); // Set State - this.setState({nodeDataArray: goJSNodes.nodeDataArray, linkDataArray: goJSNodes.linkDataArray}); + setNodeDataArray(goJSNodes.nodeDataArray); + setLinkDataArray(goJSNodes.linkDataArray); } - public render(): React.ReactElement { - return ( -
- { // this.state.loadingProgress != 100 || this.state.nodeDataArray.length == 0 - this.state.loadingProgress != 100 || this.state.nodeDataArray.length == 0 ? -
- -
: - { + loadDiagram(); + }, [optionRelationOnly]); - />} -
- ); - } + + return ( +
+ { + loadingProgress != 100 || nodeDataArray.length == 0 ? +
+ +
: + } +
+ ); } + +export default SpSiteErDiagram;