Skip to content

Commit db98b8d

Browse files
committed
Fix delete IoT device metadata
1 parent 49ab0df commit db98b8d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/app/applications/iot-devices/iot-device-edit/iot-device-edit.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ export class IotDeviceEditComponent implements OnInit, OnDestroy {
184184
onSubmit(): void {
185185
this.adjustModelBasedOnType();
186186

187-
if (this.isMetadataSet()) {
187+
if (this.metadataTags.length === 0) {
188+
this.iotDevice.metadata = JSON.stringify({});
189+
} else if (this.isMetadataSet()) {
188190
const invalidKey = this.validateMetadata();
189191

190192
if (!invalidKey) {

src/app/shared/components/forms/form-key-value/form-key-value-list/form-key-value-list.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
22
import { KeyValue } from '@shared/types/tuple.type';
33

44
@Component({
@@ -8,6 +8,7 @@ import { KeyValue } from '@shared/types/tuple.type';
88
})
99
export class FormKeyValueListComponent implements OnInit {
1010
@Input() tags: KeyValue[] = [{}];
11+
@Output() tagsChange = new EventEmitter<KeyValue[]>();
1112
@Input() errorFieldId: string | undefined;
1213

1314
constructor() {}
@@ -19,6 +20,8 @@ export class FormKeyValueListComponent implements OnInit {
1920
}
2021

2122
deleteTag(id: number): void {
22-
this.tags = this.tags.filter((_tag, i) => i !== id);
23+
const newTags = this.tags.filter((_tag, i) => i !== id);
24+
// Update parent with a tag less and banana-in-a-box binding (in html) for the update to propagate 2-way
25+
this.tagsChange.emit(newTags);
2326
}
2427
}

0 commit comments

Comments
 (0)