Skip to content

Commit

Permalink
[FIX] web: add record in list with sample data: no flickering
Browse files Browse the repository at this point in the history
Have an editable list view with sample data (sample="1" and no
record). Before this commit, there was a flickering when the user
clicked on "New" to add a record. Indeed, the list was first
re-rendered without the sample mode (i.e. without the opacity style
and no content helper), but still with the sample records. With
this commit, we wait for the reload to be done before leaving the
sample mode, s.t. when the list is re-rendered, we don't have
sample records anymore.

Part-of: odoo#132802
  • Loading branch information
aab-odoo committed Aug 23, 2023
1 parent 2cfafbb commit ecb4175
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addons/web/static/src/model/relational_model/dynamic_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ export class DynamicList extends DataPoint {
return unlinked;
}

_leaveSampleMode() {
async _leaveSampleMode() {
if (this.model.useSampleModel) {
await this._load(this.offset, this.limit, this.orderBy, this.domain);
this.model.useSampleModel = false;
return this._load(this.offset, this.limit, this.orderBy, this.domain);
}
}

Expand Down
37 changes: 37 additions & 0 deletions addons/web/static/tests/views/list_view_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19407,6 +19407,7 @@ QUnit.module("Views", (hooks) => {
assert.strictEqual(input, document.activeElement);
assert.strictEqual(input.value, "Value 1");
});

QUnit.test("monetary field display for rtl languages", async function (assert) {
patchWithCleanup(localization, {
direction: "rtl",
Expand Down Expand Up @@ -19442,4 +19443,40 @@ QUnit.module("Views", (hooks) => {
"Monetary cells should have ltr direction"
);
});

QUnit.test("add record in editable list view with sample data", async function (assert) {
serverData.models.foo.records = [];
let def;
await makeView({
type: "list",
resModel: "foo",
serverData,
arch: '<tree sample="1" editable="top"><field name="int_field"/></tree>',
noContentHelp: "click to add a record",
mockRPC(route, args) {
if (args.method === "unity_web_search_read") {
return def;
}
},
});

assert.containsOnce(target, ".o_view_sample_data");
assert.containsOnce(target, ".o_view_nocontent");
assert.containsN(target, ".o_data_row", 10);

def = makeDeferred();
await clickAdd();

assert.containsOnce(target, ".o_view_sample_data");
assert.containsOnce(target, ".o_view_nocontent");
assert.containsN(target, ".o_data_row", 10);

def.resolve();
await nextTick();

assert.containsNone(target, ".o_view_sample_data");
assert.containsNone(target, ".o_view_nocontent");
assert.containsOnce(target, ".o_data_row");
assert.containsOnce(target, ".o_data_row.o_selected_row");
});
});

0 comments on commit ecb4175

Please sign in to comment.