Skip to content

Commit

Permalink
handle string value for array operators in console permission builder
Browse files Browse the repository at this point in the history
  • Loading branch information
rikinsk committed Mar 26, 2019
1 parent d80694e commit 20202f5
Showing 1 changed file with 31 additions and 15 deletions.
Expand Up @@ -410,6 +410,14 @@ class PermissionBuilder extends React.Component {

/********************************/

const sessionVariableSuggestion = dispatchInput => {
return renderSuggestion(dispatchInput, 'X-Hasura-User-Id');
};

const jsonSuggestion = dispatchInput => {
return renderSuggestion(dispatchInput, '{}', 'JSON');
};

const renderValue = (dispatchFunc, value, prefix, valueType) => {
const dispatchInput = val => {
let _val = val;
Expand Down Expand Up @@ -440,14 +448,6 @@ class PermissionBuilder extends React.Component {
return renderInput(dispatchInput, value);
};

const sessionVariableSuggestion = () => {
return renderSuggestion(dispatchInput, 'X-Hasura-User-Id');
};

const jsonSuggestion = () => {
return renderSuggestion(dispatchInput, '{}', 'JSON');
};

let input;
let suggestion;

Expand All @@ -459,10 +459,10 @@ class PermissionBuilder extends React.Component {
PGTypes.geography.includes(valueType)
) {
input = inputBox();
suggestion = jsonSuggestion();
suggestion = jsonSuggestion(dispatchInput);
} else {
input = wrapDoubleQuotes(inputBox());
suggestion = sessionVariableSuggestion();
suggestion = sessionVariableSuggestion(dispatchInput);
}

return (
Expand All @@ -473,25 +473,38 @@ class PermissionBuilder extends React.Component {
};

const renderValueArray = (dispatchFunc, values, prefix, valueType) => {
const _inputArray = [];
const dispatchInput = val => {
dispatchFunc({ prefix: prefix, value: val });
};

const inputArray = [];

(values || []).concat(['']).map((val, i) => {
const input = renderValue(
dispatchFunc,
val,
addToPrefix(prefix, i),
valueType
);
_inputArray.push(input);
inputArray.push(input);
});

const unselectedElements = [(values || []).length];

return (
const _inputArray = (
<QueryBuilderJson
element={_inputArray}
element={inputArray}
unselectedElements={unselectedElements}
/>
);

const _suggestion = sessionVariableSuggestion(dispatchInput);

return (
<span>
{_inputArray} {_suggestion}
</span>
);
};

const renderOperatorExp = (dispatchFunc, expression, prefix, valueType) => {
Expand Down Expand Up @@ -529,7 +542,10 @@ class PermissionBuilder extends React.Component {

let _valueInput = '';
if (operator) {
if (isArrayTypeColumnOperator(operator)) {
if (
isArrayTypeColumnOperator(operator) &&
operationValue instanceof Array
) {
_valueInput = renderValueArray(
dispatchFunc,
operationValue,
Expand Down

0 comments on commit 20202f5

Please sign in to comment.