[FIX] web: list: determine width according to widget

On a list with no data, the width of each column is determined by
a heuristic. Before this rev., the heuristic was based on the field
type. It now takes the potential widget set in the arch into
account, and fallbacks on the field type.
This commit is contained in:
Aaron Bohy
2019-08-23 06:28:34 +00:00
parent bf3c1d3e0c
commit b2c09b4d3d
2 changed files with 34 additions and 12 deletions
@@ -566,19 +566,21 @@ ListRenderer.include({
// width.
return 1;
}
var widget = this.state.fieldsInfo.list[column.attrs.name].Widget.prototype;
if ('widthFactor' in widget) {
return widget.widthFactor;
}
switch (field.type) {
case 'boolean': return '40px';
case 'date': return '92px';
case 'datetime': return '146px';
case 'float': return '92px';
case 'integer': return '74px';
case 'monetary': return '104px';
default: return 1; // evenly distribute the remaining space
var widgetProto = this.state.fieldsInfo.list[column.attrs.name].Widget.prototype;
if ('widthFactor' in widgetProto) {
return widgetProto.widthFactor;
}
var fixedWidthTypes = {
boolean: '40px',
date: '92px',
datetime: '146px',
float: '92px',
integer: '74px',
monetary: '104px',
};
var widget = this.state.fieldsInfo.list[column.attrs.name].widget;
var type = widget in fixedWidthTypes ? widget : field.type;
return fixedWidthTypes[type] || 1;
},
/**
*
@@ -1497,6 +1497,26 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('column width should depend on the widget', async function (assert) {
assert.expect(1);
this.data.foo.records = []; // the width heuristic only applies when there are no records
var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="top">' +
'<field name="datetime" widget="date"/>' +
'<field name="text"/>' +
'</tree>',
});
assert.strictEqual(list.$('th[data-name="datetime"]')[0].offsetWidth, 92,
"should be the optimal width to display a date, not a datetime");
list.destroy();
});
QUnit.test('row height should not change when switching mode', async function (assert) {
// Warning: this test is css dependant
assert.expect(3);