Skip to content

Commit

Permalink
Adding missing type to lens field icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic committed Oct 3, 2019
1 parent 7364649 commit 2b03cf7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ import { i18n } from '@kbn/i18n';
import { toElasticsearchQuery } from '@kbn/es-query';
import { Query } from 'src/plugins/data/common';
// @ts-ignore
import classNames from 'classnames';
import { fieldFormats } from '../../../../../../src/legacy/ui/public/registry/field_formats';
import { IndexPattern, IndexPatternField, DraggedField } from './indexpattern';
import { DragDrop } from '../drag_drop';
import { DatasourceDataPanelProps, DataType } from '../types';
import { BucketedAggregation, FieldStatsResponse } from '../../common';
import { LensFieldIcon } from './lens_field_icon';
import { LensFieldIcon, getColorForDataType } from './lens_field_icon';

export interface FieldItemProps {
core: DatasourceDataPanelProps['core'];
Expand Down Expand Up @@ -362,6 +361,7 @@ function FieldItemPopoverContents(props: State & FieldItemProps) {
colorValues: [],
specId,
};
const expectedColor = getColorForDataType(field.type);

const seriesColors = new Map([[colors, expectedColor]]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,32 @@
*/

import React from 'react';
import { ICON_TYPES, palettes } from '@elastic/eui';
import classNames from 'classnames';
import { FieldIcon } from '../../../../../../src/plugins/kibana_react/public';
import { DataType } from '../types';

function stringToNum(s: string) {
return Array.from(s).reduce((acc, ch) => acc + ch.charCodeAt(0), 1);
}

function getIconForDataType(dataType: string) {
const icons: Partial<Record<string, UnwrapArray<typeof ICON_TYPES>>> = {
boolean: 'invert',
date: 'calendar',
geo_point: 'globe',
ip: 'storage',
};
return icons[dataType] || ICON_TYPES.find(t => t === dataType) || 'document';
}

export function getColorForDataType(type: string) {
const iconType = getIconForDataType(type);
const { colors } = palettes.euiPaletteColorBlind;
const colorIndex = stringToNum(iconType) % colors.length;
return colors[colorIndex];
}

export function LensFieldIcon({ type }: { type: DataType }) {
const classes = classNames(
'lnsFieldListPanel__fieldIcon',
Expand Down

0 comments on commit 2b03cf7

Please sign in to comment.