From 3d401de92c2ef76292af05bd48bf40e3350d1fe0 Mon Sep 17 00:00:00 2001 From: Alex P Date: Fri, 4 May 2018 16:04:00 -0700 Subject: [PATCH] Color builder arguments based on type --- ui/src/ifql/components/FuncNode.tsx | 46 ++++++++++++++++--- .../components/time-machine/ifql-builder.scss | 8 +++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/ui/src/ifql/components/FuncNode.tsx b/ui/src/ifql/components/FuncNode.tsx index 747d630d4..36e8b695e 100644 --- a/ui/src/ifql/components/FuncNode.tsx +++ b/ui/src/ifql/components/FuncNode.tsx @@ -1,4 +1,5 @@ import React, {PureComponent, MouseEvent} from 'react' +import uuid from 'uuid' import FuncArgs from 'src/ifql/components/FuncArgs' import {OnDeleteFuncNode, OnChangeArg, Func} from 'src/types/ifql' import {ErrorHandling} from 'src/shared/decorators/errors' @@ -46,7 +47,7 @@ export default class FuncNode extends PureComponent { onMouseLeave={this.handleMouseLeave} >
{func.name}
-
{this.stringifyArgs}
+ {this.coloredSyntaxArgs} {isExpanded && ( { ) } - private get stringifyArgs(): string { + private get coloredSyntaxArgs(): JSX.Element { const { func: {args}, } = this.props @@ -70,15 +71,46 @@ export default class FuncNode extends PureComponent { return } - return args.reduce((acc, arg, i) => { + const coloredSyntax = args.map((arg, i): JSX.Element => { if (!arg.value) { - return acc + return } - const separator = i === 0 ? '' : ', ' + const separator = i === 0 ? null : ', ' - return `${acc}${separator}${arg.key}: ${arg.value}` - }, '') + return ( + + {separator} + {arg.key}: {this.colorArgType(`${arg.value}`, arg.type)} + + ) + }) + + return
{coloredSyntax}
+ } + + private colorArgType = (argument: string, type: string): JSX.Element => { + switch (type) { + case 'time': + case 'number': + case 'period': + case 'duration': + case 'array': { + return {argument} + } + case 'bool': { + return {argument} + } + case 'string': { + return "{argument}" + } + case 'invalid': { + return {argument} + } + default: { + return {argument} + } + } } private handleDelete = (): void => { diff --git a/ui/src/style/components/time-machine/ifql-builder.scss b/ui/src/style/components/time-machine/ifql-builder.scss index 7731e73cd..b9b187deb 100644 --- a/ui/src/style/components/time-machine/ifql-builder.scss +++ b/ui/src/style/components/time-machine/ifql-builder.scss @@ -51,9 +51,15 @@ $ifql-arg-min-width: 120px; .variable-value--string { color: $c-honeydew } +.variable-value--boolean { + color: $c-viridian +} .variable-value--number { color: $c-neutrino; } +.variable-value--invalid { + color: $c-dreamsicle; +} .func-node { @extend %ifql-node; @@ -97,7 +103,7 @@ $ifql-arg-min-width: 120px; } .func-node--preview { - color: $g13-mist; + color: $g11-sidewalk; margin-left: 4px; .func-node:hover & {