Skip to content

Commit

Permalink
Renamed ColorSchemaVislibParams to ColorSchemaParams, added enums and…
Browse files Browse the repository at this point in the history
… got rid of useValidation function
  • Loading branch information
DianaDerevyankina committed Apr 10, 2020
1 parent 61860ee commit b09c31a
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -43,7 +43,7 @@ function RangesPanel({
vis,
}: GaugeOptionsInternalProps) {
const setColorSchemaOptions = useCallback(
<T extends keyof ColorSchemaVislibParams>(paramName: T, value: ColorSchemaVislibParams[T]) => {
<T extends keyof ColorSchemaParams>(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
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/vis_type_vislib/public/gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/vis_type_vislib/public/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 10 additions & 14 deletions src/plugins/charts/public/static/components/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof ColorModes>;

export const Rotates = Object.freeze({
HORIZONTAL: 0,
VERTICAL: 90,
ANGLED: 75,
});
export type Rotates = $Values<typeof Rotates>;
export enum Rotates {
HORIZONTAL = 0,
VERTICAL = 90,
ANGLED = 75,
}
8 changes: 4 additions & 4 deletions src/plugins/charts/public/static/components/color_schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T extends keyof ColorSchemaVislibParams>(
export type SetColorSchemaOptionsValue = <T extends keyof ColorSchemaParams>(
paramName: T,
value: ColorSchemaVislibParams[T]
value: ColorSchemaParams[T]
) => void;

interface ColorSchemaOptionsProps extends ColorSchemaVislibParams {
interface ColorSchemaOptionsProps extends ColorSchemaParams {
disabled?: boolean;
colorSchemas: ColorSchema[];
uiState: VisOptionsProps['uiState'];
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/charts/public/static/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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<ParamName extends string> {
disabled?: boolean;
Expand Down Expand Up @@ -57,7 +56,12 @@ function RequiredNumberInputOption<ParamName extends string>({
'data-test-subj': dataTestSubj,
}: NumberInputOptionProps<ParamName>) {
const isValid = value !== null;
useValidation(setValidity, paramName, isValid);

useEffect(() => {
setValidity(paramName, isValid);

return () => setValidity(paramName, true);
}, [isValid, paramName, setValidity]);

const onChange = useCallback(
(ev: ChangeEvent<HTMLInputElement>) =>
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/charts/public/static/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { ColorSchemas } from '../color_maps';
import { Rotates } from './collections';

export interface ColorSchemaVislibParams {
export interface ColorSchemaParams {
colorSchema: ColorSchemas;
invertColors: boolean;
}
Expand Down
34 changes: 0 additions & 34 deletions src/plugins/charts/public/static/components/utils.ts

This file was deleted.

0 comments on commit b09c31a

Please sign in to comment.