[FIX] web: graph: keep pending filters when toggling a measure
Consider the following scenario on a slow network in a graph view: - add a filter (triggers a reload) - toggle a measure (triggers another reload, before the first one completes) Before this commit, the new searchParams coming from the first reload were lost, even though they were still displayed in the search view. This commit ensures that we keep the last searchParams when reloading the graph view. closes odoo/odoo#76918 X-original-commit: 1719de73099eca0b765237cb47caf44813157b94 Related: odoo/enterprise#21046 Signed-off-by: Géry Debongnie (ged) <ged@openerp.com> Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -97,6 +97,7 @@ export class GraphModel extends Model {
|
||||
|
||||
this.metaData = params;
|
||||
this.data = null;
|
||||
this.searchParams = null;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -107,31 +108,11 @@ export class GraphModel extends Model {
|
||||
* @param {SearchParams} searchParams
|
||||
*/
|
||||
async load(searchParams) {
|
||||
const { comparison, domain, context, groupBy } = searchParams;
|
||||
const metaData = Object.assign({}, this.metaData, { context });
|
||||
if (comparison) {
|
||||
metaData.domains = comparison.domains;
|
||||
metaData.comparisonField = comparison.fieldName;
|
||||
} else {
|
||||
metaData.domains = [{ arrayRepr: domain, description: null }];
|
||||
}
|
||||
metaData.measure = context.graph_measure || metaData.measure;
|
||||
metaData.mode = context.graph_mode || metaData.mode;
|
||||
|
||||
this.searchParams = searchParams;
|
||||
if (!this.initialGroupBy) {
|
||||
this.initialGroupBy = context.graph_groupbys || this.metaData.groupBy; // = arch groupBy --> change that
|
||||
this.initialGroupBy = searchParams.context.graph_groupbys || this.metaData.groupBy; // = arch groupBy --> change that
|
||||
}
|
||||
metaData.groupBy = groupBy.length ? groupBy : this.initialGroupBy;
|
||||
|
||||
this._normalize(metaData);
|
||||
|
||||
metaData.measures = computeReportMeasures(
|
||||
metaData.fields,
|
||||
metaData.fieldAttrs,
|
||||
[metaData.measure],
|
||||
metaData.additionalMeasures
|
||||
);
|
||||
|
||||
const metaData = this._buildMetaData();
|
||||
return this._fetchDataPoints(metaData);
|
||||
}
|
||||
|
||||
@@ -149,7 +130,8 @@ export class GraphModel extends Model {
|
||||
*/
|
||||
async updateMetaData(params) {
|
||||
if ("measure" in params) {
|
||||
await this._fetchDataPoints(Object.assign({}, this.metaData, params));
|
||||
const metaData = this._buildMetaData(params);
|
||||
await this._fetchDataPoints(metaData);
|
||||
} else {
|
||||
await this.race.getCurrentProm();
|
||||
this.metaData = Object.assign({}, this.metaData, params);
|
||||
@@ -162,6 +144,37 @@ export class GraphModel extends Model {
|
||||
// Protected
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @param {Object} [params={}]
|
||||
* @returns {Object}
|
||||
*/
|
||||
_buildMetaData(params) {
|
||||
const { comparison, domain, context, groupBy } = this.searchParams;
|
||||
|
||||
const metaData = Object.assign({}, this.metaData, { context });
|
||||
if (comparison) {
|
||||
metaData.domains = comparison.domains;
|
||||
metaData.comparisonField = comparison.fieldName;
|
||||
} else {
|
||||
metaData.domains = [{ arrayRepr: domain, description: null }];
|
||||
}
|
||||
metaData.measure = context.graph_measure || metaData.measure;
|
||||
metaData.mode = context.graph_mode || metaData.mode;
|
||||
metaData.groupBy = groupBy.length ? groupBy : this.initialGroupBy;
|
||||
|
||||
this._normalize(metaData);
|
||||
|
||||
metaData.measures = computeReportMeasures(
|
||||
metaData.fields,
|
||||
metaData.fieldAttrs,
|
||||
[metaData.measure],
|
||||
metaData.additionalMeasures
|
||||
);
|
||||
|
||||
return Object.assign(metaData, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the data points determined by the metaData. This function has
|
||||
* several side effects. It can alter this.metaData and set this.dataPoints.
|
||||
|
||||
@@ -3326,7 +3326,7 @@ QUnit.module("Views", (hooks) => {
|
||||
</graph>`,
|
||||
searchViewArch: `
|
||||
<search>
|
||||
<filter name="my_filter" string="My Filter" domain="[('id', '<', 2)]"/>
|
||||
<filter name="my_filter" string="My Filter" domain="[('id', '<', 6)]"/>
|
||||
</search>`,
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "web_read_group") {
|
||||
@@ -3363,7 +3363,7 @@ QUnit.module("Views", (hooks) => {
|
||||
await nextTick();
|
||||
|
||||
checkDatasets(assert, graph, ["data", "label"], {
|
||||
data: [82, 157],
|
||||
data: [82, 4],
|
||||
label: "Foo",
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user