fix: early-out for literal

This commit is contained in:
cha0s 2020-06-23 20:17:55 -05:00
parent 4a7afab0df
commit 92acaa3b86

View File

@ -1,4 +1,4 @@
import {makeCompilable} from '@avocado/behavior';
import {makeCompilable, description as typeDescription} from '@avocado/behavior';
import {compose} from '@avocado/core';
import contempo from 'contempo';
import React from 'react';
@ -16,7 +16,7 @@ const decorate = compose(
contempo(require('./expression.raw.scss')),
);
const Traversal = (props) => {
const Expression = (props) => {
const {
context,
onChange = () => {},
@ -39,6 +39,11 @@ const Traversal = (props) => {
<span className="key" data-op-key={op.key}>
<select
onChange={(event) => {
if ('<literal>' === event.target.value) {
const {defaultLiteral} = typeDescription(type, undefined);
onChange({type: 'literal', value: defaultLiteral}, event);
return;
}
const newSteps = [
...ops.slice(0, i),
{
@ -46,7 +51,7 @@ const Traversal = (props) => {
key: event.target.value,
},
];
return onChange({
onChange({
...value,
ops: defaultOps(context, type, newSteps),
value: undefined,
@ -55,7 +60,7 @@ const Traversal = (props) => {
value={op.key}
>
{
options
[...options, '<literal>']
.sort((l, r) => (l.toLowerCase() < r.toLowerCase() ? -1 : 1))
.map((option) => <option key={option}>{option}</option>)
}
@ -133,11 +138,11 @@ const Traversal = (props) => {
);
};
Traversal.propTypes = {
Expression.propTypes = {
...propTypes,
};
export default {
type: 'expression',
Component: decorate(Traversal),
Component: decorate(Expression),
};