aamirxshaikh commented on code in PR #1057:
URL: https://github.com/apache/streampipes/pull/1057#discussion_r1064186705
##########
ui/src/app/connect/dialog/edit-event-property/edit-event-property.component.ts:
##########
@@ -33,159 +44,215 @@ import { EditValueTransformationComponent } from
'./components/edit-value-transf
import { EditUnitTransformationComponent } from
'./components/edit-unit-transformation/edit-unit-transformation.component';
@Component({
- selector: 'sp-edit-event-property',
- templateUrl: './edit-event-property.component.html',
- styleUrls: ['./edit-event-property.component.scss']
+ selector: 'sp-edit-event-property',
+ templateUrl: './edit-event-property.component.html',
+ styleUrls: ['./edit-event-property.component.scss'],
})
export class EditEventPropertyComponent implements OnInit {
-
- @Input() property: EventPropertyUnion;
- @Input() isEditable: boolean;
-
- @Output() propertyChange = new EventEmitter<EventPropertyUnion>();
-
- schemaTransformationComponent: EditSchemaTransformationComponent;
- valueTransformationComponent: EditValueTransformationComponent;
- unitTransformationComponent: EditUnitTransformationComponent;
-
- cachedProperty: any;
-
- isTimestampProperty = false;
- isEventPropertyPrimitive: boolean;
- isEventPropertyNested: boolean;
- isEventPropertyList: boolean;
- isNumericProperty: boolean;
- isSaveBtnEnabled: boolean;
-
- private propertyForm: UntypedFormGroup;
-
- private runtimeDataTypes;
-
- constructor(public dialogRef: DialogRef<EditEventPropertyComponent>,
- private formBuilder: UntypedFormBuilder,
- private dataTypeService: DataTypesService,
- private semanticTypeUtilsService: SemanticTypeUtilsService,
- private semanticTypesService: SemanticTypesService) {
- }
-
- ngOnInit(): void {
- this.cachedProperty = this.copyEp(this.property);
- this.runtimeDataTypes = this.dataTypeService.getDataTypes();
- this.isTimestampProperty =
this.semanticTypeUtilsService.isTimestamp(this.cachedProperty);
- this.isEventPropertyList = this.property instanceof EventPropertyList;
- this.isEventPropertyPrimitive = this.property instanceof
EventPropertyPrimitive;
- this.isEventPropertyNested = this.property instanceof EventPropertyNested;
- this.isNumericProperty =
this.semanticTypeUtilsService.isNumeric(this.cachedProperty) ||
- this.dataTypeService.isNumeric(this.cachedProperty.runtimeType);
- this.createForm();
-
- }
-
- copyEp(ep: EventPropertyUnion) {
- if (ep instanceof EventPropertyPrimitive) {
- const result = EventPropertyPrimitive.fromData(ep as
EventPropertyPrimitive, new EventPropertyPrimitive());
-
- result.measurementUnit = (ep as EventPropertyPrimitive).measurementUnit;
- (result as any).measurementUnitTmp = (ep as any).measurementUnitTmp;
- (result as any).oldMeasurementUnit = (ep as any).oldMeasurementUnit;
- (result as any).hadMeasarumentUnit = (ep as any).hadMeasarumentUnit;
-
- (result as any).timestampTransformationMode = (ep as
any).timestampTransformationMode;
- (result as any).timestampTransformationFormatString = (ep as
any).timestampTransformationFormatString;
- (result as any).timestampTransformationMultiplier = (ep as
any).timestampTransformationMultiplier;
-
- (result as any).staticValue = (ep as any).staticValue;
-
- (result as any).correctionValue = (ep as any).correctionValue;
- (result as any).operator = (ep as any).operator;
-
- return result;
- } else if (ep instanceof EventPropertyNested) {
- return EventPropertyNested.fromData(ep as EventPropertyNested, new
EventPropertyNested());
- } else {
- return EventPropertyList.fromData(ep as EventPropertyList, new
EventPropertyList());
- }
- }
-
- private createForm() {
- this.propertyForm = this.formBuilder.group({
- label: [this.property.label, Validators.required],
- runtimeName: [this.property.runtimeName, Validators.required],
- description: [this.property.description, Validators.required],
- domainProperty: ['', Validators.required],
- dataType: ['', Validators.required]
- });
- }
-
- staticValueAddedByUser() {
- return
(this.property.elementId.startsWith('http://eventProperty.de/staticValue/'));
- }
-
- save(): void {
- this.property.label = this.cachedProperty.label;
- this.property.description = this.cachedProperty.description;
-
- // remove undefined from domain properies array
- this.property.domainProperties =
this.cachedProperty.domainProperties.filter(n => n);
- this.property.runtimeName = this.cachedProperty.runtimeName;
- this.property.propertyScope = this.cachedProperty.propertyScope;
-
- if (this.property instanceof EventPropertyList) {
- // @ts-ignore
- this.property.eventProperty.runtimeType = (this.cachedProperty as
EventPropertyList).eventProperty.runtimeType;
+ @Input() property: EventPropertyUnion;
+ @Input() isEditable: boolean;
+
+ @Output() propertyChange = new EventEmitter<EventPropertyUnion>();
+
+ schemaTransformationComponent: EditSchemaTransformationComponent;
+ valueTransformationComponent: EditValueTransformationComponent;
+ unitTransformationComponent: EditUnitTransformationComponent;
+
+ cachedProperty: any;
+
+ isTimestampProperty = false;
+ isEventPropertyPrimitive: boolean;
+ isEventPropertyNested: boolean;
+ isEventPropertyList: boolean;
+ isNumericProperty: boolean;
+ isSaveBtnEnabled: boolean;
+
+ private propertyForm: UntypedFormGroup;
+
+ private runtimeDataTypes;
+
+ constructor(
+ public dialogRef: DialogRef<EditEventPropertyComponent>,
+ private formBuilder: UntypedFormBuilder,
+ private dataTypeService: DataTypesService,
+ private semanticTypeUtilsService: SemanticTypeUtilsService,
+ private semanticTypesService: SemanticTypesService,
+ ) {}
+
+ ngOnInit(): void {
+ this.cachedProperty = this.copyEp(this.property);
+ this.runtimeDataTypes = this.dataTypeService.getDataTypes();
+ this.isTimestampProperty = this.semanticTypeUtilsService.isTimestamp(
+ this.cachedProperty,
+ );
+ this.isEventPropertyList = this.property instanceof EventPropertyList;
+ this.isEventPropertyPrimitive =
+ this.property instanceof EventPropertyPrimitive;
+ this.isEventPropertyNested =
+ this.property instanceof EventPropertyNested;
+ this.isNumericProperty =
+ this.semanticTypeUtilsService.isNumeric(this.cachedProperty) ||
+ this.dataTypeService.isNumeric(this.cachedProperty.runtimeType);
+ this.createForm();
}
- if (this.property instanceof EventPropertyPrimitive) {
- this.property.runtimeType = (this.cachedProperty as
EventPropertyPrimitive).runtimeType;
-
- this.property.measurementUnit = (this.cachedProperty as
any).oldMeasurementUnit;
+ copyEp(ep: EventPropertyUnion) {
+ if (ep instanceof EventPropertyPrimitive) {
+ const result = EventPropertyPrimitive.fromData(
+ ep as EventPropertyPrimitive,
+ new EventPropertyPrimitive(),
+ );
+
+ result.measurementUnit = (
+ ep as EventPropertyPrimitive
+ ).measurementUnit;
+ (result as any).measurementUnitTmp = (ep as
any).measurementUnitTmp;
+ (result as any).oldMeasurementUnit = (ep as
any).oldMeasurementUnit;
+ (result as any).hadMeasarumentUnit = (ep as
any).hadMeasarumentUnit;
+
+ (result as any).timestampTransformationMode = (
+ ep as any
+ ).timestampTransformationMode;
+ (result as any).timestampTransformationFormatString = (
+ ep as any
+ ).timestampTransformationFormatString;
+ (result as any).timestampTransformationMultiplier = (
+ ep as any
+ ).timestampTransformationMultiplier;
+
+ (result as any).staticValue = (ep as any).staticValue;
+
+ (result as any).correctionValue = (ep as any).correctionValue;
+ (result as any).operator = (ep as any).operator;
+
+ return result;
+ } else if (ep instanceof EventPropertyNested) {
+ return EventPropertyNested.fromData(
+ ep as EventPropertyNested,
+ new EventPropertyNested(),
+ );
+ } else {
+ return EventPropertyList.fromData(
+ ep as EventPropertyList,
+ new EventPropertyList(),
+ );
+ }
+ }
- (this.property as any).measurementUnitTmp = (this.cachedProperty as
any).measurementUnitTmp;
- (this.property as any).oldMeasurementUnit = (this.cachedProperty as
any).oldMeasurementUnit;
- (this.property as any).hadMeasarumentUnit = (this.cachedProperty as
any).hadMeasarumentUnit;
+ private createForm() {
+ this.propertyForm = this.formBuilder.group({
+ label: [this.property.label, Validators.required],
+ runtimeName: [this.property.runtimeName, Validators.required],
+ description: [this.property.description, Validators.required],
+ domainProperty: ['', Validators.required],
+ dataType: ['', Validators.required],
+ });
+ }
- (this.property as any).timestampTransformationMode =
(this.cachedProperty as any).timestampTransformationMode;
- (this.property as any).timestampTransformationFormatString =
(this.cachedProperty as any).timestampTransformationFormatString;
- (this.property as any).timestampTransformationMultiplier =
(this.cachedProperty as any).timestampTransformationMultiplier;
+ staticValueAddedByUser() {
+ return this.property.elementId.startsWith(
+ 'http://eventProperty.de/staticValue/',
+ );
+ }
- (this.property as any).staticValue = (this.cachedProperty as
any).staticValue;
+ save(): void {
+ this.property.label = this.cachedProperty.label;
+ this.property.description = this.cachedProperty.description;
+
+ // remove undefined from domain properies array
+ this.property.domainProperties =
+ this.cachedProperty.domainProperties.filter(n => n);
+ this.property.runtimeName = this.cachedProperty.runtimeName;
+ this.property.propertyScope = this.cachedProperty.propertyScope;
+
+ if (this.property instanceof EventPropertyList) {
+ // @ts-ignore
+ this.property.eventProperty.runtimeType = (
+ this.cachedProperty as EventPropertyList
+ ).eventProperty.runtimeType;
Review Comment:
I have tried removing it. Still getting the same error.
I have come across a quick fix in IDE.

Replace with object destructuring:
```
if (this.property instanceof EventPropertyList) {
// @ts-ignore
({runtimeType: this.property.eventProperty.runtimeType} = (
this.cachedProperty as EventPropertyList
).eventProperty);
}
```
Replace with index access:
```
if (this.property instanceof EventPropertyList) {
// @ts-ignore
this.property.eventProperty.runtimeType = (
this.cachedProperty as EventPropertyList
).eventProperty["runtimeType"];
}
```
Both above code snippets fix the error. So, is it ok if we can use either of
these two?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]