Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/60719 disable wp comment submitter while the form request is in progress #17696

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flex_layout(my: 2, data: { test_selector: "op-work-package-journal-form" }) do |new_form_container|
new_form_container.with_row(
display: button_row_display_value,
data: {
data: {
"work-packages--activities-tab--index-target": "buttonRow"
}) do
flex_layout(justify_content: :space_between) do |button_row|
Expand Down Expand Up @@ -39,10 +39,10 @@
id: "work-package-journal-form-element", # required for specs
model: journal,
method: :post,
data: {
turbo: true,
turbo_stream: true,
"work-packages--activities-tab--index-target": "form",
data: {
turbo: true,
turbo_stream: true,
"work-packages--activities-tab--index-target": "form",
action: "submit->work-packages--activities-tab--index#onSubmit",
"test_selector": "op-work-package-journal-form-element"
},
Expand All @@ -61,7 +61,10 @@
icon: :"paper-airplane",
"aria-label": t("activities.work_packages.activity_tab.label_submit_comment"),
type: :submit,
data: { "test_selector": "op-submit-work-package-journal-form" }
data: {
"test_selector": "op-submit-work-package-journal-form",
"work-packages--activities-tab--index-target": "formSubmitButton"
}
))
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ export default class IndexController extends Controller {
showConflictFlashMessageUrl: String,
};

static targets = ['journalsContainer', 'buttonRow', 'formRow', 'form', 'reactionButton'];
static targets = ['journalsContainer', 'buttonRow', 'formRow', 'form', 'formSubmitButton', 'reactionButton'];

declare readonly journalsContainerTarget:HTMLElement;
declare readonly buttonRowTarget:HTMLInputElement;
declare readonly formRowTarget:HTMLElement;
declare readonly formTarget:HTMLFormElement;
declare readonly formSubmitButtonTarget:HTMLButtonElement;
declare readonly reactionButtonTargets:HTMLElement[];

declare readonly hasFormSubmitButtonTarget:boolean;

declare updateStreamsUrlValue:string;
declare sortingValue:string;
declare lastServerTimestampValue:string;
Expand Down Expand Up @@ -648,7 +651,7 @@ export default class IndexController extends Controller {
async onSubmit(event:Event | null = null) {
if (this.saveInProgress === true) return;

this.saveInProgress = true;
this.setFormSubmitInProgress(true);

event?.preventDefault();

Expand All @@ -661,10 +664,18 @@ export default class IndexController extends Controller {
console.error('Error saving activity:', error);
})
.finally(() => {
this.saveInProgress = false;
this.setFormSubmitInProgress(false);
});
}

private setFormSubmitInProgress(inProgress:boolean) {
this.saveInProgress = inProgress;

if (this.hasFormSubmitButtonTarget) {
this.formSubmitButtonTarget.disabled = inProgress;
}
}

private prepareFormData():FormData {
const ckEditorInstance = this.getCkEditorInstance();
const data = ckEditorInstance ? ckEditorInstance.getData({ trim: false }) : '';
Expand Down Expand Up @@ -711,7 +722,7 @@ export default class IndexController extends Controller {
this.handleStemVisibility();
}, 10);

this.saveInProgress = false;
this.setFormSubmitInProgress(false);
}

private resetJournalsContainerMargins():void {
Expand Down
Loading