[FIX] web: add hideCustomGroupBy option
Prior to this commit, it was not possible to hide the 'Add Custom Group'. This commit adds this feature and associated tests. Hiding this menu entry can now be performed by adding `hideCustomGroupBy: false` in the `View`. This commit also uses `MAPPING` values in the components assignment of `ControlPanel` in order to improve code maintenance. task-2845729
This commit is contained in:
@@ -95,10 +95,7 @@ export class ControlPanel extends Component {
|
||||
}
|
||||
|
||||
ControlPanel.components = {
|
||||
ComparisonMenu,
|
||||
FavoriteMenu,
|
||||
FilterMenu,
|
||||
GroupByMenu,
|
||||
...Object.values(MAPPING),
|
||||
Pager,
|
||||
SearchBar,
|
||||
};
|
||||
|
||||
@@ -26,6 +26,13 @@ export class GroupByMenu extends Component {
|
||||
useBus(this.env.searchModel, "update", this.render);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get hideCustomGroupBy() {
|
||||
return this.env.searchModel.hideCustomGroupBy || false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Object[]}
|
||||
*/
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
</t>
|
||||
<t t-set="currentGroup" t-value="item.groupNumber"/>
|
||||
</t>
|
||||
<t t-if="fields.length">
|
||||
<t t-if="!hideCustomGroupBy and fields.length">
|
||||
<div t-if="items.length" role="separator" class="dropdown-divider"/>
|
||||
<CustomGroupByItem fields="fields" onAddCustomGroup.bind="onAddCustomGroup"/>
|
||||
</t>
|
||||
|
||||
@@ -212,13 +212,14 @@ export class SearchModel extends EventBus {
|
||||
// used to avoid useless recomputations
|
||||
this._reset();
|
||||
|
||||
const { comparison, context, domain, groupBy, orderBy } = config;
|
||||
const { comparison, context, domain, groupBy, hideCustomGroupBy, orderBy } = config;
|
||||
|
||||
this.globalComparison = comparison;
|
||||
this.globalContext = toRaw(context || {});
|
||||
this.globalDomain = domain || [];
|
||||
this.globalGroupBy = groupBy || [];
|
||||
this.globalOrderBy = orderBy || [];
|
||||
this.hideCustomGroupBy = hideCustomGroupBy;
|
||||
|
||||
this.searchMenuTypes = new Set(config.searchMenuTypes || ["filter", "groupBy", "favorite"]);
|
||||
|
||||
|
||||
@@ -86,5 +86,6 @@ WithSearch.props = {
|
||||
// extra options
|
||||
activateFavorite: { type: Boolean, optional: true },
|
||||
dynamicFilters: { type: Array, element: Object, optional: true },
|
||||
hideCustomGroupBy: { type: Boolean, optional: true },
|
||||
searchMenuTypes: { type: Array, element: String, optional: true },
|
||||
};
|
||||
|
||||
@@ -85,6 +85,7 @@ export function getDefaultConfig() {
|
||||
*
|
||||
* @property {boolean} [activateFavorite]
|
||||
* @property {Object[]} [dynamicFilters]
|
||||
* @property {boolean} [hideCustomGroupBy]
|
||||
* @property {string[]} [searchMenuTypes]
|
||||
* @property {Object} [globalState]
|
||||
*/
|
||||
@@ -123,6 +124,7 @@ const STANDARD_PROPS = [
|
||||
|
||||
"activateFavorite",
|
||||
"dynamicFilters",
|
||||
"hideCustomGroupBy",
|
||||
"searchMenuTypes",
|
||||
|
||||
// LEGACY: remove this later (clean when mappings old state <-> new state are established)
|
||||
@@ -321,6 +323,7 @@ export class View extends Component {
|
||||
this.componentProps = finalProps;
|
||||
this.withSearchProps = {
|
||||
...toRaw(props),
|
||||
hideCustomGroupBy: props.hideCustomGroupBy || descr.hideCustomGroupBy,
|
||||
searchMenuTypes,
|
||||
SearchModel: descr.SearchModel,
|
||||
};
|
||||
|
||||
@@ -457,4 +457,69 @@ QUnit.module("Search", (hooks) => {
|
||||
assert.deepEqual(controlPanel.env.searchModel.groupBy, []);
|
||||
assert.deepEqual(getFacetTexts(target), []);
|
||||
});
|
||||
|
||||
QUnit.test("Custom group by menu is displayed when hideCustomGroupBy is not set", async function (assert) {
|
||||
|
||||
await makeWithSearch({
|
||||
serverData,
|
||||
resModel: "foo",
|
||||
Component: ControlPanel,
|
||||
searchViewId: false,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<filter string="Birthday" name="birthday" context="{'group_by': 'birthday'}"/>
|
||||
<filter string="Date" name="date" context="{'group_by': 'foo'}"/>
|
||||
</search>
|
||||
`,
|
||||
searchMenuTypes: ["groupBy"],
|
||||
});
|
||||
|
||||
await toggleGroupByMenu(target);
|
||||
|
||||
assert.containsOnce(target, ".o_add_custom_group_menu");
|
||||
});
|
||||
|
||||
QUnit.test("Custom group by menu is displayed when hideCustomGroupBy is false", async function (assert) {
|
||||
|
||||
await makeWithSearch({
|
||||
serverData,
|
||||
resModel: "foo",
|
||||
Component: ControlPanel,
|
||||
searchViewId: false,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<filter string="Birthday" name="birthday" context="{'group_by': 'birthday'}"/>
|
||||
<filter string="Date" name="date" context="{'group_by': 'foo'}"/>
|
||||
</search>
|
||||
`,
|
||||
hideCustomGroupBy: false,
|
||||
searchMenuTypes: ["groupBy"],
|
||||
});
|
||||
|
||||
await toggleGroupByMenu(target);
|
||||
|
||||
assert.containsOnce(target, ".o_add_custom_group_menu");
|
||||
});
|
||||
|
||||
QUnit.test("Custom group by menu is displayed when hideCustomGroupBy is true", async function (assert) {
|
||||
|
||||
await makeWithSearch({
|
||||
serverData,
|
||||
resModel: "foo",
|
||||
Component: ControlPanel,
|
||||
searchViewId: false,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<filter string="Birthday" name="birthday" context="{'group_by': 'birthday'}"/>
|
||||
<filter string="Date" name="date" context="{'group_by': 'foo'}"/>
|
||||
</search>
|
||||
`,
|
||||
hideCustomGroupBy: true,
|
||||
searchMenuTypes: ["groupBy"],
|
||||
});
|
||||
|
||||
await toggleGroupByMenu(target);
|
||||
|
||||
assert.containsNone(target, ".o_add_custom_group_menu");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user