forked from pnp/sp-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LobIntegrationWebPart.ts
96 lines (87 loc) · 3.11 KB
/
LobIntegrationWebPart.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField,
PropertyPaneChoiceGroup
} from '@microsoft/sp-webpart-base';
import { DisplayMode } from '@microsoft/sp-core-library';
import * as strings from 'LobIntegrationWebPartStrings';
import LobIntegration from './components/LobIntegration';
import { ILobIntegrationProps } from './components/ILobIntegrationProps';
import { ILobIntegrationWebPartProps, serviceType } from './ILobIntegrationWebPartProps';
export default class LobIntegrationWebPart extends BaseClientSideWebPart<ILobIntegrationWebPartProps> {
// method to determine if the web part has to be configured
private needsConfiguration(): boolean {
// as long as we don't have the configuration settings
return (!this.properties.webapiUri && !this.properties.functionUri) ||
!this.properties.serviceType;
}
public render(): void {
const element: React.ReactElement<ILobIntegrationProps > = React.createElement(
LobIntegration,
{
webapiUri: this.properties.webapiUri,
functionUri: this.properties.functionUri,
serviceType: this.properties.serviceType,
needsConfiguration: this.needsConfiguration(),
context: this.context,
configureHandler: () => {
this.context.propertyPane.open();
},
errorHandler: (errorMessage: string) => {
if (this.displayMode === DisplayMode.Edit) {
this.context.statusRenderer.renderError(this.domElement, errorMessage);
} else {
// nothing to do, if we are not in edit Mode
}
}
}
);
ReactDom.render(element, this.domElement);
}
protected get dataVersion(): Version {
return Version.parse('1.0');
}
// // method to disable reactive properties in the property pane
// protected get disableReactivePropertyChanges(): boolean {
// return true;
// }
// // method to refresh any error after properties configuration
// protected onAfterPropertyPaneChangesApplied(): void {
// this.context.statusRenderer.clearError(this.domElement);
// }
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
return {
pages: [
{
header: {
description: strings.PropertyPaneDescription
},
groups: [
{
groupName: strings.BasicGroupName,
groupFields: [
PropertyPaneTextField('webapiUri', {
label: strings.WebApiUriFieldLabel
}),
PropertyPaneTextField('functionUri', {
label: strings.FunctionUriFieldLabel
}),
PropertyPaneChoiceGroup('serviceType', {
label: strings.ServiceTypeFieldLabel,
options: [
{ key: 1, text: "ASP.NET REST API"},
{ key: 2, text: "Azure Function"},
]
}),
]
}
]
}
]
};
}
}