1
1
import { Component , onWillUpdateProps , useState } from "@odoo/owl" ;
2
2
import { getChartMenuActions } from "../../../../actions/figure_menu_actions" ;
3
3
import { BACKGROUND_CHART_COLOR } from "../../../../constants" ;
4
+ import { isDefined } from "../../../../helpers" ;
4
5
import { chartRegistry , chartSubtypeRegistry } from "../../../../registries/chart_types" ;
6
+ import { Store , useStore } from "../../../../store_engine" ;
7
+ import { _t } from "../../../../translation" ;
5
8
import { ChartDefinition , ChartType , FigureUI , SpreadsheetChildEnv } from "../../../../types" ;
9
+ import { FullScreenChartStore } from "../../../full_screen_chart/full_screen_chart_store" ;
6
10
import { Menu , MenuState } from "../../../menu/menu" ;
7
11
8
12
interface Props {
9
13
figureUI : FigureUI ;
10
14
}
11
15
16
+ interface MenuItem {
17
+ id : string ;
18
+ label : string ;
19
+ iconClass : string ;
20
+ onClick : ( ) => void ;
21
+ isSelected ?: boolean ;
22
+ }
23
+
12
24
export class ChartDashboardMenu extends Component < Props , SpreadsheetChildEnv > {
13
25
static template = "spreadsheet.ChartDashboardMenu" ;
14
26
static components = { Menu } ;
15
27
static props = { figureUI : Object } ;
16
28
17
29
private originalChartDefinition ! : ChartDefinition ;
30
+ private fullScreenFigureStore ! : Store < FullScreenChartStore > ;
18
31
19
32
private menuState : MenuState = useState ( { isOpen : false , anchorRect : null , menuItems : [ ] } ) ;
20
33
21
34
setup ( ) {
22
35
super . setup ( ) ;
36
+ this . fullScreenFigureStore = useStore ( FullScreenChartStore ) ;
23
37
this . originalChartDefinition = this . env . model . getters . getChartDefinition (
24
38
this . props . figureUI . id
25
39
) ;
@@ -30,7 +44,11 @@ export class ChartDashboardMenu extends Component<Props, SpreadsheetChildEnv> {
30
44
} ) ;
31
45
}
32
46
33
- getAvailableTypes ( ) {
47
+ getMenuItems ( ) : MenuItem [ ] {
48
+ return [ this . fullScreenMenuItem , ...this . changeChartTypeMenuItems ] . filter ( isDefined ) ;
49
+ }
50
+
51
+ get changeChartTypeMenuItems ( ) : MenuItem [ ] {
34
52
const definition = this . env . model . getters . getChartDefinition ( this . props . figureUI . id ) ;
35
53
if ( ! [ "line" , "bar" , "pie" ] . includes ( definition . type ) ) {
36
54
return [ ] ;
@@ -39,8 +57,11 @@ export class ChartDashboardMenu extends Component<Props, SpreadsheetChildEnv> {
39
57
return [ "column" , "line" , "pie" ] . map ( ( type ) => {
40
58
const item = chartSubtypeRegistry . get ( type ) ;
41
59
return {
42
- ...item ,
43
- icon : this . getIconClasses ( item . chartType ) ,
60
+ id : item . chartType ,
61
+ label : item . displayName ,
62
+ onClick : ( ) => this . onTypeChange ( item . chartType ) ,
63
+ isSelected : item . chartType === this . selectedChartType ,
64
+ iconClass : this . getIconClasses ( item . chartType ) ,
44
65
} ;
45
66
} ) ;
46
67
}
@@ -100,4 +121,30 @@ export class ChartDashboardMenu extends Component<Props, SpreadsheetChildEnv> {
100
121
this . menuState . anchorRect = { x : ev . clientX , y : ev . clientY , width : 0 , height : 0 } ;
101
122
this . menuState . menuItems = getChartMenuActions ( this . props . figureUI . id , ( ) => { } , this . env ) ;
102
123
}
124
+
125
+ get fullScreenMenuItem ( ) : MenuItem | undefined {
126
+ const definition = this . env . model . getters . getChartDefinition ( this . props . figureUI . id ) ;
127
+ if ( definition . type === "scorecard" ) {
128
+ return undefined ;
129
+ }
130
+
131
+ if ( this . props . figureUI . id === this . fullScreenFigureStore . fullScreenFigure ?. id ) {
132
+ return {
133
+ id : "fullScreenChart" ,
134
+ label : _t ( "Exit Full Screen" ) ,
135
+ iconClass : "fa fa-compress" ,
136
+ onClick : ( ) => {
137
+ this . fullScreenFigureStore . toggleFullScreenChart ( this . props . figureUI . id ) ;
138
+ } ,
139
+ } ;
140
+ }
141
+ return {
142
+ id : "fullScreenChart" ,
143
+ label : _t ( "Full Screen" ) ,
144
+ iconClass : "fa fa-expand" ,
145
+ onClick : ( ) => {
146
+ this . fullScreenFigureStore . toggleFullScreenChart ( this . props . figureUI . id ) ;
147
+ } ,
148
+ } ;
149
+ }
103
150
}
0 commit comments