diff --git a/ui-ngx/src/app/core/services/script/node-script-test.service.ts b/ui-ngx/src/app/core/services/script/node-script-test.service.ts index 411f5d2216..600c290edc 100644 --- a/ui-ngx/src/app/core/services/script/node-script-test.service.ts +++ b/ui-ngx/src/app/core/services/script/node-script-test.service.ts @@ -72,12 +72,12 @@ export class NodeScriptTestService { } if (!metadata) { metadata = { - deviceType: 'default', deviceName: 'Test Device', + deviceType: 'default', ts: new Date().getTime() + '' }; } else { - metadata = sortObjectKeys(metadata) as {[key: string]: string}; + metadata = sortObjectKeys(metadata); } if (!msgType) { msgType = 'POST_TELEMETRY_REQUEST'; diff --git a/ui-ngx/src/app/core/utils.ts b/ui-ngx/src/app/core/utils.ts index fff70435bf..bf18c2dcae 100644 --- a/ui-ngx/src/app/core/utils.ts +++ b/ui-ngx/src/app/core/utils.ts @@ -511,9 +511,9 @@ export function padValue(val: any, dec: number): string { return strVal; } -export function sortObjectKeys(obj: object): object{ - return Object.keys(obj).sort().reduce((acc,key)=>{ - acc[key]=obj[key]; +export function sortObjectKeys(obj: T): T { + return Object.keys(obj).sort().reduce((acc, key) => { + acc[key] = obj[key]; return acc; - },{}); + }, {} as T); } diff --git a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts index f5ce96c2e4..a0bed03aad 100644 --- a/ui-ngx/src/app/modules/home/components/event/event-table-config.ts +++ b/ui-ngx/src/app/modules/home/components/event/event-table-config.ts @@ -210,7 +210,7 @@ export class EventTableConfig extends EntityTableConfig { icon: 'more_horiz', isEnabled: (entity) => entity.body.metadata ? entity.body.metadata.length > 0 : false, onAction: ($event, entity) => this.showContent($event, entity.body.metadata, - 'event.metadata', ContentType.JSON) + 'event.metadata', ContentType.JSON, true) }, '40px'), new EntityActionTableColumn('error', 'event.error', @@ -230,21 +230,20 @@ export class EventTableConfig extends EntityTableConfig { } } - showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null): void { + showContent($event: MouseEvent, content: string, title: string, contentType: ContentType = null, sortKeys = false): void { if ($event) { $event.stopPropagation(); } - let sortedContent: string; - try { - sortedContent = JSON.stringify(sortObjectKeys(JSON.parse(content))); - } catch() { - sortedContent = content; + if (contentType === ContentType.JSON && sortKeys) { + try { + content = JSON.stringify(sortObjectKeys(JSON.parse(content))); + } catch (e) {} } this.dialog.open(EventContentDialogComponent, { disableClose: true, panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], data: { - constent: sortedContent, + content, title, contentType }