[FIX] web: ListView: do not show handle column if grouped

The HandleField widget should not be displayed in grouped list
view, probably because we do not support the resequence feature
in this situation. This is the legacy spec.

In the wowl ListView, we didn't implement this restriction. As
a consequence, some list views (e.g. DebugMenu > Open View) didn't
render correctly when grouped, because the presence of the handle
field (which is aggregatable) didn't leave any space to display
the group titles.

closes odoo/odoo#100356

Signed-off-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
Aaron Bohy
2022-09-17 00:51:29 +02:00
parent 31c975ae94
commit c31a159b4e
2 changed files with 21 additions and 18 deletions
@@ -66,9 +66,7 @@ export class ListRenderer extends Component {
this.cellClassByColumn = {};
this.groupByButtons = this.props.archInfo.groupBy.buttons;
this.state = useState({
columns: this.allColumns.filter(
(col) => !col.optional || this.optionalActiveFields[col.name]
),
columns: this.getActiveColumns(this.props.list),
});
this.withHandleColumn = this.state.columns.some((col) => col.widget === "handle");
useExternalListener(document, "click", this.onGlobalClick.bind(this));
@@ -92,9 +90,7 @@ export class ListRenderer extends Component {
});
onWillUpdateProps((nextProps) => {
this.allColumns = nextProps.archInfo.columns;
this.state.columns = this.allColumns.filter(
(col) => !col.optional || this.optionalActiveFields[col.name]
);
this.state.columns = this.getActiveColumns(nextProps.list);
});
onPatched(() => {
const editedRecord = this.props.list.editedRecord;
@@ -189,6 +185,15 @@ export class ListRenderer extends Component {
});
}
getActiveColumns(list) {
return this.allColumns.filter((col) => {
if (list.isGrouped && col.widget === "handle") {
return false; // no handle column if the list is grouped
}
return !col.optional || this.optionalActiveFields[col.name];
});
}
get hasSelectors() {
return this.props.allowSelectors && !this.env.isSmall;
}
@@ -1560,9 +1565,7 @@ export class ListRenderer extends Component {
async toggleOptionalField(fieldName) {
await this.props.list.unselectRecord(true);
this.optionalActiveFields[fieldName] = !this.optionalActiveFields[fieldName];
this.state.columns = this.allColumns.filter(
(col) => !col.optional || this.optionalActiveFields[col.name]
);
this.state.columns = this.getActiveColumns(this.props.list);
this.saveOptionalActiveFields(
this.allColumns.filter((col) => this.optionalActiveFields[col.name] && col.optional)
);
@@ -1233,15 +1233,15 @@ QUnit.module("Views", (hooks) => {
groupBy: ["bar"],
});
assert.strictEqual($(target).find("th:contains(Foo)").length, 1, "should contain Foo");
assert.strictEqual($(target).find("th:contains(Bar)").length, 1, "should contain Bar");
assert.containsN(target, "tr.o_group_header", 2, "should have 2 .o_group_header");
assert.containsN(target, "th.o_group_name", 2, "should have 2 .o_group_name");
assert.containsNone(
target,
"th:contains(int_field)",
"Should not have int_field in grouped list"
);
assert.containsN(target, "thead th", 3); // record selector + Foo + Bar
assert.containsOnce(target, "thead th.o_list_record_selector");
assert.containsOnce(target, "thead th[data-name=foo]");
assert.containsOnce(target, "thead th[data-name=bar]");
assert.containsNone(target, "thead th[data-name=int_field]");
assert.containsN(target, "tr.o_group_header", 2);
assert.containsN(target, "th.o_group_name", 2);
assert.containsN(target.querySelector(".o_group_header"), "th", 2); // group name + colspan 2
assert.containsNone(target.querySelector(".o_group_header"), ".o_list_number");
});
QUnit.test("basic grouped list rendering 1 col without selector", async function (assert) {