@adaptabletools/adaptable-cjs
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
67 lines (66 loc) • 4.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const react_1 = require("react");
const BaseEditorInput_1 = require("./BaseEditorInput");
const editorButtonsSearch_1 = require("./editorButtonsSearch");
const EditorContext_1 = require("./EditorContext");
const StringExtensions_1 = tslib_1.__importDefault(require("../../Utilities/Extensions/StringExtensions"));
const editorButtonsAggregatedScalar_1 = require("./editorButtonsAggregatedScalar");
const aggregatedScalarExpressionFunctions_1 = require("../../Utilities/ExpressionFunctions/aggregatedScalarExpressionFunctions");
const editorButtonsCumulativeAggregatedScalar_1 = require("./editorButtonsCumulativeAggregatedScalar");
const editorButtonsQuantileAggregatedScalar_1 = require("./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([
// we cannot have a hardcodede set of functions,
// we need to allow custom expressions
...aggregatedScalarExpressionFunctions_1.cumulativeAggregatedExpressionFunctions,
...aggregatedScalarExpressionFunctions_1.quantileAggregatedExpressionFunctions,
]);
filteredCollection = Object.keys(availableAggregatedExpressionFunctions).filter((key) =>
// need to allow standard ones
aggregatedScalarExpressionFunctions_1.cumulativeAggregatedExpressionFunctions.includes(key) ||
// and anything else that is not cumul or quantile
!excludeSet.has(key));
}
else {
const includeExpressionFunctions = type === 'cumulativeAggregatedScalar'
? aggregatedScalarExpressionFunctions_1.cumulativeAggregatedExpressionFunctions
: aggregatedScalarExpressionFunctions_1.quantileAggregatedExpressionFunctions;
filteredCollection = Object.keys(availableAggregatedExpressionFunctions).filter((key) => includeExpressionFunctions.includes(key));
}
return filteredCollection.reduce((obj, key) => {
obj[key] = availableAggregatedExpressionFunctions[key];
return obj;
}, {});
};
const expressionFunctions = (0, react_1.useMemo)(() => {
return props.type === 'aggregatedScalar' ||
props.type === 'cumulativeAggregatedScalar' ||
props.type === 'quantileAggregatedScalar'
? getFilteredAggregatedExpressionFunctions(moduleExpressionFunctions.aggregatedScalarFunctions, props.type)
: {
...moduleExpressionFunctions.booleanFunctions,
...moduleExpressionFunctions.scalarFunctions,
};
}, [props.type]);
const { setSelectedFunction } = (0, EditorContext_1.useExpressionEditor)();
const queryName = `${StringExtensions_1.default.CapitaliseFirstLetter(props.type)}Query`;
return (React.createElement(BaseEditorInput_1.BaseEditorInput, { type: 'main', value: props.value, placeholder: `Create ${queryName}`, onChange: props.onChange, onSelectedFunctionChange: setSelectedFunction, expressionFunctions: expressionFunctions, editorButtons: props.type === 'aggregatedScalar'
? editorButtonsAggregatedScalar_1.editorButtonsAggregatedScalar
: props.type === 'cumulativeAggregatedScalar'
? editorButtonsCumulativeAggregatedScalar_1.editorButtonsCumulativeAggregatedScalar
: props.type === 'quantileAggregatedScalar'
? editorButtonsQuantileAggregatedScalar_1.editorButtonsQuantileAggregatedScalar
: editorButtonsSearch_1.editorButtonsSearch, testData: props.testData, isFullExpression: props.isFullExpression, hideResultPreview: props.type === 'aggregatedScalar' ||
props.type === 'cumulativeAggregatedScalar' ||
props.type === 'quantileAggregatedScalar', api: props.api }));
}
exports.default = EditorInput;