Skip to content

Commit

Permalink
Cancel the editField correctly when canceling the dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
HDinger committed Dec 16, 2024
1 parent f7d3b70 commit b7cba78
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%=
content_tag("turbo-frame", id: "wp-datepicker-dialog--content") do
component_wrapper do
component_wrapper(data: { "application-target": "dynamic",
controller: "work-packages--date-picker--preview" }) do
component_collection do |collection|
if show_banner?
collection.with_component(WorkPackages::DatePicker::BannerComponent.new(work_package:, manually_scheduled:))
Expand All @@ -12,9 +13,7 @@
url: work_package_datepicker_dialog_content_path,
method: :put,
id: DIALOG_FORM_ID,
data: { "application-target": "dynamic",
"work-packages--date-picker--preview-target": "form",
controller: "work-packages--date-picker--preview" },
data: { "work-packages--date-picker--preview-target": "form" },
html: { autocomplete: "off" },
) do |f|
flex_layout do |body|
Expand Down Expand Up @@ -90,7 +89,7 @@

collection.with_component(Primer::Alpha::Dialog::Footer.new) do
component_collection do |footer|
footer.with_component(Primer::ButtonComponent.new) do
footer.with_component(Primer::ButtonComponent.new(data: { action: "work-packages--date-picker--preview#cancel" })) do
I18n.t("button_cancel")
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
[change]="change"
[resource]="resource"
(successfulCreate)="handleSuccessfulCreate($event)"

Check warning

Code scanning / CodeQL

Duplicate HTML element attributes Warning

This attribute
is duplicated later
.
(successfulUpdate)="handleSuccessfulUpdate()"
(successfulCreate)="handleSuccessfulCreate($event)"
(cancel)="onModalClosed()"
id="wp-datepicker-dialog--content">
<op-content-loader viewBox="0 0 100 100">
<svg:rect x="5" y="5" width="70" height="5" rx="1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
[resource]="resource"
(successfulCreate)="handleSuccessfulCreate($event)"
(successfulUpdate)="handleSuccessfulUpdate()"
(cancel)="cancel()"
>
<op-content-loader
viewBox="0 0 180 80"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class ModalWithTurboContentDirective implements AfterViewInit, OnDestroy

@Output() successfulCreate= new EventEmitter<unknown>();
@Output() successfulUpdate= new EventEmitter();
@Output() cancel= new EventEmitter();

constructor(
readonly elementRef:ElementRef,
Expand All @@ -70,13 +71,20 @@ export class ModalWithTurboContentDirective implements AfterViewInit, OnDestroy
.elementRef
.nativeElement
.addEventListener('turbo:submit-end', this.contextBasedListener.bind(this));

Check failure on line 73 in frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts#L70-L73 <@typescript-eslint/no-unsafe-call>(https://typescript-eslint.io/rules/no-unsafe-call)

Unsafe call of an `any` typed value.
Raw output
{"ruleId":"@typescript-eslint/no-unsafe-call","severity":2,"message":"Unsafe call of an `any` typed value.","line":70,"column":5,"nodeType":"MemberExpression","messageId":"unsafeCall","endLine":73,"endColumn":24}

Check failure on line 73 in frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts#L73 <@typescript-eslint/no-unsafe-member-access>(https://typescript-eslint.io/rules/no-unsafe-member-access)

Unsafe member access .addEventListener on an `any` value.
Raw output
{"ruleId":"@typescript-eslint/no-unsafe-member-access","severity":2,"message":"Unsafe member access .addEventListener on an `any` value.","line":73,"column":8,"nodeType":"Identifier","messageId":"unsafeMemberExpression","endLine":73,"endColumn":24}

document
.addEventListener('cancelModalWithTurboContent', this.cancelListener.bind(this));
}

ngOnDestroy() {
this
.elementRef
.nativeElement
.removeEventListener('turbo:submit-end', this.contextBasedListener.bind(this));

Check failure on line 83 in frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts#L80-L83 <@typescript-eslint/no-unsafe-call>(https://typescript-eslint.io/rules/no-unsafe-call)

Unsafe call of an `any` typed value.
Raw output
{"ruleId":"@typescript-eslint/no-unsafe-call","severity":2,"message":"Unsafe call of an `any` typed value.","line":80,"column":5,"nodeType":"MemberExpression","messageId":"unsafeCall","endLine":83,"endColumn":27}

Check failure on line 83 in frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts#L83 <@typescript-eslint/no-unsafe-member-access>(https://typescript-eslint.io/rules/no-unsafe-member-access)

Unsafe member access .removeEventListener on an `any` value.
Raw output
{"ruleId":"@typescript-eslint/no-unsafe-member-access","severity":2,"message":"Unsafe member access .removeEventListener on an `any` value.","line":83,"column":8,"nodeType":"Identifier","messageId":"unsafeMemberExpression","endLine":83,"endColumn":27}


document

Check failure on line 86 in frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts

View workflow job for this annotation

GitHub Actions / eslint

[eslint] frontend/src/app/shared/components/fields/edit/modal-with-turbo-content/modal-with-turbo-content.directive.ts#L85-L86 <no-multiple-empty-lines>(https://eslint.org/docs/latest/rules/no-multiple-empty-lines)

More than 1 blank line not allowed.
Raw output
{"ruleId":"no-multiple-empty-lines","severity":2,"message":"More than 1 blank line not allowed.","line":85,"column":1,"nodeType":"Program","messageId":"consecutiveBlank","endLine":86,"endColumn":1,"fix":{"range":[2983,2984],"text":""}}
.removeEventListener('cancelModalWithTurboContent', this.cancelListener.bind(this));
}

private contextBasedListener(event:CustomEvent) {
Expand All @@ -88,6 +96,10 @@ export class ModalWithTurboContentDirective implements AfterViewInit, OnDestroy
}
}

private cancelListener():void {
this.cancel.emit();
}

private async propagateSuccessfulCreate(event:CustomEvent) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { fetchResponse } = event.detail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export abstract class DialogPreviewController extends Controller {
}
}

protected cancel():void {
document.dispatchEvent(new CustomEvent('cancelModalWithTurboContent'));
}

markFieldAsTouched(event:{ target:HTMLInputElement }) {
this.targetFieldName = event.target.name.replace(/^work_package\[([^\]]+)\]$/, '$1');
this.markTouched(this.targetFieldName);
Expand Down

0 comments on commit b7cba78

Please sign in to comment.