moved to react.fc
This commit is contained in:
parent
f33c23603e
commit
157db93bf5
|
@ -9,8 +9,7 @@ import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
|
||||||
import { IReadonlyTheme } from '@microsoft/sp-component-base';
|
import { IReadonlyTheme } from '@microsoft/sp-component-base';
|
||||||
|
|
||||||
import * as strings from 'SpSiteErDiagramWebPartStrings';
|
import * as strings from 'SpSiteErDiagramWebPartStrings';
|
||||||
import SpSiteErDiagram from './components/SpSiteErDiagram';
|
import SpSiteErDiagram, { ISpSiteDiagramProps } from './components/SpSiteErDiagram';
|
||||||
import { ISpSiteErDiagramProps } from './components/ISpSiteErDiagramProps';
|
|
||||||
|
|
||||||
export interface ISpSiteErDiagramWebPartProps {
|
export interface ISpSiteErDiagramWebPartProps {
|
||||||
description: string;
|
description: string;
|
||||||
|
@ -23,15 +22,15 @@ export default class SpSiteErDiagramWebPart extends BaseClientSideWebPart<ISpSit
|
||||||
|
|
||||||
|
|
||||||
public render(): void {
|
public render(): void {
|
||||||
const element: React.ReactElement<ISpSiteErDiagramProps> = React.createElement(
|
const element: React.ReactElement<ISpSiteDiagramProps> = React.createElement(
|
||||||
SpSiteErDiagram,
|
SpSiteErDiagram,
|
||||||
{
|
{
|
||||||
context: this.context,
|
context: this.context,
|
||||||
description: this.properties.description,
|
//description: this.properties.description,
|
||||||
isDarkTheme: this._isDarkTheme,
|
//isDarkTheme: this._isDarkTheme,
|
||||||
environmentMessage: this._environmentMessage,
|
//environmentMessage: this._environmentMessage,
|
||||||
hasTeamsContext: !!this.context.sdks.microsoftTeams,
|
//hasTeamsContext: !!this.context.sdks.microsoftTeams,
|
||||||
userDisplayName: this.context.pageContext.user.displayName
|
//userDisplayName: this.context.pageContext.user.displayName
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
ReactDom.render(element, this.domElement);
|
ReactDom.render(element, this.domElement);
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
export interface ISpSiteErDiagramProps {
|
|
||||||
context: any,
|
|
||||||
description: string;
|
|
||||||
isDarkTheme: boolean;
|
|
||||||
environmentMessage: string;
|
|
||||||
hasTeamsContext: boolean;
|
|
||||||
userDisplayName: string;
|
|
||||||
}
|
|
|
@ -1,53 +1,55 @@
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import styles from './SpSiteErDiagram.module.scss';
|
import styles from './SpSiteErDiagram.module.scss';
|
||||||
import { ISpSiteErDiagramProps } from './ISpSiteErDiagramProps';
|
|
||||||
import { ReactDiagram } from 'gojs-react';
|
import { ReactDiagram } from 'gojs-react';
|
||||||
import getSPSiteData from './helpers/SPSiteData';
|
import getSPSiteData from './helpers/SPSiteData';
|
||||||
import { initDiagram } from './helpers/GoJSHelper';
|
import { initDiagram } from './helpers/GoJSHelper';
|
||||||
import getGoJSNodesFromSPSiteData from './helpers/SPSiteDataToGoJSER';
|
import getGoJSNodesFromSPSiteData from './helpers/SPSiteDataToGoJSER';
|
||||||
import { ProgressIndicator } from 'office-ui-fabric-react';
|
import { ProgressIndicator } from 'office-ui-fabric-react';
|
||||||
|
|
||||||
interface SpSiteDiagramState {
|
export interface ISpSiteDiagramProps {
|
||||||
loadingProgress: number,
|
context: any
|
||||||
nodeDataArray: any[],
|
|
||||||
linkDataArray: any[]
|
|
||||||
}
|
}
|
||||||
export default class SpSiteErDiagram extends React.Component<ISpSiteErDiagramProps, SpSiteDiagramState> {
|
const SpSiteErDiagram: React.FC<ISpSiteDiagramProps> = (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) {
|
const loadDiagram = async () => {
|
||||||
super(props);
|
|
||||||
this.state = { loadingProgress: 0, nodeDataArray: [], linkDataArray: []};
|
|
||||||
}
|
|
||||||
|
|
||||||
public async componentDidMount() {
|
|
||||||
// Get SP SiteData for ER Diagram
|
// Get SP SiteData for ER Diagram
|
||||||
let spSiteData = await getSPSiteData(this.props.context, true, (progress) => {
|
let spSiteData = await getSPSiteData(props.context, true, (progress) => {setLoadingProgress(progress);});
|
||||||
this.setState({ loadingProgress: progress });
|
|
||||||
});
|
|
||||||
console.log("SPSiteData", spSiteData);
|
console.log("SPSiteData", spSiteData);
|
||||||
// Transform to GoJS Model
|
// Transform to GoJS Model
|
||||||
let goJSNodes = getGoJSNodesFromSPSiteData(spSiteData);
|
let goJSNodes = getGoJSNodesFromSPSiteData(spSiteData);
|
||||||
// Set State
|
// Set State
|
||||||
this.setState({nodeDataArray: goJSNodes.nodeDataArray, linkDataArray: goJSNodes.linkDataArray});
|
setNodeDataArray(goJSNodes.nodeDataArray);
|
||||||
|
setLinkDataArray(goJSNodes.linkDataArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
public render(): React.ReactElement<ISpSiteErDiagramProps> {
|
// "ComponentDitMount"
|
||||||
|
React.useEffect(() => {
|
||||||
|
loadDiagram();
|
||||||
|
}, [optionRelationOnly]);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.spSiteErDiagram} style={{height: "calc(100% - 0px)", padding: "0px"}}>
|
<div className={styles.spSiteErDiagram} style={{height: "calc(100% - 0px)", padding: "0px"}}>
|
||||||
{ // this.state.loadingProgress != 100 || this.state.nodeDataArray.length == 0
|
{
|
||||||
this.state.loadingProgress != 100 || this.state.nodeDataArray.length == 0 ?
|
loadingProgress != 100 || nodeDataArray.length == 0 ?
|
||||||
<div style={{ padding: "8%" }}>
|
<div style={{ padding: "8%" }}>
|
||||||
<ProgressIndicator label={`Loading Lists and Columns ${this.state.loadingProgress.toFixed(0)}%`} percentComplete={this.state.loadingProgress/100} />
|
<ProgressIndicator label={`Loading Lists and Columns ${loadingProgress.toFixed(0)}%`} percentComplete={loadingProgress/100} />
|
||||||
</div> :
|
</div> :
|
||||||
<ReactDiagram //ref={diagramRef}
|
<ReactDiagram //ref={diagramRef}
|
||||||
divClassName='diagram-component'
|
divClassName='diagram-component'
|
||||||
style={{ backgroundColor: '#eee' }}
|
style={{ backgroundColor: '#eee' }}
|
||||||
initDiagram={initDiagram}
|
initDiagram={initDiagram}
|
||||||
nodeDataArray={this.state.nodeDataArray}
|
nodeDataArray={nodeDataArray}
|
||||||
linkDataArray={this.state.linkDataArray}
|
linkDataArray={linkDataArray}
|
||||||
|
|
||||||
/>}
|
/>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default SpSiteErDiagram;
|
||||||
|
|
Loading…
Reference in New Issue