Files
zitadel/console/src/app/modules/actions-two/actions-two-targets/actions-two-targets.component.ts
Ramon 0af5346288 fix: Improve Actions V2 Texts and reenable in settings (#9814)
# Which Problems Are Solved
This pr includes improved texts to make the usage of Actions V2 more
easy.
Since the removal of the Actions V2 Feature Flag we removed the code
that checks if it's enabled in the settings sidenav.

# How the Problems Are Solved
Added new texts to translations. Removed sidenav logic that checks for
Actions V2 Feature Flag

# Additional Context

- Part of #7248
- Part of #9688

---------

Co-authored-by: Max Peintner <peintnerm@gmail.com>
Co-authored-by: Max Peintner <max@caos.ch>
(cherry picked from commit d930a09cb0)
2025-04-30 15:23:11 +02:00

94 lines
3.0 KiB
TypeScript

import { ChangeDetectionStrategy, Component, DestroyRef } from '@angular/core';
import { lastValueFrom, Observable, of, ReplaySubject } from 'rxjs';
import { ActionService } from 'src/app/services/action.service';
import { ToastService } from 'src/app/services/toast.service';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { catchError, map, startWith, switchMap } from 'rxjs/operators';
import { MatDialog } from '@angular/material/dialog';
import { ActionTwoAddTargetDialogComponent } from '../actions-two-add-target/actions-two-add-target-dialog.component';
import { MessageInitShape } from '@bufbuild/protobuf';
import { Target } from '@zitadel/proto/zitadel/action/v2beta/target_pb';
import {
CreateTargetRequestSchema,
UpdateTargetRequestSchema,
} from '@zitadel/proto/zitadel/action/v2beta/action_service_pb';
import { InfoSectionType } from '../../info-section/info-section.component';
@Component({
selector: 'cnsl-actions-two-targets',
templateUrl: './actions-two-targets.component.html',
styleUrls: ['./actions-two-targets.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ActionsTwoTargetsComponent {
protected readonly targets$: Observable<Target[]>;
protected readonly refresh$ = new ReplaySubject<true>(1);
constructor(
private readonly actionService: ActionService,
private readonly toast: ToastService,
private readonly destroyRef: DestroyRef,
private readonly dialog: MatDialog,
) {
this.targets$ = this.getTargets$();
}
private getTargets$() {
return this.refresh$.pipe(
startWith(true),
switchMap(() => {
return this.actionService.listTargets({});
}),
map(({ result }) => result),
catchError((err) => {
this.toast.showError(err);
return of([]);
}),
);
}
public async deleteTarget(target: Target) {
await this.actionService.deleteTarget({ id: target.id });
await new Promise((res) => setTimeout(res, 1000));
this.refresh$.next(true);
}
public async openDialog(target?: Target) {
const request$ = this.dialog
.open<
ActionTwoAddTargetDialogComponent,
{ target?: Target },
MessageInitShape<typeof UpdateTargetRequestSchema | typeof CreateTargetRequestSchema>
>(ActionTwoAddTargetDialogComponent, {
width: '550px',
data: {
target: target,
},
})
.afterClosed()
.pipe(takeUntilDestroyed(this.destroyRef));
const request = await lastValueFrom(request$);
if (!request) {
return;
}
try {
if ('id' in request) {
await this.actionService.updateTarget(request);
} else {
const resp = await this.actionService.createTarget(request);
console.log(`Your singing key: ${resp.signingKey}`);
}
await new Promise((res) => setTimeout(res, 1000));
this.refresh$.next(true);
} catch (error) {
console.error(error);
this.toast.showError(error);
}
}
protected readonly InfoSectionType = InfoSectionType;
}