From 7df8cf0496b6f35c1fc403a8b0c884ca47e89c1c Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Mon, 14 Mar 2022 18:56:09 +0100 Subject: [PATCH] [IMP] project: refactor to easily create right side panel components Before this commit, the components created and used in the right side panel are components for the `project.milestone` and we cannot reused some components for another context. This commit refactors a little bit to create a parent component with the common code useful for another components than `project.milestone` ones. task-2710808 --- .../src/js/right_panel/project_utils.js | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/addons/project/static/src/js/right_panel/project_utils.js b/addons/project/static/src/js/right_panel/project_utils.js index 3bf3b2d801a..aefbd3dda7e 100644 --- a/addons/project/static/src/js/right_panel/project_utils.js +++ b/addons/project/static/src/js/right_panel/project_utils.js @@ -7,7 +7,26 @@ import { useService } from "@web/core/utils/hooks"; const { Component, onWillUpdateProps, useState } = owl; -class MilestoneComponent extends Component { +export class ProjectRightSidePanelComponent extends Component { + setup() { + super.setup(); + this.contextValue = {}; + } + + async openLegacyFormDialog(params) { + const adapterParent = standaloneAdapter({ Component }); + const dialog = new FormViewDialog(adapterParent, { + context: this.contextValue, + res_id: false, + ...params, + }); + await dialog.open(); + return dialog; + } +} +ProjectRightSidePanelComponent.components = { ComponentAdapter }; + +class MilestoneComponent extends ProjectRightSidePanelComponent { setup() { super.setup(); this.contextValue = Object.assign({}, { @@ -15,30 +34,14 @@ class MilestoneComponent extends Component { }, this.props.context); } - get context() { - return this.contextValue; - } - - set context(value) { - this.contextValue = Object.assign({}, { - 'default_project_id': value.active_id, - }, value); - } - async openLegacyFormDialog(params) { - const adapterParent = standaloneAdapter({ Component }); - const dialog = new FormViewDialog(adapterParent, { - context: this.context, + return super.openLegacyFormDialog({ res_model: "project.milestone", - res_id: false, on_saved: this.props.onMilestoneUpdate, ...params, }); - await dialog.open(); - return dialog; } } -MilestoneComponent.components = { ComponentAdapter }; export class AddMilestone extends MilestoneComponent { onAddMilestoneClick(event) {