Skip to content

Commit

Permalink
chore(ux): message handling table
Browse files Browse the repository at this point in the history
  • Loading branch information
fdewas-aneo committed Nov 18, 2024
1 parent 951a55f commit cea4f02
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/app/components/table/table-cell.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
@case ('object') {
<app-table-inspect-object [object]="handleNestedKeys(element)" [label]="column.name" />
}
@case ('message') {
<app-table-inspect-message [label]="column.name" [message]="string" />
}
@case ('output') {
<app-table-inspect-message [label]="column.name" [message]="string" />
}
@case ('link') {
<button mat-button (click)="navigate()">
{{ value | emptyCell }}
Expand Down
6 changes: 6 additions & 0 deletions src/app/components/table/table-cell.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Duration, Timestamp } from '@ngx-grpc/well-known-types';
import { DurationPipe } from '@pipes/duration.pipe';
import { EmptyCellPipe } from '@pipes/empty-cell.pipe';
import { Subject } from 'rxjs';
import { TableInspectMessageComponent } from './table-inspect-message.component';
import { TableInspectObjectComponent } from './table-inspect-object.component';

@Component({
Expand All @@ -28,6 +29,7 @@ import { TableInspectObjectComponent } from './table-inspect-object.component';
MatButtonModule,
CountTasksByStatusComponent,
MatCheckboxModule,
TableInspectMessageComponent,
]
})
export class TableCellComponent<T extends DataRaw, S extends Status, O extends TaskOptions | null = null>{
Expand Down Expand Up @@ -78,6 +80,10 @@ export class TableCellComponent<T extends DataRaw, S extends Status, O extends T
return this._value;
}

get string() {
return this._value as string;
}

get durationValue() {
return this._value as Duration;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h2 mat-dialog-title>{{ label }}</h2>

<mat-dialog-content>
<mat-card>{{ message }}</mat-card>
</mat-dialog-content>

<mat-dialog-actions align="end">
<button mat-flat-button (click)="onNoClick()" color="primary">Close</button>
</mat-dialog-actions>
53 changes: 53 additions & 0 deletions src/app/components/table/table-inspect-message-dialog.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Clipboard } from '@angular/cdk/clipboard';
import { Component, Inject, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { IconsService } from '@services/icons.service';
import { NotificationService } from '@services/notification.service';

export interface TableInspectMessageDialogData {
label: string;
message: string;
}

@Component({
selector: 'app-inspect-message-dialog',
templateUrl: 'table-inspect-message-dialog.component.html',
standalone: true,
imports: [
MatCardModule,
MatButtonModule,
MatDialogModule,
],
providers: [
NotificationService,
]
})
export class TableInspectMessageDialogComponent {
get label() {
return this.data.label;
}

get message() {
return this.data.message;
}

constructor(
public dialogRef: MatDialogRef<TableInspectMessageDialogComponent>,
@Inject(MAT_DIALOG_DATA) private data: TableInspectMessageDialogData
) {}

private readonly iconsService = inject(IconsService);
private readonly clipboard = inject(Clipboard);
private readonly notificationService = inject(NotificationService);

copy() {
this.clipboard.copy(this.message);
this.notificationService.success('Message copied');
}

onNoClick(): void {
this.dialogRef.close();
}
}
13 changes: 13 additions & 0 deletions src/app/components/table/table-inspect-message.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@if (message) {
<span>{{croppedMessage}}...</span>
<button mat-icon-button (click)="copy()">
<mat-icon [fontIcon]="getIcon('copy')" />
</button>
@if (displayEye) {
<button mat-icon-button (click)="onView()">
<mat-icon [fontIcon]="getIcon('view')" />
</button>
}
} @else {
<span>-</span>
}
81 changes: 81 additions & 0 deletions src/app/components/table/table-inspect-message.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Clipboard } from '@angular/cdk/clipboard';
import { Component, Input, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { IconsService } from '@services/icons.service';
import { NotificationService } from '@services/notification.service';
import { TableInspectMessageDialogComponent, TableInspectMessageDialogData } from './table-inspect-message-dialog.component';

@Component({
selector: 'app-table-inspect-message',
templateUrl: 'table-inspect-message.component.html',
standalone: true,
imports: [
MatDialogModule,
MatButtonModule,
MatIconModule,
],
providers: [
NotificationService
]
})
export class TableInspectMessageComponent {
@Input({ required: true }) label: string;

@Input({ required: true }) set message(entry: string | undefined) {

if (entry && entry !== '') {
if (entry.length > 5) {
this._croppedMessage = entry.substring(0, 30);
this._message = entry;
this._displayEye = true;
} else {
this._croppedMessage = entry;
}
}
}

private readonly iconsService = inject(IconsService);
private readonly dialog = inject(MatDialog);
private readonly clipboard = inject(Clipboard);
private readonly notificationService = inject(NotificationService);

private _croppedMessage: string | undefined;
private _message: string |undefined;
private _displayEye = false;

get message() {
return this._message;
}

get croppedMessage() {
return this._croppedMessage;
}

get displayEye() {
return this._displayEye;
}

getIcon(name: string) {
return this.iconsService.getIcon(name);
}

onView() {
if (this._message) {
this.dialog.open<TableInspectMessageDialogComponent, TableInspectMessageDialogData>(TableInspectMessageDialogComponent, {
data: {
label: this.label,
message: this._message
}
});
}
}

copy() {
if (this._message) {
this.clipboard.copy(this._message);
this.notificationService.success('Message copied');
}
}
}
2 changes: 2 additions & 0 deletions src/app/tasks/services/tasks-index.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class TasksIndexService implements IndexServiceCustomInterface<TaskSummar
{
name: $localize`Status Message`,
key: 'statusMessage',
type: 'message',
sortable: false,
},
{
Expand Down Expand Up @@ -147,6 +148,7 @@ export class TasksIndexService implements IndexServiceCustomInterface<TaskSummar
{
name: $localize`Error`,
key: 'error',
type: 'output',
sortable: false,
},
{
Expand Down

0 comments on commit cea4f02

Please sign in to comment.