Merge pull request #12184 from AllForNothing/release-2.0.0

[Cherry-pick]Remove test button for webhook
This commit is contained in:
Daniel Jiang 2020-06-09 14:51:24 +08:00 committed by GitHub
commit 6a65b27c19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 37 deletions

View File

@ -90,14 +90,12 @@
</div>
</section>
</form>
<div class="mt-1" *ngIf="!isModify">
<button type="button" id="webhook-test-add" [clrLoading]="checkBtnState" class="btn btn-outline" (click)="onTestEndpoint()" [disabled]="checking || enpointURL.errors">{{'WEBHOOK.TEST_ENDPOINT_BUTTON' | translate}}</button>
<div class="mt-1 bottom-btn" *ngIf="!isModify">
<button type="button" class="btn btn-outline" id="add-webhook-cancel" (click)="onCancel()">{{'BUTTON.CANCEL' | translate}}</button>
<button type="button" id="new-webhook-continue" class="btn btn-primary" [disabled]="!isValid" (click)="add()">{{'BUTTON.ADD' | translate}}</button>
</div>
<div class="mt-1 bottom-btn" *ngIf="isModify">
<button type="button" [clrLoading]="checkBtnState" class="btn btn-outline" id="webhook-test" (click)="onTestEndpoint()" [disabled]="checking || enpointURL.errors">{{'WEBHOOK.TEST_ENDPOINT_BUTTON' | translate}}</button>
<button type="button" class="btn btn-outline" id="edit-webhook-cancel" (click)="onCancel()">{{'BUTTON.CANCEL' | translate}}</button>
<button type="button" class="btn btn-primary" id="edit-webhook-save" [disabled]="!isValid" (click)="save()">{{'BUTTON.SAVE' | translate}}</button>
<button type="button" class="btn btn-primary" id="edit-webhook-save" [disabled]="!isValid || !hasChange()" (click)="save()">{{'BUTTON.SAVE' | translate}}</button>
</div>
</div>
</div>

View File

@ -6,7 +6,6 @@
}
.bottom-btn {
text-align: right;
margin-right: 3.4rem;
}
.width-238 {
width: 238px;
@ -16,4 +15,4 @@
}
.clr-control-label {
width: 9rem !important;
}
}

View File

@ -128,14 +128,6 @@ describe('AddWebhookFormComponent', () => {
const errorEle: HTMLElement = fixture.nativeElement.querySelector("clr-control-error");
expect(errorEle.innerText).toEqual('WEBHOOK.NAME_REQUIRED');
});
it("test button should work", async () => {
const spy: jasmine.Spy = spyOn(component, 'onTestEndpoint').and.returnValue(undefined);
const testButton: HTMLButtonElement = fixture.nativeElement.querySelector("#webhook-test-add");
testButton.dispatchEvent(new Event('click'));
fixture.detectChanges();
await fixture.whenStable();
expect(spy.calls.count()).toEqual(1);
});
it("add button should work", async () => {
const spy: jasmine.Spy = spyOn(component, 'add').and.returnValue(undefined);
component.webhook = mockedWehook;

View File

@ -12,6 +12,7 @@ import { ClrLoadingState } from "@clr/angular";
import { finalize } from "rxjs/operators";
import { WebhookService } from "../webhook.service";
import { InlineAlertComponent } from "../../../shared/inline-alert/inline-alert.component";
import { compareValue } from '../../../../lib/utils/utils';
@Component({
selector: 'add-webhook-form',
@ -20,13 +21,13 @@ import { InlineAlertComponent } from "../../../shared/inline-alert/inline-alert.
})
export class AddWebhookFormComponent implements OnInit {
closable: boolean = true;
staticBackdrop: boolean = true;
checking: boolean = false;
checkBtnState: ClrLoadingState = ClrLoadingState.DEFAULT;
webhookForm: NgForm;
submitting: boolean = false;
@Input() projectId: number;
webhook: Webhook = new Webhook();
originValue: Webhook;
isModify: boolean;
@Input() isOpen: boolean;
@Output() close = new EventEmitter<boolean>();
@ -41,27 +42,6 @@ export class AddWebhookFormComponent implements OnInit {
ngOnInit() {
}
onTestEndpoint() {
this.checkBtnState = ClrLoadingState.LOADING;
this.checking = true;
this.webhookService
.testEndpoint(this.projectId, {
targets: this.webhook.targets
})
.pipe(finalize(() => (this.checking = false)))
.subscribe(
response => {
this.inlineAlert.showInlineSuccess({message: "WEBHOOK.TEST_ENDPOINT_SUCCESS"});
this.checkBtnState = ClrLoadingState.SUCCESS;
},
error => {
this.inlineAlert.showInlineError("WEBHOOK.TEST_ENDPOINT_FAILURE");
this.checkBtnState = ClrLoadingState.DEFAULT;
}
);
}
onCancel() {
this.close.emit(false);
this.currentForm.reset();
@ -111,6 +91,9 @@ export class AddWebhookFormComponent implements OnInit {
this.hasEventType()
);
}
hasChange(): boolean {
return !compareValue(this.originValue, this.webhook);
}
setEventType(eventType) {
if (this.webhook.event_types.indexOf(eventType) === -1) {

View File

@ -206,6 +206,7 @@ export class WebhookComponent implements OnInit {
this.addWebhookComponent.isEdit = true;
this.addWebhookComponent.addWebhookFormComponent.isModify = true;
this.addWebhookComponent.addWebhookFormComponent.webhook = clone(this.selectedRow[0]);
this.addWebhookComponent.addWebhookFormComponent.originValue = clone(this.selectedRow[0]);
this.addWebhookComponent.addWebhookFormComponent.webhook.event_types = clone(this.selectedRow[0].event_types);
}
}