2
2
3
3
import { Component , onWillUpdateProps } from "@odoo/owl" ;
4
4
import { DateTimeInput } from "@web/core/datetime/datetime_input" ;
5
- import { FILTER_DATE_OPTION , monthsOptions } from "@spreadsheet/assets_backend/constants" ;
6
- import { getPeriodOptions } from "@web/search/utils/dates" ;
5
+ import { monthsOptions } from "@spreadsheet/assets_backend/constants" ;
6
+ import { QUARTER_OPTIONS } from "@web/search/utils/dates" ;
7
7
8
8
const { DateTime } = luxon ;
9
9
10
10
export class DateFilterValue extends Component {
11
+ static template = "spreadsheet_edition.DateFilterValue" ;
12
+ static components = { DateTimeInput } ;
13
+ static props = {
14
+ // See @spreadsheet_edition /bundle/global_filters/filters_plugin.RangeType
15
+ onTimeRangeChanged : Function ,
16
+ yearOffset : { type : Number , optional : true } ,
17
+ period : { type : String , optional : true } ,
18
+ disabledPeriods : { type : Array , optional : true } ,
19
+ } ;
11
20
setup ( ) {
12
21
this . _setStateFromProps ( this . props ) ;
13
- onWillUpdateProps ( this . _setStateFromProps ) ;
14
- this . dateOptions = this . getDateOptions ( ) ;
22
+ this . dateOptions = this . getDateOptions ( this . props ) ;
23
+ onWillUpdateProps ( ( nextProps ) => {
24
+ this . _setStateFromProps ( nextProps ) ;
25
+ this . dateOptions = this . getDateOptions ( nextProps ) ;
26
+ } ) ;
15
27
}
16
28
_setStateFromProps ( props ) {
17
29
this . period = props . period ;
@@ -32,12 +44,18 @@ export class DateFilterValue extends Component {
32
44
*
33
45
* @returns {Array<Object> }
34
46
*/
35
- getDateOptions ( ) {
36
- const periodOptions = getPeriodOptions ( DateTime . local ( ) ) ;
37
- const quarters = FILTER_DATE_OPTION [ "quarter" ] . map ( ( quarterId ) =>
38
- periodOptions . find ( ( option ) => option . id === quarterId )
39
- ) ;
40
- return quarters . concat ( monthsOptions ) ;
47
+ getDateOptions ( props ) {
48
+ const quarterOptions = Object . values ( QUARTER_OPTIONS ) ;
49
+ const disabledPeriods = props . disabledPeriods || [ ] ;
50
+
51
+ const dateOptions = [ ] ;
52
+ if ( ! disabledPeriods . includes ( "quarter" ) ) {
53
+ dateOptions . push ( ...quarterOptions ) ;
54
+ }
55
+ if ( ! disabledPeriods . includes ( "month" ) ) {
56
+ dateOptions . push ( ...monthsOptions ) ;
57
+ }
58
+ return dateOptions ;
41
59
}
42
60
43
61
isSelected ( periodId ) {
@@ -65,12 +83,3 @@ export class DateFilterValue extends Component {
65
83
} ) ;
66
84
}
67
85
}
68
- DateFilterValue . template = "spreadsheet_edition.DateFilterValue" ;
69
- DateFilterValue . components = { DateTimeInput } ;
70
-
71
- DateFilterValue . props = {
72
- // See @spreadsheet_edition /bundle/global_filters/filters_plugin.RangeType
73
- onTimeRangeChanged : Function ,
74
- yearOffset : { type : Number , optional : true } ,
75
- period : { type : String , optional : true } ,
76
- } ;
0 commit comments