Skip to content

Commit

Permalink
Add title to Custom Wildcard Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
espressoroaster committed Feb 11, 2018
1 parent 1990e7f commit 9ec6fb1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/components/field/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Schema} from 'compassql/build/src/schema';
import {isWildcard} from 'compassql/build/src/wildcard';
import {isWildcard, isWildcardDef} from 'compassql/build/src/wildcard';
import * as React from 'react';
import * as CSSModules from 'react-css-modules';
import {
Expand All @@ -9,6 +9,7 @@ import {
import * as TetherComponent from 'react-tether';
import {OneOfFilter, RangeFilter} from 'vega-lite/build/src/filter';
import {DraggableType, FieldParentType} from '../../constants';
import {CustomWildcardFieldDef} from '../../models/custom-wildcard-field';
import {ShelfId} from '../../models/shelf';
import {ShelfFieldDef} from '../../models/shelf';
import {createDefaultFilter} from '../../models/shelf/filter';
Expand Down Expand Up @@ -123,6 +124,14 @@ class FieldBase extends React.PureComponent<FieldProps, FieldState> {
fnName = fn;
}

const isCustomWildcardField = isWildcardDef(fieldDef.field);
let customWildcardFieldDescription = "";

if (isCustomWildcardField) {
const fields = (fieldDef as CustomWildcardFieldDef).field.enum; // TS isn't the inferring correct type
customWildcardFieldDescription = "(" + fields.length + ") " + (description || fields.toString());
}

let component = (
<span
styleName={
Expand All @@ -137,7 +146,11 @@ class FieldBase extends React.PureComponent<FieldProps, FieldState> {
{this.renderCaretTypeSpan()}
{this.renderFuncSpan(fnName)}
<span styleName={isFieldFn ? 'fn-text' : 'text'}>
{isWildcard(field) ? description : field !== '*' ? field : ''}
{
isWildcard(field) ?
(isCustomWildcardField ? customWildcardFieldDescription : description) :
(field !== '*' ? field : '')
}
</span>
{this.renderAddFilterSpan()}
{this.renderAddSpan()}
Expand Down

0 comments on commit 9ec6fb1

Please sign in to comment.