@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
85 lines (84 loc) • 4.57 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo } from 'react';
import { BaseEditorInput } from './BaseEditorInput';
import { editorButtonsSearch } from './editorButtonsSearch';
import { useExpressionEditor } from './EditorContext';
import { editorButtonsAggregatedScalar } from './editorButtonsAggregatedScalar';
import { cumulativeAggregatedExpressionFunctions, quantileAggregatedExpressionFunctions, } from '../../Utilities/ExpressionFunctions/aggregatedScalarExpressionFunctions';
import { editorButtonsCumulativeAggregatedScalar } from './editorButtonsCumulativeAggregatedScalar';
import { editorButtonsQuantileAggregatedScalar } from './editorButtonsQuantileAggregatedScalar';
function EditorInput(props) {
const moduleExpressionFunctions = props.api.internalApi
.getQueryLanguageService()
.getModuleExpressionFunctionsMap(props.module);
const getFilteredAggregatedExpressionFunctions = (availableAggregatedExpressionFunctions, type) => {
let filteredCollection = [];
if (type === 'aggregatedScalar') {
const excludeSet = new Set([
...cumulativeAggregatedExpressionFunctions,
...quantileAggregatedExpressionFunctions,
]);
filteredCollection = Object.keys(availableAggregatedExpressionFunctions).filter((key) => cumulativeAggregatedExpressionFunctions.includes(key) ||
!excludeSet.has(key));
}
else {
const includeExpressionFunctions = type === 'cumulativeAggregatedScalar'
? cumulativeAggregatedExpressionFunctions
: quantileAggregatedExpressionFunctions;
filteredCollection = Object.keys(availableAggregatedExpressionFunctions).filter((key) => includeExpressionFunctions.includes(key));
}
return filteredCollection.reduce((obj, key) => {
obj[key] = availableAggregatedExpressionFunctions[key];
return obj;
}, {});
};
const expressionFunctions = useMemo(() => {
if (props.type === 'aggregatedScalar' ||
props.type === 'cumulativeAggregatedScalar' ||
props.type === 'quantileAggregatedScalar') {
return getFilteredAggregatedExpressionFunctions(moduleExpressionFunctions.aggregatedScalarFunctions, props.type);
}
let booleanAndScalarFunctions = {
...moduleExpressionFunctions.booleanFunctions,
...moduleExpressionFunctions.scalarFunctions,
};
if (!props.columnScope) {
booleanAndScalarFunctions = Object.keys(booleanAndScalarFunctions)
.filter((key) => key !== '$SCOPE')
.reduce((obj, key) => {
obj[key] = booleanAndScalarFunctions[key];
return obj;
}, {});
}
return booleanAndScalarFunctions;
}, [props.type, props.columnScope]);
const { setSelectedFunction } = useExpressionEditor();
let queryName;
switch (props.type) {
case 'boolean':
queryName = 'Create an Expression that returns true / false';
break;
case 'scalar':
queryName = "Create an Expression that returns a single value of any type";
break;
case 'aggregatedScalar':
queryName = "Create an Expression that evaluates multiple rows and returns a value of any type";
break;
case 'cumulativeAggregatedScalar':
queryName = "Create a Cumulative Expression";
break;
case 'quantileAggregatedScalar':
queryName = "Create a Quantile Expression";
break;
}
return (_jsx(BaseEditorInput, { type: 'main', value: props.value, placeholder: queryName, onChange: props.onChange, onSelectedFunctionChange: setSelectedFunction, expressionFunctions: expressionFunctions, editorButtons: props.type === 'aggregatedScalar'
? editorButtonsAggregatedScalar
: props.type === 'cumulativeAggregatedScalar'
? editorButtonsCumulativeAggregatedScalar
: props.type === 'quantileAggregatedScalar'
? editorButtonsQuantileAggregatedScalar
: editorButtonsSearch, testData: props.testData, isFullExpression: props.isFullExpression, hideResultPreview: props.type === 'aggregatedScalar' ||
props.type === 'cumulativeAggregatedScalar' ||
props.type === 'quantileAggregatedScalar', api: props.api, columnScope: props.columnScope }));
}
export default EditorInput;