Files
zitadel/console/src/app/modules/actions-two/actions-two-add-target/actions-two-add-target-dialog.component.ts

116 lines
3.9 KiB
TypeScript
Raw Normal View History

chore!: Introduce ZITADEL v3 (#9645) This PR summarizes multiple changes specifically only available with ZITADEL v3: - feat: Web Keys management (https://github.com/zitadel/zitadel/pull/9526) - fix(cmd): ensure proper working of mirror (https://github.com/zitadel/zitadel/pull/9509) - feat(Authz): system user support for permission check v2 (https://github.com/zitadel/zitadel/pull/9640) - chore(license): change from Apache to AGPL (https://github.com/zitadel/zitadel/pull/9597) - feat(console): list v2 sessions (https://github.com/zitadel/zitadel/pull/9539) - fix(console): add loginV2 feature flag (https://github.com/zitadel/zitadel/pull/9682) - fix(feature flags): allow reading "own" flags (https://github.com/zitadel/zitadel/pull/9649) - feat(console): add Actions V2 UI (https://github.com/zitadel/zitadel/pull/9591) BREAKING CHANGE - feat(webkey): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9445) - chore!: remove CockroachDB Support (https://github.com/zitadel/zitadel/pull/9444) - feat(actions): migrate to v2beta API (https://github.com/zitadel/zitadel/pull/9489) --------- Co-authored-by: Livio Spring <livio.a@gmail.com> Co-authored-by: Stefan Benz <46600784+stebenz@users.noreply.github.com> Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com> Co-authored-by: Ramon <mail@conblem.me> Co-authored-by: Elio Bischof <elio@zitadel.com> Co-authored-by: Kenta Yamaguchi <56732734+KEY60228@users.noreply.github.com> Co-authored-by: Harsha Reddy <harsha.reddy@klaviyo.com> Co-authored-by: Livio Spring <livio@zitadel.com> Co-authored-by: Max Peintner <max@caos.ch> Co-authored-by: Iraq <66622793+kkrime@users.noreply.github.com> Co-authored-by: Florian Forster <florian@zitadel.com> Co-authored-by: Tim Möhlmann <tim+github@zitadel.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Max Peintner <peintnerm@gmail.com>
2025-04-02 16:53:06 +02:00
import { Component, Inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { TranslateModule } from '@ngx-translate/core';
import { CommonModule } from '@angular/common';
import { FormBuilder, FormControl, ReactiveFormsModule } from '@angular/forms';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { InputModule } from '../../input/input.module';
import { requiredValidator } from '../../form-field/validators/validators';
import { MessageInitShape } from '@bufbuild/protobuf';
import { DurationSchema } from '@bufbuild/protobuf/wkt';
import { MatSelectModule } from '@angular/material/select';
import { Target } from '@zitadel/proto/zitadel/action/v2beta/target_pb';
import {
CreateTargetRequestSchema,
UpdateTargetRequestSchema,
} from '@zitadel/proto/zitadel/action/v2beta/action_service_pb';
type TargetTypes = ActionTwoAddTargetDialogComponent['targetTypes'][number];
@Component({
selector: 'cnsl-actions-two-add-target-dialog',
templateUrl: './actions-two-add-target-dialog.component.html',
styleUrls: ['./actions-two-add-target-dialog.component.scss'],
standalone: true,
imports: [
CommonModule,
MatButtonModule,
MatDialogModule,
ReactiveFormsModule,
TranslateModule,
InputModule,
MatCheckboxModule,
MatSelectModule,
],
})
export class ActionTwoAddTargetDialogComponent {
protected readonly targetTypes = ['restCall', 'restWebhook', 'restAsync'] as const;
protected readonly targetForm: ReturnType<typeof this.buildTargetForm>;
constructor(
private fb: FormBuilder,
public dialogRef: MatDialogRef<
ActionTwoAddTargetDialogComponent,
MessageInitShape<typeof CreateTargetRequestSchema | typeof UpdateTargetRequestSchema>
>,
@Inject(MAT_DIALOG_DATA) private readonly data: { target?: Target },
) {
this.targetForm = this.buildTargetForm();
if (!data?.target) {
return;
}
this.targetForm.patchValue({
name: data.target.name,
endpoint: data.target.endpoint,
timeout: Number(data.target.timeout?.seconds),
type: this.data.target?.targetType?.case ?? 'restWebhook',
interruptOnError:
data.target.targetType.case === 'restWebhook' || data.target.targetType.case === 'restCall'
? data.target.targetType.value.interruptOnError
: false,
});
}
public buildTargetForm() {
return this.fb.group({
name: new FormControl<string>('', { nonNullable: true, validators: [requiredValidator] }),
type: new FormControl<TargetTypes>('restWebhook', {
nonNullable: true,
validators: [requiredValidator],
}),
endpoint: new FormControl<string>('', { nonNullable: true, validators: [requiredValidator] }),
timeout: new FormControl<number>(10, { nonNullable: true, validators: [requiredValidator] }),
interruptOnError: new FormControl<boolean>(false, { nonNullable: true }),
});
}
public closeWithResult() {
if (this.targetForm.invalid) {
return;
}
const { type, name, endpoint, timeout, interruptOnError } = this.targetForm.getRawValue();
const timeoutDuration: MessageInitShape<typeof DurationSchema> = {
seconds: BigInt(timeout),
nanos: 0,
};
const targetType: Extract<MessageInitShape<typeof CreateTargetRequestSchema>['targetType'], { case: TargetTypes }> =
type === 'restWebhook'
? { case: type, value: { interruptOnError } }
: type === 'restCall'
? { case: type, value: { interruptOnError } }
: { case: 'restAsync', value: {} };
const baseReq = {
name,
endpoint,
timeout: timeoutDuration,
targetType,
};
this.dialogRef.close(
this.data.target
? {
...baseReq,
id: this.data.target.id,
}
: baseReq,
);
}
}