[FIX] documents: handle multiple clicks on record in selectCreateDialog

Steps to reproduce:
- Go to Documents activity view.
- Click on Schedule activity.
- Perform multiple clicks on any record.

Issue:
The 'Schedule Activity' wizard opened as many times as the record was clicked.
As a result, even after successfully scheduling an activity on that record,
the user still faced multiple open wizards remaining and had to manually close
each one of them.

Fix:
This commit introduces a method `executeOnceAndClose` which makes use of a
flag 'busy' to ensure that the `onSelected` function is called only once and
hence exactly one `Schedule Activity` wizard is opened, despite clicking a record
more than once.

closes odoo/odoo#154442

Task: 3721404
X-original-commit: 19cc5ea3cf2c8fcf742ba5ab9b4b82305d81d555
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Khushi
2024-02-20 07:52:05 +00:00
parent a7f9eb3127
commit 097c7bc91d
2 changed files with 37 additions and 4 deletions
@@ -19,6 +19,7 @@ export class SelectCreateDialog extends Component {
// ℹ️ `_t` can only be inlined directly inside JS template literals
// after Babel has been updated to version 2.12.
const translatedText = _t("No records found!");
this.busy = false; // flag used to ensure we only call once the onSelected/onUnselect props
this.baseViewProps = {
display: { searchPanel: false },
editable: false, // readonly
@@ -52,17 +53,28 @@ export class SelectCreateDialog extends Component {
return props;
}
async executeOnceAndClose(callback) {
if (!this.busy) {
this.busy = true;
try {
await callback();
} catch (e) {
this.busy = false;
throw e;
}
this.props.close();
}
}
async select(resIds) {
if (this.props.onSelected) {
await this.props.onSelected(resIds);
this.props.close();
this.executeOnceAndClose(() => this.props.onSelected(resIds));
}
}
async unselect() {
if (this.props.onUnselect) {
await this.props.onUnselect();
this.props.close();
this.executeOnceAndClose(() => this.props.onUnselect());
}
}
@@ -480,6 +480,27 @@ QUnit.module("ViewDialogs", (hooks) => {
}
);
QUnit.test("SelectCreateDialog: multiple clicks on record", async function (assert) {
serverData.views = {
"partner,false,list": `<tree><field name="display_name"/></tree>`,
"partner,false,search": `<search><field name="foo"/></search>`,
};
const webClient = await createWebClient({ serverData });
webClient.env.services.dialog.add(SelectCreateDialog, {
resModel: "partner",
onSelected: async function (records) {
assert.step(`select record ${records[0]}`);
},
});
await nextTick();
click(target.querySelector(".modal .o_data_row .o_data_cell"));
click(target.querySelector(".modal .o_data_row .o_data_cell"));
click(target.querySelector(".modal .o_data_row .o_data_cell"));
await nextTick();
assert.verifySteps(["select record 1"], "should have called onSelected only once");
});
QUnit.test("SelectCreateDialog: default props, create a record", async function (assert) {
serverData.views = {
"partner,false,list": `<tree><field name="display_name"/></tree>`,