Skip to content

Commit

Permalink
displayName implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Aug 13, 2020
1 parent 0f6d445 commit 78e42e9
Show file tree
Hide file tree
Showing 25 changed files with 183 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,42 @@ const initialState: IndexPatternPrivateState = {
fields: [
{
name: 'timestamp',
displayName: 'timestamp',
type: 'date',
aggregatable: true,
searchable: true,
},
{
name: 'bytes',
displayName: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
},
{
name: 'memory',
displayName: 'memory',
type: 'number',
aggregatable: true,
searchable: true,
},
{
name: 'unsupported',
displayName: 'unsupported',
type: 'geo',
aggregatable: true,
searchable: true,
},
{
name: 'source',
displayName: 'source',
type: 'string',
aggregatable: true,
searchable: true,
},
{
name: 'client',
displayName: 'client',
type: 'ip',
aggregatable: true,
searchable: true,
Expand All @@ -131,6 +137,7 @@ const initialState: IndexPatternPrivateState = {
fields: [
{
name: 'timestamp',
displayName: 'timestamp',
type: 'date',
aggregatable: true,
searchable: true,
Expand All @@ -145,6 +152,7 @@ const initialState: IndexPatternPrivateState = {
},
{
name: 'bytes',
displayName: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
Expand All @@ -166,6 +174,7 @@ const initialState: IndexPatternPrivateState = {
},
{
name: 'source',
displayName: 'source',
type: 'string',
aggregatable: true,
searchable: true,
Expand All @@ -185,18 +194,21 @@ const initialState: IndexPatternPrivateState = {
fields: [
{
name: 'timestamp',
displayName: 'timestamp',
type: 'date',
aggregatable: true,
searchable: true,
},
{
name: 'bytes',
displayName: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
},
{
name: 'source',
displayName: 'source',
type: 'string',
aggregatable: true,
searchable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { mount } from 'enzyme';
import React from 'react';
import { BucketNestingEditor } from './bucket_nesting_editor';
import { IndexPatternColumn } from '../indexpattern';
import { IndexPatternField } from '../types';

const fieldMap = {
a: { displayName: 'a' } as IndexPatternField,
b: { displayName: 'b' } as IndexPatternField,
c: { displayName: 'c' } as IndexPatternField,
};

describe('BucketNestingEditor', () => {
function mockCol(col: Partial<IndexPatternColumn> = {}): IndexPatternColumn {
Expand All @@ -32,6 +39,7 @@ describe('BucketNestingEditor', () => {
it('should display the top level grouping when at the root', () => {
const component = mount(
<BucketNestingEditor
fieldMap={fieldMap}
columnId="a"
layer={{
columnOrder: ['a', 'b', 'c'],
Expand All @@ -56,6 +64,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['b', 'a', 'c'],
columns: {
Expand All @@ -81,6 +90,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['b', 'a', 'c'],
columns: {
Expand Down Expand Up @@ -124,6 +134,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['a', 'b', 'c'],
columns: {
Expand All @@ -144,6 +155,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['a', 'b', 'c'],
columns: {
Expand All @@ -164,6 +176,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['c', 'a', 'b'],
columns: {
Expand All @@ -187,6 +200,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['c', 'a', 'b'],
columns: {
Expand All @@ -213,6 +227,7 @@ describe('BucketNestingEditor', () => {
const component = mount(
<BucketNestingEditor
columnId="a"
fieldMap={fieldMap}
layer={{
columnOrder: ['c', 'a', 'b'],
columns: {
Expand All @@ -238,6 +253,7 @@ describe('BucketNestingEditor', () => {
const setColumns = jest.fn();
const component = mount(
<BucketNestingEditor
fieldMap={fieldMap}
columnId="b"
layer={{
columnOrder: ['c', 'a', 'b'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiHorizontalRule, EuiRadio, EuiSelect, htmlIdGenerator } from '@elastic/eui';
import { IndexPatternLayer } from '../types';
import { IndexPatternLayer, IndexPatternField } from '../types';
import { hasField } from '../utils';

const generator = htmlIdGenerator('lens-nesting');
Expand All @@ -25,10 +25,12 @@ export function BucketNestingEditor({
columnId,
layer,
setColumns,
fieldMap,
}: {
columnId: string;
layer: IndexPatternLayer;
setColumns: (columns: string[]) => void;
fieldMap: Record<string, IndexPatternField>;
}) {
const column = layer.columns[columnId];
const columns = Object.entries(layer.columns);
Expand All @@ -37,14 +39,14 @@ export function BucketNestingEditor({
.map(([value, c]) => ({
value,
text: c.label,
fieldName: hasField(c) ? c.sourceField : '',
fieldName: hasField(c) ? fieldMap[c.sourceField].displayName : '',
}));

if (!column || !column.isBucketed || !aggColumns.length) {
return null;
}

const fieldName = hasField(column) ? column.sourceField : '';
const fieldName = hasField(column) ? fieldMap[column.sourceField].displayName : '';

const prevColumn = layer.columnOrder[layer.columnOrder.indexOf(columnId) - 1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,31 @@ const expectedIndexPatterns = {
fields: [
{
name: 'timestamp',
displayName: 'timestamp',
type: 'date',
aggregatable: true,
searchable: true,
exists: true,
},
{
name: 'bytes',
displayName: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
exists: true,
},
{
name: 'memory',
displayName: 'memory',
type: 'number',
aggregatable: true,
searchable: true,
exists: true,
},
{
name: 'source',
displayName: 'source',
type: 'string',
aggregatable: true,
searchable: true,
Expand Down Expand Up @@ -1095,12 +1099,12 @@ describe('IndexPatternDimensionEditorPanel', () => {
columnOrder: ['col1'],
columns: {
col1: {
label: 'Average of bar',
label: 'Average of memory',
dataType: 'number',
isBucketed: false,
// Private
operationType: 'avg',
sourceField: 'bar',
sourceField: 'memory',
},
},
},
Expand Down Expand Up @@ -1145,12 +1149,12 @@ describe('IndexPatternDimensionEditorPanel', () => {
columnOrder: ['col1'],
columns: {
col1: {
label: 'Average of bar',
label: 'Average of memory',
dataType: 'number',
isBucketed: false,
// Private
operationType: 'avg',
sourceField: 'bar',
sourceField: 'memory',
params: {
format: { id: 'bytes', params: { decimals: 0 } },
},
Expand Down Expand Up @@ -1195,12 +1199,12 @@ describe('IndexPatternDimensionEditorPanel', () => {
columnOrder: ['col1'],
columns: {
col1: {
label: 'Average of bar',
label: 'Average of memory',
dataType: 'number',
isBucketed: false,
// Private
operationType: 'avg',
sourceField: 'bar',
sourceField: 'memory',
params: {
format: { id: 'bytes', params: { decimals: 2 } },
},
Expand Down Expand Up @@ -1253,12 +1257,14 @@ describe('IndexPatternDimensionEditorPanel', () => {
{
aggregatable: true,
name: 'bar',
displayName: 'bar',
searchable: true,
type: 'number',
},
{
aggregatable: true,
name: 'mystring',
displayName: 'mystring',
searchable: true,
type: 'string',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function FieldSelect({
function fieldNamesToOptions(items: string[]) {
return items
.map((field) => ({
label: field,
label: fieldMap[field].displayName,
value: {
type: 'field',
field,
Expand Down Expand Up @@ -161,7 +161,7 @@ export function FieldSelect({
? selectedColumnSourceField
? [
{
label: selectedColumnSourceField,
label: fieldMap[selectedColumnSourceField].displayName,
value: { type: 'field', field: selectedColumnSourceField },
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export function PopoverEditor(props: PopoverEditorProps) {

{!hideGrouping && (
<BucketNestingEditor
fieldMap={fieldMap}
layer={state.layers[props.layerId]}
columnId={props.columnId}
setColumns={(columnOrder) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
*/

import { i18n } from '@kbn/i18n';
import { IndexPatternField } from './types';

/**
* This is a special-case field which allows us to perform
* document-level operations such as count.
*/
export const documentField = {
export const documentField: IndexPatternField = {
displayName: i18n.translate('xpack.lens.indexPattern.records', {
defaultMessage: 'Records',
}),
name: i18n.translate('xpack.lens.indexPattern.records', {
defaultMessage: 'Records',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('IndexPattern Field Item', () => {
filters: [],
field: {
name: 'bytes',
displayName: 'bytes',
type: 'number',
aggregatable: true,
searchable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const InnerFieldItem = function InnerFieldItem(props: FieldItemProps) {
isLoading: false,
});

const wrappableName = wrapOnDot(field.name)!;
const wrappableName = wrapOnDot(field.displayName)!;
const wrappableHighlight = wrapOnDot(highlight);
const highlightIndex = wrappableHighlight
? wrappableName.toLowerCase().indexOf(wrappableHighlight.toLowerCase())
Expand Down Expand Up @@ -185,7 +185,7 @@ export const InnerFieldItem = function InnerFieldItem(props: FieldItemProps) {
container={document.querySelector<HTMLElement>('.application') || undefined}
button={
<DragDrop
label={field.name}
label={field.displayName}
value={value}
data-test-subj="lnsFieldListPanelField"
draggable
Expand Down Expand Up @@ -213,7 +213,7 @@ export const InnerFieldItem = function InnerFieldItem(props: FieldItemProps) {
>
<LensFieldIcon type={field.type as DataType} />

<span className="lnsFieldItem__name" title={field.name}>
<span className="lnsFieldItem__name" title={field.displayName}>
{wrappableHighlightableFieldName}
</span>

Expand Down
Loading

0 comments on commit 78e42e9

Please sign in to comment.