This is an automated email from the ASF dual-hosted git repository.

gongchao pushed a commit to branch alarm-1-3
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git

commit 1b4442bb77015c35ae91822a770a26010c74ffaf
Author: tomsun28 <[email protected]>
AuthorDate: Fri Jan 3 16:30:58 2025 +0800

    [webapp] update labels
    
    Signed-off-by: tomsun28 <[email protected]>
---
 web-app/src/app/pojo/Monitor.ts                          |  3 ---
 .../monitor/monitor-list/monitor-list.component.html     |  8 +++-----
 .../monitor/monitor-list/monitor-list.component.ts       | 16 +++++++++++++++-
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/web-app/src/app/pojo/Monitor.ts b/web-app/src/app/pojo/Monitor.ts
index 649bb67e8..2f42c7053 100644
--- a/web-app/src/app/pojo/Monitor.ts
+++ b/web-app/src/app/pojo/Monitor.ts
@@ -17,8 +17,6 @@
  * under the License.
  */
 
-import { Tag } from './Tag';
-
 export class Monitor {
   id!: number;
   name!: string;
@@ -34,5 +32,4 @@ export class Monitor {
   modifier!: string;
   gmtCreate!: number;
   gmtUpdate!: number;
-  tags!: Tag[];
 }
diff --git 
a/web-app/src/app/routes/monitor/monitor-list/monitor-list.component.html 
b/web-app/src/app/routes/monitor/monitor-list/monitor-list.component.html
index 65e9407bf..84620da17 100644
--- a/web-app/src/app/routes/monitor/monitor-list/monitor-list.component.html
+++ b/web-app/src/app/routes/monitor/monitor-list/monitor-list.component.html
@@ -201,11 +201,9 @@
         </a>
       </td>
       <td nzAlign="left">
-        <a *ngFor="let tag of data?.tags; let i = index" 
routerLink="/monitors" [queryParams]="{ tag: sliceTagName(tag) }">
-          <nz-tag style="margin-top: 2px" [nzColor]="tag?.color" 
class="hoverClass">
-            {{ sliceTagName(tag) }}
-          </nz-tag>
-        </a>
+        <nz-tag *ngFor="let label of data.labels | keyvalue" 
style="margin-top: 2px" [nzColor]="getLabelColor(label.key)">
+          {{ label.key }}:{{ label.value }}
+        </nz-tag>
       </td>
       <td nzAlign="center">{{ (data.gmtUpdate ? data.gmtUpdate : 
data.gmtCreate) | date : 'YYYY-MM-dd HH:mm:ss' }}</td>
       <td nzAlign="center">
diff --git 
a/web-app/src/app/routes/monitor/monitor-list/monitor-list.component.ts 
b/web-app/src/app/routes/monitor/monitor-list/monitor-list.component.ts
index 1184a6bbd..79781adb7 100644
--- a/web-app/src/app/routes/monitor/monitor-list/monitor-list.component.ts
+++ b/web-app/src/app/routes/monitor/monitor-list/monitor-list.component.ts
@@ -594,5 +594,19 @@ export class MonitorListComponent implements OnInit, 
OnDestroy {
     );
   }
 
-  protected readonly sliceTagName = formatTagName;
+  getLabelColor(key: string): string {
+    const colors = ['blue', 'green', 'orange', 'purple', 'cyan'];
+    const index = Math.abs(this.hashString(key)) % colors.length;
+    return colors[index];
+  }
+
+  private hashString(str: string): number {
+    let hash = 0;
+    for (let i = 0; i < str.length; i++) {
+      const char = str.charCodeAt(i);
+      hash = (hash << 5) - hash + char;
+      hash = hash & hash;
+    }
+    return hash;
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to