Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private static getStateFromProps(props: PropertyEditorProps): EnumEditorState | null {
const propertyRecord = props.propertyRecord;
let selectValue: string | number;
// istanbul ignore else
if (propertyRecord && propertyRecord.value.valueFormat === PropertyValueFormat.Primitive) {
const primitiveValue = (propertyRecord.value as PrimitiveValue).value;
if (typeof primitiveValue === "string") {
selectValue = primitiveValue as string;
} else {
selectValue = primitiveValue as number;
}
return { selectValue };
}
return null;
}
private async setStateFromProps() {
const record = this.props.propertyRecord;
let initialValue = "";
// istanbul ignore else
if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
initialValue = (record.value as PrimitiveValue).value as string;
}
const readonly = record && undefined !== record.isReadonly ? record.isReadonly : false;
const isDisabled = record ? record.isDisabled : undefined;
// istanbul ignore else
if (this._isMounted)
this.setState(
{ icon: initialValue, readonly, isDisabled },
() => {
if (this.props.setFocus) {
this.setFocus();
}
},
);
private _resetToOriginalValue() {
const record = this.props.propertyRecord;
let initialDisplayValue = "";
let numberValue = 0;
// istanbul ignore else
if (record) {
// istanbul ignore else
if (record.value.valueFormat === PropertyValueFormat.Primitive) {
const primitiveValue = (record.value as PrimitiveValue);
numberValue = (undefined !== primitiveValue.value) ? primitiveValue.value as number : 0;
if (primitiveValue.displayValue)
initialDisplayValue = primitiveValue.displayValue;
else
initialDisplayValue = (this._formatParams as CustomFormattedNumberParams).formatFunction(numberValue, record.property!.quantityType);
}
}
this.setState({ inputValue: initialDisplayValue });
}
public async getPropertyValue(): Promise {
const record = this.props.propertyRecord;
let propertyValue: PropertyValue | undefined;
// istanbul ignore else
if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
propertyValue = {
valueFormat: PropertyValueFormat.Primitive,
value: this.state.colorValue,
displayValue: "",
};
}
return propertyValue;
}
public async getPropertyValue(): Promise {
const record = this.props.propertyRecord;
let propertyValue: PropertyValue | undefined;
// istanbul ignore else
if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {
propertyValue = {
valueFormat: PropertyValueFormat.Primitive,
value: this.state.checkboxValue,
displayValue: "",
};
}
return propertyValue;
}
const createEnumPropertyRecord = (rowIndex: number, column: ColumnDescription) => {
const value = rowIndex % 4;
const v: PropertyValue = {
valueFormat: PropertyValueFormat.Primitive,
value,
displayValue: value.toString(),
};
const pd: PropertyDescription = {
typename: "enum",
name: column.key,
displayLabel: column.label,
};
column.propertyDescription = pd;
const enumPropertyRecord = new PropertyRecord(v, pd);
enumPropertyRecord.property.enum = { choices: [], isStrict: false };
enumPropertyRecord.property.enum.choices = [
{ label: "Yellow", value: 0 },
{ label: "Red", value: 1 },
{ label: "Green", value: 2 },
{ label: "Blue", value: 3 },
const createValue = (propertyDescription: PropertyDescription, typeDescription: TypeDescription, isMerged: boolean, value: Value, displayValue: DisplayValue): PropertyValue => {
if (undefined === value && undefined === displayValue) {
return {
valueFormat: UiPropertyValueFormat.Primitive,
value,
displayValue: "",
};
}
if (!isMerged) {
if (typeDescription.valueFormat === PropertyValueFormat.Array) {
if (!Value.isArray(value) || !DisplayValue.isArray(displayValue))
throw new PresentationError(PresentationStatus.InvalidArgument, "value and displayValue should both be arrays");
return createArrayValue(propertyDescription, typeDescription, value, displayValue);
}
if (typeDescription.valueFormat === PropertyValueFormat.Struct) {
if (!Value.isMap(value) || !DisplayValue.isMap(displayValue))
throw new PresentationError(PresentationStatus.InvalidArgument, "value and displayValue should both be of map type");
return createStructValue(typeDescription, value, displayValue);
}
}
private async getCellDisplayValue(cellItem: CellItem): Promise {
if (!cellItem.record || cellItem.record!.value.valueFormat !== PropertyValueFormat.Primitive)
return "";
const value = (cellItem.record!.value as PrimitiveValue).value;
if (value === undefined)
return "";
const displayValue = await TypeConverterManager
.getConverter(cellItem.record!.property.typename)
.convertPropertyToString(cellItem.record!.property, value);
return displayValue ? displayValue : "";
}
public canRender(record: PropertyRecord) {
return record.value.valueFormat === PropertyValueFormat.Primitive
&& record.property.typename === "double";
}
private _onEnabledPropertyClicked(property: PropertyRecord, key: string | undefined, rightClick: boolean = false) {
let selectedPropertyKey = this.state.selectedPropertyKey;
let editingPropertyKey = this.state.editingPropertyKey;
if (this.props.isPropertyEditingEnabled && property.value.valueFormat === PropertyValueFormat.Primitive && !rightClick) {
if (this.props.isPropertySelectionEnabled) {
if (selectedPropertyKey === key)
editingPropertyKey = key;
else
editingPropertyKey = undefined;
} else {
editingPropertyKey = key;
}
}
if (editingPropertyKey !== key || rightClick) {
if (rightClick) {
editingPropertyKey = undefined;
if (selectedPropertyKey !== key)
selectedPropertyKey = key;
} else
if (selectedPropertyKey === key) {