Browse Source

Feature/extend alert dialog with copy-to-clipboard functionality (#7258)

* Extend alert dialog with copy-to-clipboard functionality

* Update changelog
pull/7262/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
0b94f87f32
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 6
      apps/client/src/app/components/user-account-membership/user-account-membership.component.ts
  3. 29
      libs/ui/src/lib/notifications/alert-dialog/alert-dialog.component.ts
  4. 16
      libs/ui/src/lib/notifications/alert-dialog/alert-dialog.html
  5. 1
      libs/ui/src/lib/notifications/alert-dialog/interfaces/interfaces.ts
  6. 1
      libs/ui/src/lib/notifications/interfaces/interfaces.ts
  7. 1
      libs/ui/src/lib/notifications/notification.service.ts

4
CHANGELOG.md

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Added
- Added support for a copy-to-clipboard action in the alert dialog component
### Changed
- Set the change detection strategy to `OnPush` in the _FIRE_ page

6
apps/client/src/app/components/user-account-membership/user-account-membership.component.ts

@ -146,11 +146,9 @@ export class GfUserAccountMembershipComponent {
)
.subscribe(({ apiKey }) => {
this.notificationService.alert({
copyValue: apiKey,
discardLabel: $localize`Okay`,
message:
$localize`Set this API key in your self-hosted environment:` +
'<br />' +
apiKey,
message: $localize`Set this API key in your self-hosted environment:`,
title: $localize`Ghostfolio Premium Data Provider API Key`
});
});

29
libs/ui/src/lib/notifications/alert-dialog/alert-dialog.component.ts

@ -1,6 +1,9 @@
import { Clipboard } from '@angular/cdk/clipboard';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatSnackBar } from '@angular/material/snack-bar';
import ms from 'ms';
import { AlertDialogParams } from './interfaces/interfaces';
@ -12,6 +15,7 @@ import { AlertDialogParams } from './interfaces/interfaces';
templateUrl: './alert-dialog.html'
})
export class GfAlertDialogComponent {
public copyValue?: string;
public discardLabel: string;
public message?: string;
public title: string;
@ -19,9 +23,32 @@ export class GfAlertDialogComponent {
protected readonly dialogRef =
inject<MatDialogRef<GfAlertDialogComponent>>(MatDialogRef);
public initialize({ discardLabel, message, title }: AlertDialogParams) {
private readonly clipboard = inject(Clipboard);
private readonly snackBar = inject(MatSnackBar);
public initialize({
copyValue,
discardLabel,
message,
title
}: AlertDialogParams) {
this.copyValue = copyValue;
this.discardLabel = discardLabel;
this.message = message;
this.title = title;
}
public onCopyToClipboard() {
if (this.copyValue) {
this.clipboard.copy(this.copyValue);
this.snackBar.open(
'✅ ' + $localize`The value has been copied to the clipboard`,
undefined,
{
duration: ms('3 seconds')
}
);
}
}
}

16
libs/ui/src/lib/notifications/alert-dialog/alert-dialog.html

@ -2,10 +2,22 @@
<div mat-dialog-title [innerHTML]="title"></div>
}
@if (message) {
<div mat-dialog-content [innerHTML]="message"></div>
@if (message || copyValue) {
<div mat-dialog-content>
@if (message) {
<div [innerHTML]="message"></div>
}
@if (copyValue) {
<div class="mt-2">{{ copyValue }}</div>
}
</div>
}
<div align="end" mat-dialog-actions>
<button mat-button (click)="dialogRef.close()">{{ discardLabel }}</button>
@if (copyValue) {
<button color="primary" mat-flat-button (click)="onCopyToClipboard()">
<ng-container i18n>Copy</ng-container>
</button>
}
</div>

1
libs/ui/src/lib/notifications/alert-dialog/interfaces/interfaces.ts

@ -1,4 +1,5 @@
export interface AlertDialogParams {
copyValue?: string;
discardLabel: string;
message?: string;
title: string;

1
libs/ui/src/lib/notifications/interfaces/interfaces.ts

@ -1,6 +1,7 @@
import { ConfirmationDialogType } from '@ghostfolio/common/enums';
export interface AlertParams {
copyValue?: string;
discardFn?: () => void;
discardLabel?: string;
message?: string;

1
libs/ui/src/lib/notifications/notification.service.ts

@ -31,6 +31,7 @@ export class NotificationService {
});
dialog.componentInstance.initialize({
copyValue: aParams.copyValue,
discardLabel: aParams.discardLabel,
message: aParams.message,
title: aParams.title

Loading…
Cancel
Save