diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/gauge/ranges_panel.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/gauge/ranges_panel.tsx index d2b5e8f1fbc1b..433cc4edeb47b 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/gauge/ranges_panel.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/gauge/ranges_panel.tsx @@ -25,13 +25,13 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { ColorRanges, ColorSchemaOptions, - ColorSchemaVislibParams, + ColorSchemaParams, SetColorRangeValue, SwitchOption, + ColorSchemas, } from '../../../../../../../plugins/charts/public'; import { GaugeOptionsInternalProps } from '.'; import { Gauge } from '../../../gauge'; -import { ColorSchemas } from '../../../../../../../plugins/charts/public'; function RangesPanel({ setGaugeValue, @@ -43,7 +43,7 @@ function RangesPanel({ vis, }: GaugeOptionsInternalProps) { const setColorSchemaOptions = useCallback( - (paramName: T, value: ColorSchemaVislibParams[T]) => { + (paramName: T, value: ColorSchemaParams[T]) => { setGaugeValue(paramName, value as Gauge[T]); // set outline if color schema is changed to greys // if outline wasn't set explicitly yet diff --git a/src/legacy/core_plugins/vis_type_vislib/public/gauge.ts b/src/legacy/core_plugins/vis_type_vislib/public/gauge.ts index b6526d1f80599..5e0b2b8fbd36c 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/gauge.ts +++ b/src/legacy/core_plugins/vis_type_vislib/public/gauge.ts @@ -26,14 +26,14 @@ import { getGaugeCollections, Alignments, GaugeTypes } from './utils/collections import { ColorModes, ColorSchemas, - ColorSchemaVislibParams, + ColorSchemaParams, Labels, Style, } from '../../../../plugins/charts/public'; import { createVislibVisController } from './vis_controller'; import { VisTypeVislibDependencies } from './plugin'; -export interface Gauge extends ColorSchemaVislibParams { +export interface Gauge extends ColorSchemaParams { backStyle: 'Full'; gaugeStyle: 'Full'; orientation: 'vertical'; diff --git a/src/legacy/core_plugins/vis_type_vislib/public/heatmap.ts b/src/legacy/core_plugins/vis_type_vislib/public/heatmap.ts index 4eafc0b09070c..9feed60b984ba 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/heatmap.ts +++ b/src/legacy/core_plugins/vis_type_vislib/public/heatmap.ts @@ -27,9 +27,9 @@ import { createVislibVisController } from './vis_controller'; import { TimeMarker } from './vislib/visualizations/time_marker'; import { CommonVislibParams, ValueAxis } from './types'; import { VisTypeVislibDependencies } from './plugin'; -import { ColorSchemas, ColorSchemaVislibParams } from '../../../../plugins/charts/public'; +import { ColorSchemas, ColorSchemaParams } from '../../../../plugins/charts/public'; -export interface HeatmapVisParams extends CommonVislibParams, ColorSchemaVislibParams { +export interface HeatmapVisParams extends CommonVislibParams, ColorSchemaParams { type: 'heatmap'; addLegend: boolean; enableHover: boolean; diff --git a/src/plugins/charts/public/static/components/collections.ts b/src/plugins/charts/public/static/components/collections.ts index 9dde50f2b44c9..52359157ae5f5 100644 --- a/src/plugins/charts/public/static/components/collections.ts +++ b/src/plugins/charts/public/static/components/collections.ts @@ -17,18 +17,14 @@ * under the License. */ -import { $Values } from '@kbn/utility-types'; +export enum ColorModes { + BACKGROUND = 'Background', + LABELS = 'Labels', + NONE = 'None', +} -export const ColorModes = Object.freeze({ - BACKGROUND: 'Background' as 'Background', - LABELS: 'Labels' as 'Labels', - NONE: 'None' as 'None', -}); -export type ColorModes = $Values; - -export const Rotates = Object.freeze({ - HORIZONTAL: 0, - VERTICAL: 90, - ANGLED: 75, -}); -export type Rotates = $Values; +export enum Rotates { + HORIZONTAL = 0, + VERTICAL = 90, + ANGLED = 75, +} diff --git a/src/plugins/charts/public/static/components/color_schema.tsx b/src/plugins/charts/public/static/components/color_schema.tsx index 9bc29bcb6f311..62fe3143f0481 100644 --- a/src/plugins/charts/public/static/components/color_schema.tsx +++ b/src/plugins/charts/public/static/components/color_schema.tsx @@ -25,15 +25,15 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { VisOptionsProps } from 'src/plugins/vis_default_editor/public'; import { SelectOption } from './select'; import { SwitchOption } from './switch'; -import { ColorSchemaVislibParams } from './types'; +import { ColorSchemaParams } from './types'; import { ColorSchema } from '../color_maps'; -export type SetColorSchemaOptionsValue = ( +export type SetColorSchemaOptionsValue = ( paramName: T, - value: ColorSchemaVislibParams[T] + value: ColorSchemaParams[T] ) => void; -interface ColorSchemaOptionsProps extends ColorSchemaVislibParams { +interface ColorSchemaOptionsProps extends ColorSchemaParams { disabled?: boolean; colorSchemas: ColorSchema[]; uiState: VisOptionsProps['uiState']; diff --git a/src/plugins/charts/public/static/components/index.ts b/src/plugins/charts/public/static/components/index.ts index 7f09e78845cb9..48c9e40145481 100644 --- a/src/plugins/charts/public/static/components/index.ts +++ b/src/plugins/charts/public/static/components/index.ts @@ -21,11 +21,10 @@ export { BasicOptions } from './basic_options'; export { ColorModes, Rotates } from './collections'; export { ColorRanges, SetColorRangeValue } from './color_ranges'; export { ColorSchemaOptions, SetColorSchemaOptionsValue } from './color_schema'; -export { ColorSchemaVislibParams, Labels, Style } from './types'; +export { ColorSchemaParams, Labels, Style } from './types'; export { NumberInputOption } from './number_input'; export { RangeOption } from './range'; export { RequiredNumberInputOption } from './required_number_input'; export { SelectOption } from './select'; export { SwitchOption } from './switch'; export { TextInputOption } from './text_input'; -export { useValidation } from './utils'; diff --git a/src/plugins/charts/public/static/components/required_number_input.tsx b/src/plugins/charts/public/static/components/required_number_input.tsx index a9ddbadb86228..7594c775b07ad 100644 --- a/src/plugins/charts/public/static/components/required_number_input.tsx +++ b/src/plugins/charts/public/static/components/required_number_input.tsx @@ -17,9 +17,8 @@ * under the License. */ -import React, { ReactNode, useCallback, ChangeEvent } from 'react'; +import React, { ReactNode, useCallback, ChangeEvent, useEffect } from 'react'; import { EuiFormRow, EuiFieldNumber } from '@elastic/eui'; -import { useValidation } from './utils'; interface NumberInputOptionProps { disabled?: boolean; @@ -57,7 +56,12 @@ function RequiredNumberInputOption({ 'data-test-subj': dataTestSubj, }: NumberInputOptionProps) { const isValid = value !== null; - useValidation(setValidity, paramName, isValid); + + useEffect(() => { + setValidity(paramName, isValid); + + return () => setValidity(paramName, true); + }, [isValid, paramName, setValidity]); const onChange = useCallback( (ev: ChangeEvent) => diff --git a/src/plugins/charts/public/static/components/types.ts b/src/plugins/charts/public/static/components/types.ts index de8ec80abf0f2..196eb60b06aec 100644 --- a/src/plugins/charts/public/static/components/types.ts +++ b/src/plugins/charts/public/static/components/types.ts @@ -20,7 +20,7 @@ import { ColorSchemas } from '../color_maps'; import { Rotates } from './collections'; -export interface ColorSchemaVislibParams { +export interface ColorSchemaParams { colorSchema: ColorSchemas; invertColors: boolean; } diff --git a/src/plugins/charts/public/static/components/utils.ts b/src/plugins/charts/public/static/components/utils.ts deleted file mode 100644 index d51631106dda7..0000000000000 --- a/src/plugins/charts/public/static/components/utils.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import { useEffect } from 'react'; - -function useValidation( - setValidity: (paramName: ParamName, isValid: boolean) => void, - paramName: ParamName, - isValid: boolean -) { - useEffect(() => { - setValidity(paramName, isValid); - - return () => setValidity(paramName, true); - }, [isValid, paramName, setValidity]); -} - -export { useValidation };