2021-01-20 06:42:45 +00:00
|
|
|
import React from "react";
|
|
|
|
import {
|
2021-01-26 17:44:14 +00:00
|
|
|
CommandBar,
|
|
|
|
ICommandBarItemProps,
|
|
|
|
IStackTokens,
|
|
|
|
MessageBar,
|
|
|
|
MessageBarType,
|
|
|
|
Spinner,
|
|
|
|
SpinnerSize,
|
|
|
|
Stack,
|
|
|
|
} from "office-ui-fabric-react";
|
|
|
|
import {
|
|
|
|
AnyDisplay,
|
|
|
|
Node,
|
2021-01-20 06:42:45 +00:00
|
|
|
InputType,
|
2021-01-26 17:44:14 +00:00
|
|
|
RefreshResult,
|
|
|
|
SelfServeDescriptor,
|
|
|
|
SmartUiInput,
|
|
|
|
DescriptionDisplay,
|
|
|
|
StringInput,
|
|
|
|
NumberInput,
|
|
|
|
BooleanInput,
|
|
|
|
ChoiceInput,
|
|
|
|
} from "./SelfServeTypes";
|
|
|
|
import { SmartUiComponent, SmartUiDescriptor } from "../Explorer/Controls/SmartUi/SmartUiComponent";
|
2021-01-28 19:17:02 +00:00
|
|
|
import { Translation } from "react-i18next";
|
|
|
|
import { TFunction } from "i18next";
|
|
|
|
import "../i18n";
|
2021-03-10 00:07:23 +00:00
|
|
|
import { sendMessage } from "../Common/MessageHandler";
|
|
|
|
import { SelfServeMessageTypes } from "../Contracts/SelfServeContracts";
|
|
|
|
import promiseRetry, { AbortError } from "p-retry";
|
|
|
|
|
|
|
|
interface SelfServeNotification {
|
|
|
|
message: string;
|
|
|
|
type: MessageBarType;
|
|
|
|
isCancellable: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface PortalNotificationContent {
|
|
|
|
retryIntervalInMs: number;
|
|
|
|
operationStatusUrl: string;
|
|
|
|
portalNotification?: {
|
|
|
|
initialize: {
|
|
|
|
title: string;
|
|
|
|
message: string;
|
|
|
|
};
|
|
|
|
success: {
|
|
|
|
title: string;
|
|
|
|
message: string;
|
|
|
|
};
|
|
|
|
failure: {
|
|
|
|
title: string;
|
|
|
|
message: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2021-01-20 06:42:45 +00:00
|
|
|
|
|
|
|
export interface SelfServeComponentProps {
|
|
|
|
descriptor: SelfServeDescriptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface SelfServeComponentState {
|
|
|
|
root: SelfServeDescriptor;
|
2021-01-26 17:44:14 +00:00
|
|
|
currentValues: Map<string, SmartUiInput>;
|
|
|
|
baselineValues: Map<string, SmartUiInput>;
|
|
|
|
isInitializing: boolean;
|
2021-03-10 00:07:23 +00:00
|
|
|
isSaving: boolean;
|
2021-01-26 17:44:14 +00:00
|
|
|
hasErrors: boolean;
|
|
|
|
compileErrorMessage: string;
|
|
|
|
refreshResult: RefreshResult;
|
2021-03-10 00:07:23 +00:00
|
|
|
notification: SelfServeNotification;
|
2021-01-20 06:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class SelfServeComponent extends React.Component<SelfServeComponentProps, SelfServeComponentState> {
|
2021-03-10 00:07:23 +00:00
|
|
|
private static readonly defaultRetryIntervalInMs = 30000;
|
2021-01-28 19:17:02 +00:00
|
|
|
private smartUiGeneratorClassName: string;
|
2021-03-10 00:07:23 +00:00
|
|
|
private retryIntervalInMs: number;
|
|
|
|
private retryOptions: promiseRetry.Options;
|
|
|
|
private translationFunction: TFunction;
|
2021-01-28 19:17:02 +00:00
|
|
|
|
2021-01-20 06:42:45 +00:00
|
|
|
componentDidMount(): void {
|
2021-03-10 00:07:23 +00:00
|
|
|
this.performRefresh().then(() => {
|
|
|
|
if (this.state.refreshResult?.isUpdateInProgress) {
|
|
|
|
promiseRetry(() => this.pollRefresh(), this.retryOptions);
|
|
|
|
}
|
|
|
|
});
|
2021-01-20 06:42:45 +00:00
|
|
|
this.initializeSmartUiComponent();
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props: SelfServeComponentProps) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
root: this.props.descriptor,
|
|
|
|
currentValues: new Map(),
|
|
|
|
baselineValues: new Map(),
|
2021-01-26 17:44:14 +00:00
|
|
|
isInitializing: true,
|
2021-03-10 00:07:23 +00:00
|
|
|
isSaving: false,
|
2021-01-26 17:44:14 +00:00
|
|
|
hasErrors: false,
|
|
|
|
compileErrorMessage: undefined,
|
|
|
|
refreshResult: undefined,
|
2021-03-10 00:07:23 +00:00
|
|
|
notification: undefined,
|
2021-01-20 06:42:45 +00:00
|
|
|
};
|
2021-01-28 19:17:02 +00:00
|
|
|
this.smartUiGeneratorClassName = this.props.descriptor.root.id;
|
2021-03-10 00:07:23 +00:00
|
|
|
this.retryIntervalInMs = this.props.descriptor.refreshParams?.retryIntervalInMs;
|
|
|
|
if (!this.retryIntervalInMs) {
|
|
|
|
this.retryIntervalInMs = SelfServeComponent.defaultRetryIntervalInMs;
|
|
|
|
}
|
|
|
|
this.retryOptions = { forever: true, maxTimeout: this.retryIntervalInMs, minTimeout: this.retryIntervalInMs };
|
2021-01-20 06:42:45 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 17:44:14 +00:00
|
|
|
private onError = (hasErrors: boolean): void => {
|
|
|
|
this.setState({ hasErrors });
|
|
|
|
};
|
|
|
|
|
2021-01-20 06:42:45 +00:00
|
|
|
private initializeSmartUiComponent = async (): Promise<void> => {
|
2021-01-26 17:44:14 +00:00
|
|
|
this.setState({ isInitializing: true });
|
2021-01-20 06:42:45 +00:00
|
|
|
await this.setDefaults();
|
2021-01-26 17:44:14 +00:00
|
|
|
const { currentValues, baselineValues } = this.state;
|
|
|
|
await this.initializeSmartUiNode(this.props.descriptor.root, currentValues, baselineValues);
|
|
|
|
this.setState({ isInitializing: false, currentValues, baselineValues });
|
2021-01-20 06:42:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private setDefaults = async (): Promise<void> => {
|
|
|
|
let { currentValues, baselineValues } = this.state;
|
|
|
|
|
|
|
|
const initialValues = await this.props.descriptor.initialize();
|
2021-01-26 17:44:14 +00:00
|
|
|
this.props.descriptor.inputNames.map((inputName) => {
|
|
|
|
let initialValue = initialValues.get(inputName);
|
|
|
|
if (!initialValue) {
|
|
|
|
initialValue = { value: undefined, hidden: false };
|
|
|
|
}
|
|
|
|
currentValues = currentValues.set(inputName, initialValue);
|
|
|
|
baselineValues = baselineValues.set(inputName, initialValue);
|
|
|
|
initialValues.delete(inputName);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (initialValues.size > 0) {
|
|
|
|
const keys = [];
|
|
|
|
for (const key of initialValues.keys()) {
|
|
|
|
keys.push(key);
|
2021-01-20 06:42:45 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 17:44:14 +00:00
|
|
|
this.setState({
|
|
|
|
compileErrorMessage: `The following fields have default values set but are not input properties of this class: ${keys.join(
|
|
|
|
", "
|
|
|
|
)}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.setState({ currentValues, baselineValues });
|
|
|
|
};
|
|
|
|
|
2021-03-10 00:07:23 +00:00
|
|
|
public updateBaselineValues = (): void => {
|
2021-01-26 17:44:14 +00:00
|
|
|
const currentValues = this.state.currentValues;
|
|
|
|
let baselineValues = this.state.baselineValues;
|
|
|
|
for (const key of currentValues.keys()) {
|
|
|
|
const currentValue = currentValues.get(key);
|
|
|
|
baselineValues = baselineValues.set(key, { ...currentValue });
|
2021-01-20 06:42:45 +00:00
|
|
|
}
|
2021-01-26 17:44:14 +00:00
|
|
|
this.setState({ baselineValues });
|
2021-01-20 06:42:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public discard = (): void => {
|
|
|
|
let { currentValues } = this.state;
|
|
|
|
const { baselineValues } = this.state;
|
2021-01-26 17:44:14 +00:00
|
|
|
for (const key of currentValues.keys()) {
|
|
|
|
const baselineValue = baselineValues.get(key);
|
|
|
|
currentValues = currentValues.set(key, { ...baselineValue });
|
2021-01-20 06:42:45 +00:00
|
|
|
}
|
|
|
|
this.setState({ currentValues });
|
|
|
|
};
|
|
|
|
|
2021-01-26 17:44:14 +00:00
|
|
|
private initializeSmartUiNode = async (
|
|
|
|
currentNode: Node,
|
|
|
|
currentValues: Map<string, SmartUiInput>,
|
|
|
|
baselineValues: Map<string, SmartUiInput>
|
|
|
|
): Promise<void> => {
|
2021-01-20 06:42:45 +00:00
|
|
|
currentNode.info = await this.getResolvedValue(currentNode.info);
|
|
|
|
|
|
|
|
if (currentNode.input) {
|
2021-01-26 17:44:14 +00:00
|
|
|
currentNode.input = await this.getResolvedInput(currentNode.input, currentValues, baselineValues);
|
2021-01-20 06:42:45 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 17:44:14 +00:00
|
|
|
const promises = currentNode.children?.map(
|
|
|
|
async (child: Node) => await this.initializeSmartUiNode(child, currentValues, baselineValues)
|
|
|
|
);
|
2021-01-20 06:42:45 +00:00
|
|
|
if (promises) {
|
|
|
|
await Promise.all(promises);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-26 17:44:14 +00:00
|
|
|
private getResolvedInput = async (
|
|
|
|
input: AnyDisplay,
|
|
|
|
currentValues: Map<string, SmartUiInput>,
|
|
|
|
baselineValues: Map<string, SmartUiInput>
|
|
|
|
): Promise<AnyDisplay> => {
|
2021-01-28 19:17:02 +00:00
|
|
|
input.labelTKey = await this.getResolvedValue(input.labelTKey);
|
|
|
|
input.placeholderTKey = await this.getResolvedValue(input.placeholderTKey);
|
2021-01-20 06:42:45 +00:00
|
|
|
|
|
|
|
switch (input.type) {
|
|
|
|
case "string": {
|
2021-01-26 17:44:14 +00:00
|
|
|
if ("description" in input) {
|
|
|
|
const descriptionDisplay = input as DescriptionDisplay;
|
|
|
|
descriptionDisplay.description = await this.getResolvedValue(descriptionDisplay.description);
|
|
|
|
}
|
2021-01-20 06:42:45 +00:00
|
|
|
return input as StringInput;
|
|
|
|
}
|
|
|
|
case "number": {
|
|
|
|
const numberInput = input as NumberInput;
|
|
|
|
numberInput.min = await this.getResolvedValue(numberInput.min);
|
|
|
|
numberInput.max = await this.getResolvedValue(numberInput.max);
|
|
|
|
numberInput.step = await this.getResolvedValue(numberInput.step);
|
2021-01-26 17:44:14 +00:00
|
|
|
|
|
|
|
const dataFieldName = numberInput.dataFieldName;
|
|
|
|
const defaultValue = currentValues.get(dataFieldName)?.value;
|
|
|
|
|
|
|
|
if (!defaultValue) {
|
|
|
|
const newDefaultValue = { value: numberInput.min, hidden: currentValues.get(dataFieldName)?.hidden };
|
|
|
|
currentValues.set(dataFieldName, newDefaultValue);
|
|
|
|
baselineValues.set(dataFieldName, newDefaultValue);
|
|
|
|
}
|
|
|
|
|
2021-01-20 06:42:45 +00:00
|
|
|
return numberInput;
|
|
|
|
}
|
|
|
|
case "boolean": {
|
|
|
|
const booleanInput = input as BooleanInput;
|
2021-01-28 19:17:02 +00:00
|
|
|
booleanInput.trueLabelTKey = await this.getResolvedValue(booleanInput.trueLabelTKey);
|
|
|
|
booleanInput.falseLabelTKey = await this.getResolvedValue(booleanInput.falseLabelTKey);
|
2021-01-20 06:42:45 +00:00
|
|
|
return booleanInput;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
const choiceInput = input as ChoiceInput;
|
|
|
|
choiceInput.choices = await this.getResolvedValue(choiceInput.choices);
|
|
|
|
return choiceInput;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public async getResolvedValue<T>(value: T | (() => Promise<T>)): Promise<T> {
|
|
|
|
if (value instanceof Function) {
|
|
|
|
return value();
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-01-26 17:44:14 +00:00
|
|
|
private onInputChange = (input: AnyDisplay, newValue: InputType) => {
|
2021-01-20 06:42:45 +00:00
|
|
|
if (input.onChange) {
|
2021-03-10 00:07:23 +00:00
|
|
|
const newValues = input.onChange(
|
|
|
|
newValue,
|
|
|
|
this.state.currentValues,
|
|
|
|
this.state.baselineValues as ReadonlyMap<string, SmartUiInput>
|
|
|
|
);
|
2021-01-20 06:42:45 +00:00
|
|
|
this.setState({ currentValues: newValues });
|
|
|
|
} else {
|
|
|
|
const dataFieldName = input.dataFieldName;
|
|
|
|
const { currentValues } = this.state;
|
2021-01-26 17:44:14 +00:00
|
|
|
const currentInputValue = currentValues.get(dataFieldName);
|
|
|
|
currentValues.set(dataFieldName, { value: newValue, hidden: currentInputValue?.hidden });
|
2021-01-20 06:42:45 +00:00
|
|
|
this.setState({ currentValues });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-10 00:07:23 +00:00
|
|
|
public performSave = async (): Promise<void> => {
|
|
|
|
this.setState({ isSaving: true, notification: undefined });
|
|
|
|
try {
|
|
|
|
const onSaveResult = await this.props.descriptor.onSave(
|
|
|
|
this.state.currentValues,
|
|
|
|
this.state.baselineValues as ReadonlyMap<string, SmartUiInput>
|
|
|
|
);
|
|
|
|
if (onSaveResult.portalNotification) {
|
|
|
|
const requestInitializedPortalNotification = onSaveResult.portalNotification.initialize;
|
|
|
|
const requestSucceededPortalNotification = onSaveResult.portalNotification.success;
|
|
|
|
const requestFailedPortalNotification = onSaveResult.portalNotification.failure;
|
|
|
|
|
|
|
|
this.sendNotificationMessage({
|
|
|
|
retryIntervalInMs: this.retryIntervalInMs,
|
|
|
|
operationStatusUrl: onSaveResult.operationStatusUrl,
|
|
|
|
portalNotification: {
|
|
|
|
initialize: {
|
|
|
|
title: this.getTranslation(requestInitializedPortalNotification.titleTKey),
|
|
|
|
message: this.getTranslation(requestInitializedPortalNotification.messageTKey),
|
|
|
|
},
|
|
|
|
success: {
|
|
|
|
title: this.getTranslation(requestSucceededPortalNotification.titleTKey),
|
|
|
|
message: this.getTranslation(requestSucceededPortalNotification.messageTKey),
|
|
|
|
},
|
|
|
|
failure: {
|
|
|
|
title: this.getTranslation(requestFailedPortalNotification.titleTKey),
|
|
|
|
message: this.getTranslation(requestFailedPortalNotification.messageTKey),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
promiseRetry(() => this.pollRefresh(), this.retryOptions);
|
|
|
|
} catch (error) {
|
2021-01-26 17:44:14 +00:00
|
|
|
this.setState({
|
|
|
|
notification: {
|
2021-03-10 00:07:23 +00:00
|
|
|
type: MessageBarType.error,
|
|
|
|
isCancellable: true,
|
|
|
|
message: this.getTranslation(error.message),
|
2021-01-26 17:44:14 +00:00
|
|
|
},
|
|
|
|
});
|
2021-03-10 00:07:23 +00:00
|
|
|
throw error;
|
|
|
|
} finally {
|
|
|
|
this.setState({ isSaving: false });
|
|
|
|
}
|
|
|
|
await this.onRefreshClicked();
|
|
|
|
this.updateBaselineValues();
|
|
|
|
};
|
|
|
|
|
|
|
|
public onSaveButtonClick = (): void => {
|
|
|
|
this.performSave();
|
2021-01-26 17:44:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public isDiscardButtonDisabled = (): boolean => {
|
2021-03-10 00:07:23 +00:00
|
|
|
if (this.state.isSaving) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-26 17:44:14 +00:00
|
|
|
for (const key of this.state.currentValues.keys()) {
|
|
|
|
const currentValue = JSON.stringify(this.state.currentValues.get(key));
|
|
|
|
const baselineValue = JSON.stringify(this.state.baselineValues.get(key));
|
|
|
|
|
|
|
|
if (currentValue !== baselineValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
public isSaveButtonDisabled = (): boolean => {
|
2021-03-10 00:07:23 +00:00
|
|
|
if (this.state.hasErrors || this.state.isSaving) {
|
2021-01-26 17:44:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (const key of this.state.currentValues.keys()) {
|
|
|
|
const currentValue = JSON.stringify(this.state.currentValues.get(key));
|
|
|
|
const baselineValue = JSON.stringify(this.state.baselineValues.get(key));
|
|
|
|
|
|
|
|
if (currentValue !== baselineValue) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2021-03-10 00:07:23 +00:00
|
|
|
private performRefresh = async (): Promise<void> => {
|
2021-01-26 17:44:14 +00:00
|
|
|
const refreshResult = await this.props.descriptor.onRefresh();
|
2021-03-10 00:07:23 +00:00
|
|
|
let updateInProgressNotification: SelfServeNotification;
|
|
|
|
if (this.state.refreshResult?.isUpdateInProgress && !refreshResult.isUpdateInProgress) {
|
|
|
|
await this.initializeSmartUiComponent();
|
|
|
|
}
|
|
|
|
if (refreshResult.isUpdateInProgress) {
|
|
|
|
updateInProgressNotification = {
|
|
|
|
type: MessageBarType.info,
|
|
|
|
isCancellable: false,
|
|
|
|
message: this.getTranslation(refreshResult.updateInProgressMessageTKey),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
refreshResult: { ...refreshResult },
|
|
|
|
notification: updateInProgressNotification,
|
|
|
|
});
|
2021-01-26 17:44:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public onRefreshClicked = async (): Promise<void> => {
|
|
|
|
this.setState({ isInitializing: true });
|
2021-03-10 00:07:23 +00:00
|
|
|
await this.performRefresh();
|
2021-01-26 17:44:14 +00:00
|
|
|
this.setState({ isInitializing: false });
|
|
|
|
};
|
|
|
|
|
2021-03-10 00:07:23 +00:00
|
|
|
public pollRefresh = async (): Promise<void> => {
|
|
|
|
try {
|
|
|
|
await this.performRefresh();
|
|
|
|
} catch (error) {
|
|
|
|
throw new AbortError(error);
|
|
|
|
}
|
|
|
|
const refreshResult = this.state.refreshResult;
|
|
|
|
if (refreshResult.isUpdateInProgress) {
|
|
|
|
throw new Error("update in progress. retrying ...");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public getCommonTranslation = (key: string): string => {
|
|
|
|
return this.getTranslation(key, "Common");
|
2021-01-28 19:17:02 +00:00
|
|
|
};
|
|
|
|
|
2021-03-10 00:07:23 +00:00
|
|
|
private getTranslation = (messageKey: string, prefix = `${this.smartUiGeneratorClassName}`): string => {
|
|
|
|
const translationKey = `${prefix}.${messageKey}`;
|
|
|
|
const translation = this.translationFunction ? this.translationFunction(translationKey) : messageKey;
|
|
|
|
if (translation === translationKey) {
|
|
|
|
return messageKey;
|
|
|
|
}
|
|
|
|
return translation;
|
|
|
|
};
|
|
|
|
|
|
|
|
private getCommandBarItems = (): ICommandBarItemProps[] => {
|
2021-01-26 17:44:14 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
key: "save",
|
2021-03-10 00:07:23 +00:00
|
|
|
text: this.getCommonTranslation("Save"),
|
2021-01-26 17:44:14 +00:00
|
|
|
iconProps: { iconName: "Save" },
|
|
|
|
split: true,
|
|
|
|
disabled: this.isSaveButtonDisabled(),
|
2021-03-10 00:07:23 +00:00
|
|
|
onClick: () => this.onSaveButtonClick(),
|
2021-01-26 17:44:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "discard",
|
2021-03-10 00:07:23 +00:00
|
|
|
text: this.getCommonTranslation("Discard"),
|
2021-01-26 17:44:14 +00:00
|
|
|
iconProps: { iconName: "Undo" },
|
|
|
|
split: true,
|
|
|
|
disabled: this.isDiscardButtonDisabled(),
|
|
|
|
onClick: () => {
|
|
|
|
this.discard();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "refresh",
|
2021-03-10 00:07:23 +00:00
|
|
|
text: this.getCommonTranslation("Refresh"),
|
2021-01-26 17:44:14 +00:00
|
|
|
disabled: this.state.isInitializing,
|
|
|
|
iconProps: { iconName: "Refresh" },
|
|
|
|
split: true,
|
|
|
|
onClick: () => {
|
|
|
|
this.onRefreshClicked();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2021-03-10 00:07:23 +00:00
|
|
|
private sendNotificationMessage = (portalNotificationContent: PortalNotificationContent): void => {
|
|
|
|
sendMessage({
|
|
|
|
type: SelfServeMessageTypes.Notification,
|
|
|
|
data: { portalNotificationContent },
|
|
|
|
});
|
2021-01-28 19:17:02 +00:00
|
|
|
};
|
|
|
|
|
2021-01-20 06:42:45 +00:00
|
|
|
public render(): JSX.Element {
|
2021-01-26 17:44:14 +00:00
|
|
|
const containerStackTokens: IStackTokens = { childrenGap: 5 };
|
|
|
|
if (this.state.compileErrorMessage) {
|
|
|
|
return <MessageBar messageBarType={MessageBarType.error}>{this.state.compileErrorMessage}</MessageBar>;
|
|
|
|
}
|
|
|
|
return (
|
2021-01-28 19:17:02 +00:00
|
|
|
<Translation>
|
|
|
|
{(translate) => {
|
2021-03-10 00:07:23 +00:00
|
|
|
if (!this.translationFunction) {
|
|
|
|
this.translationFunction = translate;
|
|
|
|
}
|
2021-01-28 19:17:02 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={{ overflowX: "auto" }}>
|
|
|
|
<Stack tokens={containerStackTokens} styles={{ root: { padding: 10 } }}>
|
2021-03-10 00:07:23 +00:00
|
|
|
<CommandBar styles={{ root: { paddingLeft: 0 } }} items={this.getCommandBarItems()} />
|
2021-01-28 19:17:02 +00:00
|
|
|
{this.state.isInitializing ? (
|
|
|
|
<Spinner
|
|
|
|
size={SpinnerSize.large}
|
|
|
|
styles={{ root: { textAlign: "center", justifyContent: "center", width: "100%", height: "100%" } }}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{this.state.notification && (
|
|
|
|
<MessageBar
|
2021-03-10 00:07:23 +00:00
|
|
|
messageBarType={this.state.notification.type}
|
|
|
|
onDismiss={
|
|
|
|
this.state.notification.isCancellable
|
|
|
|
? () => this.setState({ notification: undefined })
|
|
|
|
: undefined
|
|
|
|
}
|
2021-01-28 19:17:02 +00:00
|
|
|
>
|
2021-03-10 00:07:23 +00:00
|
|
|
{this.state.notification.message}
|
2021-01-28 19:17:02 +00:00
|
|
|
</MessageBar>
|
|
|
|
)}
|
|
|
|
<SmartUiComponent
|
2021-03-10 00:07:23 +00:00
|
|
|
disabled={this.state.refreshResult?.isUpdateInProgress || this.state.isSaving}
|
2021-01-28 19:17:02 +00:00
|
|
|
descriptor={this.state.root as SmartUiDescriptor}
|
|
|
|
currentValues={this.state.currentValues}
|
|
|
|
onInputChange={this.onInputChange}
|
|
|
|
onError={this.onError}
|
2021-03-10 00:07:23 +00:00
|
|
|
getTranslation={this.getTranslation}
|
2021-01-28 19:17:02 +00:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Stack>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</Translation>
|
2021-01-20 06:42:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|