2021-01-20 06:42:45 +00:00
|
|
|
import {
|
2021-01-26 17:44:14 +00:00
|
|
|
CommandBar,
|
|
|
|
ICommandBarItemProps,
|
|
|
|
MessageBar,
|
|
|
|
MessageBarType,
|
2021-03-18 20:40:48 +00:00
|
|
|
Separator,
|
2021-01-26 17:44:14 +00:00
|
|
|
Spinner,
|
|
|
|
SpinnerSize,
|
|
|
|
Stack,
|
2021-03-30 18:11:43 +01:00
|
|
|
Text,
|
2021-05-06 00:26:03 +01:00
|
|
|
} from "@fluentui/react";
|
2021-05-11 01:36:50 +01:00
|
|
|
import { TFunction } from "i18next";
|
2021-03-18 20:40:48 +00:00
|
|
|
import promiseRetry, { AbortError } from "p-retry";
|
|
|
|
import React from "react";
|
2021-03-30 18:11:43 +01:00
|
|
|
import { WithTranslation } from "react-i18next";
|
2021-03-18 20:40:48 +00:00
|
|
|
import * as _ from "underscore";
|
|
|
|
import { sendMessage } from "../Common/MessageHandler";
|
|
|
|
import { SelfServeMessageTypes } from "../Contracts/SelfServeContracts";
|
|
|
|
import { SmartUiComponent, SmartUiDescriptor } from "../Explorer/Controls/SmartUi/SmartUiComponent";
|
2021-05-24 20:36:57 +01:00
|
|
|
import { Action, ActionModifiers } from "../Shared/Telemetry/TelemetryConstants";
|
|
|
|
import { trace } from "../Shared/Telemetry/TelemetryProcessor";
|
2021-03-18 20:40:48 +00:00
|
|
|
import { commandBarItemStyles, commandBarStyles, containerStackTokens, separatorStyles } from "./SelfServeStyles";
|
2021-01-26 17:44:14 +00:00
|
|
|
import {
|
|
|
|
AnyDisplay,
|
2021-03-18 20:40:48 +00:00
|
|
|
BooleanInput,
|
|
|
|
ChoiceInput,
|
|
|
|
DescriptionDisplay,
|
2021-01-20 06:42:45 +00:00
|
|
|
InputType,
|
2021-03-18 20:40:48 +00:00
|
|
|
Node,
|
|
|
|
NumberInput,
|
2021-01-26 17:44:14 +00:00
|
|
|
RefreshResult,
|
2021-05-24 20:36:57 +01:00
|
|
|
SelfServeComponentTelemetryType,
|
2021-01-26 17:44:14 +00:00
|
|
|
SelfServeDescriptor,
|
|
|
|
SmartUiInput,
|
|
|
|
StringInput,
|
|
|
|
} from "./SelfServeTypes";
|
2021-03-10 00:07:23 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-03-30 18:11:43 +01:00
|
|
|
export interface SelfServeComponentProps extends WithTranslation {
|
2021-01-20 06:42:45 +00:00
|
|
|
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();
|
2021-05-24 20:36:57 +01:00
|
|
|
|
|
|
|
const telemetryData = {
|
|
|
|
selfServeClassName: this.props.descriptor.root.id,
|
|
|
|
eventType: SelfServeComponentTelemetryType.Load,
|
|
|
|
};
|
|
|
|
trace(Action.SelfServeComponent, ActionModifiers.Mark, telemetryData, SelfServeMessageTypes.TelemetryInfo);
|
2021-01-20 06:42:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-03-30 18:11:43 +01:00
|
|
|
|
|
|
|
// translation function passed to SelfServeComponent
|
|
|
|
this.translationFunction = this.props.t;
|
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) => {
|
2021-05-11 01:36:50 +01:00
|
|
|
const initialValue = initialValues.get(inputName);
|
2021-01-26 17:44:14 +00:00
|
|
|
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);
|
2021-05-21 21:19:07 +01:00
|
|
|
currentValues = currentValues.set(key, baselineValue ? { ...baselineValue } : 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> => {
|
2021-05-24 20:36:57 +01:00
|
|
|
const telemetryData = {
|
|
|
|
selfServeClassName: this.props.descriptor.root.id,
|
|
|
|
eventType: SelfServeComponentTelemetryType.Save,
|
|
|
|
};
|
|
|
|
trace(Action.SelfServeComponent, ActionModifiers.Mark, telemetryData, SelfServeMessageTypes.TelemetryInfo);
|
|
|
|
|
2021-03-10 00:07:23 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-03-18 20:40:48 +00:00
|
|
|
public isInputModified = (): boolean => {
|
2021-01-26 17:44:14 +00:00
|
|
|
for (const key of this.state.currentValues.keys()) {
|
2021-03-18 20:40:48 +00:00
|
|
|
const currentValue = this.state.currentValues.get(key);
|
|
|
|
if (currentValue && currentValue.hidden === undefined) {
|
|
|
|
currentValue.hidden = false;
|
|
|
|
}
|
|
|
|
if (currentValue && currentValue.disabled === undefined) {
|
|
|
|
currentValue.disabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const baselineValue = this.state.baselineValues.get(key);
|
|
|
|
if (baselineValue && baselineValue.hidden === undefined) {
|
|
|
|
baselineValue.hidden = false;
|
|
|
|
}
|
|
|
|
if (baselineValue && baselineValue.disabled === undefined) {
|
|
|
|
baselineValue.disabled = false;
|
|
|
|
}
|
2021-01-26 17:44:14 +00:00
|
|
|
|
2021-03-18 20:40:48 +00:00
|
|
|
if (!_.isEqual(currentValue, baselineValue)) {
|
|
|
|
return true;
|
2021-01-26 17:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-18 20:40:48 +00:00
|
|
|
return false;
|
2021-01-26 17:44:14 +00:00
|
|
|
};
|
|
|
|
|
2021-03-18 20:40:48 +00:00
|
|
|
public isRefreshing = (): boolean => {
|
|
|
|
return this.state.isSaving || this.state.isInitializing || this.state.refreshResult?.isUpdateInProgress;
|
|
|
|
};
|
2021-01-26 17:44:14 +00:00
|
|
|
|
2021-03-18 20:40:48 +00:00
|
|
|
public isDiscardButtonDisabled = (): boolean => {
|
|
|
|
return this.isRefreshing() || !this.isInputModified();
|
|
|
|
};
|
|
|
|
|
|
|
|
public isSaveButtonDisabled = (): boolean => {
|
|
|
|
return this.state.hasErrors || this.isRefreshing() || !this.isInputModified();
|
2021-01-26 17:44:14 +00:00
|
|
|
};
|
|
|
|
|
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-30 18:11:43 +01:00
|
|
|
private getTranslation = (messageKey: string, namespace = `${this.smartUiGeneratorClassName}`): string => {
|
|
|
|
const translationKey = `${namespace}:${messageKey}`;
|
2021-03-10 00:07:23 +00:00
|
|
|
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" },
|
|
|
|
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" },
|
|
|
|
disabled: this.isDiscardButtonDisabled(),
|
|
|
|
onClick: () => {
|
|
|
|
this.discard();
|
|
|
|
},
|
2021-03-18 20:40:48 +00:00
|
|
|
buttonStyles: commandBarItemStyles,
|
2021-01-26 17:44:14 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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" },
|
|
|
|
onClick: () => {
|
|
|
|
this.onRefreshClicked();
|
|
|
|
},
|
2021-03-18 20:40:48 +00:00
|
|
|
buttonStyles: commandBarItemStyles,
|
2021-01-26 17:44:14 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
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
|
|
|
if (this.state.compileErrorMessage) {
|
2021-03-30 18:11:43 +01:00
|
|
|
return (
|
|
|
|
<MessageBar messageBarType={MessageBarType.error}>
|
|
|
|
<Text>{this.state.compileErrorMessage}</Text>
|
|
|
|
</MessageBar>
|
|
|
|
);
|
2021-01-26 17:44:14 +00:00
|
|
|
}
|
|
|
|
return (
|
2021-03-30 18:11:43 +01:00
|
|
|
<div style={{ overflowX: "auto" }}>
|
|
|
|
<Stack tokens={containerStackTokens}>
|
|
|
|
<Stack.Item>
|
|
|
|
<CommandBar styles={commandBarStyles} items={this.getCommandBarItems()} />
|
|
|
|
<Separator styles={separatorStyles} />
|
|
|
|
</Stack.Item>
|
|
|
|
{this.state.isInitializing ? (
|
|
|
|
<Spinner size={SpinnerSize.large} />
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{this.state.notification && (
|
|
|
|
<MessageBar
|
|
|
|
messageBarType={this.state.notification.type}
|
|
|
|
onDismiss={
|
|
|
|
this.state.notification.isCancellable ? () => this.setState({ notification: undefined }) : undefined
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Text>{this.state.notification.message}</Text>
|
|
|
|
</MessageBar>
|
|
|
|
)}
|
|
|
|
<SmartUiComponent
|
|
|
|
disabled={this.state.refreshResult?.isUpdateInProgress || this.state.isSaving}
|
|
|
|
descriptor={this.state.root as SmartUiDescriptor}
|
|
|
|
currentValues={this.state.currentValues}
|
|
|
|
onInputChange={this.onInputChange}
|
|
|
|
onError={this.onError}
|
|
|
|
getTranslation={this.getTranslation}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Stack>
|
|
|
|
</div>
|
2021-01-20 06:42:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|