Skip to content

Commit

Permalink
Fix #318
Browse files Browse the repository at this point in the history
Also: a few improvements to the filter dialog css and some refactoring of the filter dialog code.
  • Loading branch information
rpbouman committed Dec 29, 2024
1 parent 23b5b6b commit 07665ea
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 144 deletions.
5 changes: 3 additions & 2 deletions src/AttributeUi/AttributeUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class AttributeUi {
folder: 'map operations',
expressionTemplate: "unnest( map_entries( ${columnExpression} ) )",
unnestingFunction: 'unnest',
hasEntryDataType: true
hasEntryArrayDataType: true
},
"entry count": {
folder: 'map operations',
Expand All @@ -414,7 +414,8 @@ class AttributeUi {
},
"keyset": {
folder: 'map operations',
expressionTemplate: "list_sort( map_keys( ${columnExpression} ) )"
expressionTemplate: "list_sort( map_keys( ${columnExpression} ) )",
hasKeyArrayDataType: true
}
};

Expand Down
59 changes: 30 additions & 29 deletions src/DataSet/SqlQueryGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,31 +96,18 @@ class SqlQueryGenerator {
}

static #getConditionForFilterItems(filterItems, tableAlias){
return filterItems
.filter(function(filterItem){
var filter = filterItem.filter;
if (!filter) {
return false;
}

var values = filter.values;
if (!values){
return false;
}

var keys = Object.keys(values);
keys = keys.filter(function(key){
var valueObject = values[key];
return valueObject.enabled !== false;
});
if (keys.length === 0) {
return false;
}
return true;
})
.map(function(filterItem){
// cull filter items that have incomplete filters
// and filters without any enabled filter values.
filterItems = filterItems.filter(function(filterItem){
return QueryAxisItem.isFilterItemEffective(filterItem);
});

// create SQL conditions for filter items
var filterConditions = filterItems.map(function(filterItem){
var conditionSql;
var queryAxisItems = filterItem.queryAxisItems;
// this happens when the cellset generates a filter item to push down tuples,
// see https://github.com/rpbouman/huey/issues/134
if (queryAxisItems) {
var fields = filterItem.fields;
var columns = queryAxisItems.map(function(queryAxisItem){
Expand All @@ -142,8 +129,13 @@ class SqlQueryGenerator {
conditionSql = QueryAxisItem.getFilterConditionSql(filterItem, tableAlias);
}
return conditionSql;
})
.join('\nAND ');
});

// combine SQL conditions
var filterCondition = filterConditions.join('\nAND ');

// done.
return filterCondition;
}

static #transformFilterItems(
Expand Down Expand Up @@ -217,7 +209,12 @@ class SqlQueryGenerator {
}
else {
delete filterAxisItem.memberExpressionPath;
delete filterAxisItem.derivation;
if (filterAxisItem.derivation) {
var derivationInfo = AttributeUi.getDerivationInfo(filterAxisItem.derivation);
if (derivationInfo.unnestingFunction) {
delete filterAxisItem.derivation;
}
}
}

// now we have to check whether the remaining expressionpath of the filter item still contains unnesting expressions.
Expand Down Expand Up @@ -672,10 +669,14 @@ class SqlQueryGenerator {

static #generateWhereClause(cte, sql){
var filterAxisItems = cte.filters;
if (filterAxisItems && filterAxisItems.length){
var whereCondition = SqlQueryGenerator.#getConditionForFilterItems(filterAxisItems, cte.alias);
sql.push(`WHERE ${whereCondition}`);
if (!filterAxisItems) {
return;
}
if (!filterAxisItems.length){
return;
}
var whereCondition = SqlQueryGenerator.#getConditionForFilterItems(filterAxisItems, cte.alias);
sql.push(`WHERE ${whereCondition}`);
}

static getSqlSelectStatementForAxisItems(options){
Expand Down
39 changes: 38 additions & 1 deletion src/FilterUi/FilterUi.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ dialog#filterDialog {

> select {
flex-grow: 1;
width: 100%;
width: calc( 100% - 10px );
height: 100%;
}
}
Expand Down Expand Up @@ -242,6 +242,8 @@ dialog#filterDialog:has( > header > select#filterType > option[value=notbetween]
dialog#filterDialog:has( > header > select#filterType > option[value=between]:checked ) > section > section > div:has( label[for=filterValueList] ),
dialog#filterDialog:has( > header > select#filterType > option[value=notbetween]:checked ) > section > section > div:has( label[for=filterValueList] ){
flex-grow: 0;
max-width: calc( 100% - 86px );
z-index: 1;
}

dialog#filterDialog:has( > header > select#filterType > option[value=between]:checked ) > section > section > div:has( label[for=filterValueList] ) > #filterValueList,
Expand Down Expand Up @@ -269,3 +271,38 @@ dialog#filterDialog:has( > header > select#filterType > option[value=notbetween]
#filterValueList, #toFilterValueList {
}

/*
Operators LIKE and NOT LIKE are hidden by default
*/
dialog#filterDialog > header[role=toolbar] > select#filterType > option[value=like],
dialog#filterDialog > header[role=toolbar] > select#filterType > option[value=notlike] {
display: none;
}

/*
Operators LIKE and NOT LIKE are available when the filter item data type is VARCHAR
*/
dialog#filterDialog[data-query-model-item-datatype='VARCHAR'] > header[role=toolbar] > select#filterType > option[value=like],
dialog#filterDialog[data-query-model-item-datatype='VARCHAR'] > header[role=toolbar] > select#filterType > option[value=notlike] {
display: block;
}

/*
LIST/ARRAY operators hasany, hasall, nothasany, nothasall are hidden by default
*/
dialog#filterDialog > header[role=toolbar] > select#filterType > option[value=hasany],
dialog#filterDialog > header[role=toolbar] > select#filterType > option[value=hasall],
dialog#filterDialog > header[role=toolbar] > select#filterType > option[value=nothasany],
dialog#filterDialog > header[role=toolbar] > select#filterType > option[value=nothasall] {
display: none;
}

/*
LIST/ARRAY operators hasany, hasall, nothasany, nothasall are available when the filter axis item data type is an array type.
*/
dialog#filterDialog[data-query-model-item-datatype$='[]'] > header[role=toolbar] > select#filterType > option[value=hasany],
dialog#filterDialog[data-query-model-item-datatype$='[]'] > header[role=toolbar] > select#filterType > option[value=hasall],
dialog#filterDialog[data-query-model-item-datatype$='[]'] > header[role=toolbar] > select#filterType > option[value=nothasany],
dialog#filterDialog[data-query-model-item-datatype$='[]'] > header[role=toolbar] > select#filterType > option[value=nothasall] {
display: block;
}
Loading

0 comments on commit 07665ea

Please sign in to comment.