Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var filter = essence.getEffectiveFilter(timekeeper);
// don't remove filter if time
if (unfolded && dataCube.isMandatoryFilter(dimension.expression)) {
filter = filter.remove(dimension.expression);
}
filter = filter.setExclusionforDimension(false, dimension);
var filterExpression = filter.toExpression();
if (!unfolded && colors && colors.dimension === dimension.name && colors.values) {
filterExpression = filterExpression.and(dimension.expression.in(colors.toSet()));
}
if (searchText) {
filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), 'ignoreCase'));
}
var query: any = $('main')
.filter(filterExpression);
var sortExpression: Expression = null;
if (dimension.canBucketByDefault()) {
const dimensionExpression = dimension.expression as RefExpression;
const attributeName = dimensionExpression.name;
const filterSelection: FilterSelection = essence.filter.getSelection(dimensionExpression);
if (!selectedGranularity) {
if (filterSelection) {
var range = dimension.kind === 'time' ? essence.evaluateSelection(filterSelection as Expression, timekeeper) : (filterSelection as Expression).getLiteralValue().extent();
export function stringFilterOptionsQuery({ essence, timekeeper, limit, dimension, searchText }: QueryParams): Expression {
const { dataCube } = essence;
const nativeCount = dataCube.getMeasure("count");
const $main = $("main");
const measureExpression = nativeCount ? nativeCount.expression : $main.count();
const filter = essence.getEffectiveFilter(timekeeper, { unfilterDimension: dimension }).toExpression(dataCube);
const filterWithSearch = searchText ? filter.and(dimension.expression.contains(r(searchText), "ignoreCase")) : filter;
return $main
.filter(filterWithSearch)
.split(dimension.expression, dimension.name)
.apply("MEASURE", measureExpression)
.sort($("MEASURE"), SortExpression.DESCENDING)
.limit(limit);
}
fetchData(essence: Essence, dimension: Dimension): void {
var { searchText } = this.state;
var { dataSource } = essence;
var nativeCount = dataSource.getMeasure('count');
var measureExpression = nativeCount ? nativeCount.expression : $('main').count();
var filterExpression = essence.getEffectiveFilter(null, dimension).toExpression();
if (searchText) {
filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), 'ignoreCase'));
}
var query = $('main')
.filter(filterExpression)
.split(dimension.expression, SEGMENT)
.apply('MEASURE', measureExpression)
.sort($('MEASURE'), SortAction.DESCENDING)
.limit(TOP_N + 1);
this.setState({
loading: true,
fetchQueued: false
});
dataSource.executor(query)
.then(
(dataset) => {
if (unfolded && dimension !== essence.getTimeDimension()) {
filter = filter.removeClause(dimension.name);
}
filter = filter.setExclusionForDimension(false, dimension);
let filterExpression = filter.toExpression(dataCube);
const shouldFoldRows = !unfolded && foldable && colors && colors.dimension === dimension.name && colors.values;
if (shouldFoldRows) {
filterExpression = filterExpression.and(dimension.expression.in(colors.toSet()));
}
if (searchText) {
filterExpression = filterExpression.and(dimension.expression.contains(r(searchText), "ignoreCase"));
}
let query: any = $("main")
.filter(filterExpression);
let sortExpression: Expression = null;
if (dimension.canBucketByDefault()) {
if (!selectedGranularity) {
selectedGranularity = this.bucketForDimension(dimension);
}
this.setState({ selectedGranularity });
query = query.split($(dimension.name).performAction(bucketToAction(selectedGranularity)), dimension.name);
case StringFilterAction.CONTAINS:
stringExp = expression.contains(r(values.first()));
break;
case StringFilterAction.IN:
stringExp = expression.overlap(r(values.toArray()));
break;
case StringFilterAction.MATCH:
stringExp = expression.match(values.first());
break;
}
return not ? stringExp.not() : stringExp;
}
case FilterTypes.FIXED_TIME: {
const values = (clause as FixedTimeFilterClause).values.toArray();
const elements = values.map(value => new TimeRange(value));
return expression.overlap(r(new PlywoodSet({ elements, setType: "TIME_RANGE" })));
}
case FilterTypes.RELATIVE_TIME: {
throw new Error("Can't call toExpression on RelativeFilterClause. Evaluate clause first");
}
}
}
constructFilter(): Filter {
var { dimension, filterMode, onClauseChange, searchText } = this.props;
var { expression } = dimension;
var clause: FilterClause = null;
if (searchText) {
if (filterMode === Filter.REGEX) {
clause = new FilterClause({
expression,
selection: searchText,
action: 'match'
});
} else if (filterMode === Filter.CONTAINS) {
clause = new FilterClause({
expression,
selection: r(searchText),
action: 'contains'
});
}
}
return onClauseChange(clause);
}
export function toExpression(clause: FilterClause, { expression }: Dimension): Expression {
const { type } = clause;
switch (type) {
case FilterTypes.BOOLEAN: {
const { not, values } = clause as BooleanFilterClause;
const boolExp = expression.overlap(r(values.toArray()));
return not ? boolExp.not() : boolExp;
}
case FilterTypes.NUMBER: {
const { not, values } = clause as NumberFilterClause;
const elements = values.toArray().map(range => new PlywoodNumberRange(range));
const set = new PlywoodSet({ elements, setType: "NUMBER_RANGE" });
const numExp = expression.overlap(r(set));
return not ? numExp.not() : numExp;
}
case FilterTypes.STRING: {
const { not, action, values } = clause as StringFilterClause;
let stringExp: Expression = null;
switch (action) {
case StringFilterAction.CONTAINS:
stringExp = expression.contains(r(values.first()));
break;