Skip to content

Commit

Permalink
[FIX] web: kanban: keep column folded when d&d a record
Browse files Browse the repository at this point in the history
In a grouped kanban view, drag a record and drop it in a folded
column. Before this commit, it opened and loaded the target column.
It shouldn't, the column should remain folded. This behavior has
been introduced in v16 with the wowl views.

This commit restores the legacy kanban behavior, which keeps the
target column folded and thus doesn't load it. We ensure that
the progressbar of the source column is correctly updated though.

Task 3208098

closes odoo#115628

Signed-off-by: Géry Debongnie <ged@odoo.com>
  • Loading branch information
aab-odoo committed Mar 17, 2023
1 parent 68e3e2b commit d6d6e4f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 39 deletions.
20 changes: 8 additions & 12 deletions addons/web/static/src/views/kanban/kanban_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ export class KanbanDynamicGroupList extends DynamicGroupList {
}

// Move from one group to another
const fullyLoadGroup = targetGroup.isFolded;
if (dataGroupId !== targetGroupId) {
const refIndex = targetGroup.list.records.findIndex((r) => r.id === refId);
// Quick update: moves the record at the right position and notifies components
Expand All @@ -510,24 +509,21 @@ export class KanbanDynamicGroupList extends DynamicGroupList {
throw err;
}

const promises = [this.updateGroupProgressData([sourceGroup, targetGroup], true)];
if (fullyLoadGroup) {
// The group is folded: we need to load it
// In this case since we load after saving the record there is no
// need to reload the record nor to resequence the list.
promises.push(targetGroup.toggle());
} else {
// Record can be loaded along with the group metadata
const promises = [];
const groupsToReload = [sourceGroup];
if (!targetGroup.isFolded) {
groupsToReload.push(targetGroup);
promises.push(record.load());
}

promises.push(this.updateGroupProgressData(groupsToReload, true));
await Promise.all(promises);
}

if (!fullyLoadGroup) {
// Only trigger resequence if the group hasn't been fully loaded
if (!targetGroup.isFolded) {
// Only trigger resequence if the group isn't folded
await targetGroup.list.resequence(dataRecordId, refId);
}
this.model.notify();

this.model.transaction.commit(dataRecordId);

Expand Down
80 changes: 53 additions & 27 deletions addons/web/static/tests/views/kanban_view_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -12216,8 +12216,7 @@ QUnit.module("Views", (hooks) => {
);
});

QUnit.test("fold a column and drag record on it should unfold it", async (assert) => {
let searchReadProm;
QUnit.test("fold a column and drag record on it should not unfold it", async (assert) => {
await makeView({
type: "kanban",
resModel: "partner",
Expand All @@ -12231,11 +12230,6 @@ QUnit.module("Views", (hooks) => {
</templates>
</kanban>`,
groupBy: ["product_id"],
async mockRPC(_route, { method }) {
if (method === "web_search_read") {
await searchReadProm;
}
},
});

assert.containsN(target, ".o_kanban_group", 2);
Expand All @@ -12249,24 +12243,14 @@ QUnit.module("Views", (hooks) => {
assert.hasClass(getColumn(1), "o_column_folded");
assert.strictEqual(getColumn(1).innerText, "xmo (2)");

searchReadProm = makeDeferred();

await dragAndDrop(".o_kanban_group:first-child .o_kanban_record", ".o_column_folded");

assert.containsN(getColumn(0), ".o_kanban_record", 1);
assert.hasClass(getColumn(1), "o_column_folded");
assert.strictEqual(getColumn(1).innerText, "xmo (3)");

searchReadProm.resolve();
await nextTick();

assert.containsN(getColumn(0), ".o_kanban_record", 1);
assert.doesNotHaveClass(getColumn(1), "o_column_folded");
assert.containsN(getColumn(1), ".o_kanban_record", 3);
});

QUnit.test("drag record on initially folded column should load it", async (assert) => {
let searchReadProm;
QUnit.test("drag record on initially folded column should not unfold it", async (assert) => {
await makeView({
type: "kanban",
resModel: "partner",
Expand All @@ -12285,8 +12269,6 @@ QUnit.module("Views", (hooks) => {
const result = await performRPC(route, args);
result.groups[1].__fold = true;
return result;
} else if (args.method === "web_search_read") {
await searchReadProm;
}
},
});
Expand All @@ -12295,20 +12277,64 @@ QUnit.module("Views", (hooks) => {
assert.hasClass(getColumn(1), "o_column_folded");
assert.strictEqual(getColumn(1).innerText, "xmo (2)");

searchReadProm = makeDeferred();

await dragAndDrop(".o_kanban_group:first-child .o_kanban_record", ".o_column_folded");

assert.containsN(getColumn(0), ".o_kanban_record", 1);
assert.hasClass(getColumn(1), "o_column_folded");
assert.strictEqual(getColumn(1).innerText, "xmo (3)");
});

searchReadProm.resolve();
await nextTick();
QUnit.test("drag record to folded column, with progressbars", async (assert) => {
serverData.models.partner.records[0].bar = false;
await makeView({
type: "kanban",
resModel: "partner",
serverData,
arch: /* xml */ `
<kanban>
<progressbar field="foo" colors='{"yop": "success", "gnap": "warning", "blip": "danger"}' sum_field="int_field" />
<templates>
<div t-name="kanban-box">
<field name="id" />
</div>
</templates>
</kanban>
`,
groupBy: ["bar"],
});

assert.containsN(getColumn(0), ".o_kanban_record", 1);
assert.doesNotHaveClass(getColumn(1), "o_column_folded");
assert.containsN(getColumn(1), ".o_kanban_record", 3);
assert.containsN(target, ".o_kanban_group", 2);
assert.containsN(target, ".o_kanban_group:first-child .o_kanban_record", 2);
assert.containsN(target, ".o_kanban_group:nth-child(2) .o_kanban_record", 2);
assert.deepEqual(
getProgressBars(0).map((pb) => pb.style.width),
["50%", "50%"]
);
assert.deepEqual(
getProgressBars(1).map((pb) => pb.style.width),
["50%", "50%"]
);
assert.deepEqual(getCounters(), ["6", "26"]);

const clickColumnAction = await toggleColumnActions(1);
await clickColumnAction("Fold");

assert.containsN(getColumn(0), ".o_kanban_record", 2);
assert.hasClass(getColumn(1), "o_column_folded");
assert.strictEqual(getColumn(1).innerText, "Yes (2)");

await dragAndDrop(
".o_kanban_group:first-child .o_kanban_record",
".o_kanban_group:nth-child(2)"
);

assert.containsOnce(getColumn(0), ".o_kanban_record");
assert.strictEqual(getColumn(1).innerText, "Yes (3)");
assert.deepEqual(
getProgressBars(0).map((pb) => pb.style.width),
["100%"]
);
assert.deepEqual(getCounters(), ["-4"]);
});

QUnit.test("quick create record in grouped kanban in a form view dialog", async (assert) => {
Expand Down

0 comments on commit d6d6e4f

Please sign in to comment.