11import { Component , useEffect , useExternalListener } from "@odoo/owl" ;
2- import { DEFAULT_COLOR_SCALE_MIDPOINT_COLOR } from "../../../../constants" ;
3- import { colorNumberToHex , deepCopy } from "../../../../helpers" ;
2+ import { deepCopy } from "../../../../helpers" ;
43import { useLocalStore } from "../../../../store_engine" ;
54import { _t } from "../../../../translation" ;
6- import {
7- ColorScaleThreshold ,
8- CommandResult ,
9- ConditionalFormat ,
10- UID ,
11- ValueAndLabel ,
12- } from "../../../../types" ;
5+ import { ConditionalFormat , UID } from "../../../../types" ;
136import { SpreadsheetChildEnv } from "../../../../types/spreadsheet_env" ;
147import { Store } from "../../../../types/store_engine" ;
15- import { ColorPickerWidget } from "../../../color_picker/color_picker_widget" ;
16- import { StandaloneComposer } from "../../../composer/standalone_composer/standalone_composer" ;
17- import { getTextDecoration } from "../../../helpers" ;
18- import { IconPicker } from "../../../icon_picker/icon_picker" ;
19- import { Select } from "../../../select/select" ;
208import { SelectionInput } from "../../../selection_input/selection_input" ;
219import { ValidationMessages } from "../../../validation_messages/validation_messages" ;
2210import { BadgeSelection } from "../../components/badge_selection/badge_selection" ;
23- import { RoundColorPicker } from "../../components/round_color_picker/round_color_picker" ;
2411import { Section } from "../../components/section/section" ;
12+ import { CellIsRuleEditor } from "./cell_is_rule_editor" ;
2513import { ConditionalFormattingEditorStore } from "./cf_editor_store" ;
14+ import { ColorScaleRuleEditor } from "./color_scale_rule_editor" ;
15+ import { DataBarRuleEditor } from "./data_bar_rule_editor" ;
16+ import { IconSetRuleEditor } from "./icon_set_rule_editor" ;
2617
2718interface Props {
2819 cf : ConditionalFormat ;
@@ -34,20 +25,16 @@ export class ConditionalFormattingEditor extends Component<Props, SpreadsheetChi
3425 static template = "o-spreadsheet-ConditionalFormattingEditor" ;
3526 static components = {
3627 SelectionInput,
37- IconPicker,
38- ColorPickerWidget,
3928 Section,
40- RoundColorPicker,
41- StandaloneComposer,
4229 BadgeSelection,
4330 ValidationMessages,
44- Select,
31+ CellIsRuleEditor,
32+ ColorScaleRuleEditor,
33+ IconSetRuleEditor,
34+ DataBarRuleEditor,
4535 } ;
4636 static props = { cf : Object , isNewCf : Boolean , onCloseSidePanel : Function } ;
4737
48- getTextDecoration = getTextDecoration ;
49- colorNumberToHex = colorNumberToHex ;
50-
5138 private activeSheetId ! : UID ;
5239 private store ! : Store < ConditionalFormattingEditorStore > ;
5340
@@ -122,131 +109,4 @@ export class ConditionalFormattingEditor extends Component<Props, SpreadsheetChi
122109 `ConditionalFormattingEditor_${ this . props . cf . id } `
123110 ) ;
124111 }
125-
126- /*****************************************************************************
127- * Color Scale Rule
128- ****************************************************************************/
129-
130- getThresholdColor ( threshold ?: ColorScaleThreshold ) {
131- return threshold
132- ? colorNumberToHex ( threshold . color )
133- : colorNumberToHex ( DEFAULT_COLOR_SCALE_MIDPOINT_COLOR ) ;
134- }
135-
136- isValueInvalid ( threshold : "minimum" | "midpoint" | "maximum" ) : boolean {
137- const errors = this . store . state . errors ;
138- switch ( threshold ) {
139- case "minimum" :
140- return (
141- errors . includes ( CommandResult . MinInvalidFormula ) ||
142- errors . includes ( CommandResult . MinBiggerThanMid ) ||
143- errors . includes ( CommandResult . MinBiggerThanMax ) ||
144- errors . includes ( CommandResult . MinNaN )
145- ) ;
146- case "midpoint" :
147- return (
148- errors . includes ( CommandResult . MidInvalidFormula ) ||
149- errors . includes ( CommandResult . MidNaN ) ||
150- errors . includes ( CommandResult . MidBiggerThanMax )
151- ) ;
152- case "maximum" :
153- return (
154- errors . includes ( CommandResult . MaxInvalidFormula ) || errors . includes ( CommandResult . MaxNaN )
155- ) ;
156- default :
157- return false ;
158- }
159- }
160-
161- getColorScaleComposerProps (
162- thresholdType : "minimum" | "midpoint" | "maximum"
163- ) : StandaloneComposer [ "props" ] {
164- const threshold = this . store . state . rules . colorScale [ thresholdType ] ;
165- if ( ! threshold ) {
166- throw new Error ( "Threshold not found" ) ;
167- }
168- const isInvalid = this . isValueInvalid ( thresholdType ) ;
169- return {
170- onConfirm : ( str : string ) => {
171- threshold . value = str ;
172- this . store . updateConditionalFormat ( { rule : this . store . state . rules . colorScale } ) ;
173- } ,
174- composerContent : threshold . value || "" ,
175- placeholder : _t ( "Formula" ) ,
176- defaultStatic : true ,
177- invalid : isInvalid ,
178- class : "o-sidePanel-composer" ,
179- defaultRangeSheetId : this . activeSheetId ,
180- } ;
181- }
182-
183- /*****************************************************************************
184- * Icon Set
185- ****************************************************************************/
186-
187- isInflectionPointInvalid (
188- inflectionPoint : "lowerInflectionPoint" | "upperInflectionPoint"
189- ) : boolean {
190- const errors = this . store . state . errors ;
191- switch ( inflectionPoint ) {
192- case "lowerInflectionPoint" :
193- return (
194- errors . includes ( CommandResult . ValueLowerInflectionNaN ) ||
195- errors . includes ( CommandResult . ValueLowerInvalidFormula ) ||
196- errors . includes ( CommandResult . LowerBiggerThanUpper )
197- ) ;
198- case "upperInflectionPoint" :
199- return (
200- errors . includes ( CommandResult . ValueUpperInflectionNaN ) ||
201- errors . includes ( CommandResult . ValueUpperInvalidFormula ) ||
202- errors . includes ( CommandResult . LowerBiggerThanUpper )
203- ) ;
204- default :
205- return true ;
206- }
207- }
208-
209- getColorIconSetComposerProps (
210- inflectionPoint : "lowerInflectionPoint" | "upperInflectionPoint"
211- ) : StandaloneComposer [ "props" ] {
212- const inflection = this . store . state . rules . iconSet [ inflectionPoint ] ;
213- const isInvalid = this . isInflectionPointInvalid ( inflectionPoint ) ;
214- return {
215- onConfirm : ( str : string ) => {
216- inflection . value = str ;
217- this . store . updateConditionalFormat ( { rule : this . store . state . rules . iconSet } ) ;
218- } ,
219- composerContent : inflection . value || "" ,
220- placeholder : _t ( "Formula" ) ,
221- defaultStatic : true ,
222- invalid : isInvalid ,
223- class : "o-sidePanel-composer" ,
224- defaultRangeSheetId : this . activeSheetId ,
225- } ;
226- }
227-
228- getThresholdTypeSelectOptions (
229- thresholdType : "minimum" | "midpoint" | "maximum" | "iconSet"
230- ) : ValueAndLabel [ ] {
231- const options : ValueAndLabel [ ] = [
232- { value : "number" , label : _t ( "Number" ) } ,
233- { value : "percentage" , label : _t ( "Percentage" ) } ,
234- { value : "percentile" , label : _t ( "Percentile" ) } ,
235- { value : "formula" , label : _t ( "Formula" ) } ,
236- ] ;
237- if ( thresholdType === "iconSet" ) {
238- return options ;
239- }
240- if ( thresholdType === "midpoint" ) {
241- return [ { value : "none" , label : _t ( "None" ) } , ...options ] ;
242- }
243- return [ { value : "value" , label : _t ( "Cell values" ) } , ...options ] ;
244- }
245-
246- getIconSetOperatorSelectOptions ( ) : ValueAndLabel [ ] {
247- return [
248- { value : "gt" , label : ">" } ,
249- { value : "ge" , label : ">=" } ,
250- ] ;
251- }
252112}
0 commit comments