Skip to content

Commit

Permalink
[IMP] mis_builder: preserve the filters when navigating back from dri…
Browse files Browse the repository at this point in the history
…ll-down

Prior to this commit the state of the searchModel was lost when navigating
back from a drill-down.

This commit uses the globalState in order to store and restore the state
of the searchModlel. The use of a SubEnv allows not having to pass props
up to the widget, which would have required overriding the renderer, the
compiler and field.
  • Loading branch information
IT-Ideas committed Jan 16, 2024
1 parent 46d9440 commit b0692f8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
3 changes: 2 additions & 1 deletion mis_builder/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
"mis_builder/static/src/components/mis_report_widget.esm.js",
"mis_builder/static/src/components/mis_report_widget.xml",
"mis_builder/static/src/components/mis_report_widget.css",
"mis_builder/static/src/views/form/mis_report_form_controller.esm.js",
"mis_builder/static/src/views/form/mis_report_form_view.esm.js",
],
"web.report_assets_common": [
"/mis_builder/static/src/css/report.css",
],
},
"qweb": ["static/src/xml/mis_report_widget.xml"],
"installable": True,
"application": True,
"license": "AGPL-3",
Expand Down
21 changes: 19 additions & 2 deletions mis_builder/static/src/components/mis_report_widget.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {SearchBar} from "@web/search/search_bar/search_bar";
import {SearchModel} from "@web/search/search_model";
import {parseDate} from "@web/core/l10n/dates";
import {registry} from "@web/core/registry";
import {useSetupAction} from "@web/webclient/actions/action_hook";

export class MisReportWidget extends Component {
setup() {
Expand All @@ -33,6 +34,18 @@ export class MisReportWidget extends Component {
this.refresh();
});
onWillStart(this.willStart);
useSetupAction({
getGlobalState: () => {
if (!this.showSearchBar) {
return {};
}
return {
misReportSearchModelState: JSON.stringify(
this.searchModel.exportState()
),
};
},
});
}

// Lifecycle
Expand All @@ -59,10 +72,14 @@ export class MisReportWidget extends Component {
this.widget_show_pivot_date = result.widget_show_pivot_date;
if (this.showSearchBar) {
// Initialize the search model
await this.searchModel.load({
const config = {
resModel: this.source_aml_model_name,
searchViewId: this.widget_search_view_id,
});
};
if (this.env.misReportSearchModelState) {
config.state = JSON.parse(this.env.misReportSearchModelState);
}
await this.searchModel.load(config);
}

// Compute the report
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/** @odoo-module */

import {FormController} from "@web/views/form/form_controller";
import {useSubEnv} from "@odoo/owl";

export class MisReportFormController extends FormController {
setup() {
super.setup();
useSubEnv({
misReportSearchModelState:
this.props.globalState &&
this.props.globalState.misReportSearchModelState,
});
}
}
14 changes: 14 additions & 0 deletions mis_builder/static/src/views/form/mis_report_form_view.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @odoo-module **/

import {MisReportFormController} from "@mis_builder/views/form/mis_report_form_controller.esm";
import {formView} from "@web/views/form/form_view";
import {registry} from "@web/core/registry";

// The view to use when mounting `mis_report_widget` widget in order to preserve the
// filters when returning from the drill-down views.
export const misReportFormView = {
...formView,
Controller: MisReportFormController,
};

registry.category("views").add("mis_report_form_view", misReportFormView);
3 changes: 2 additions & 1 deletion mis_builder/views/mis_report_instance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
edit="false"
create="false"
delete="false"
js_class="mis_report_form_view"
>
<sheet>
<field
name="id"
widget="mis_report_widget"
nolabel="1"
style="width:100%"
class="w-100"
/>
</sheet>
</form>
Expand Down

0 comments on commit b0692f8

Please sign in to comment.