Skip to content

Commit

Permalink
Merge pull request #356 from OutSystems/ROU-4429
Browse files Browse the repository at this point in the history
ROU-4429: Fixing APIs `FilterByCondition` & `FilterByValue` to work with checkbox column
  • Loading branch information
rugoncalves authored Jul 6, 2023
2 parents 1ab85d9 + f3cc228 commit 2157d94
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
35 changes: 26 additions & 9 deletions src/Providers/DataGrid/Wijmo/Features/ColumnFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,33 @@ namespace Providers.DataGrid.Wijmo.Feature {
);
}

/**
* Prepares the condition value to be used in the condition filter.
*
* @private
* @param {OSFramework.DataGrid.Enum.ColumnType} columnType will be used to determine the type of parse to be done to the value.
* @param {Helper.FilterFactory.WijmoFilterConditionValue} conditionValue value to be parsed
* @return {*} {Helper.FilterFactory.WijmoFilterConditionValue} value parsed according to the column type
* @memberof ColumnFilter
*/
private _getFilterConditionValue(
columnType: OSFramework.DataGrid.Enum.ColumnType,
conditionValue: Helper.FilterFactory.WijmoFilterConditionValue
) {
): Helper.FilterFactory.WijmoFilterConditionValue {
let _formattedValue: Helper.FilterFactory.WijmoFilterConditionValue;

switch (columnType) {
case OSFramework.DataGrid.Enum.ColumnType.Checkbox:
_formattedValue = (conditionValue as string) === 'True';
break;
case OSFramework.DataGrid.Enum.ColumnType.Number:
_formattedValue = parseFloat(conditionValue as string);
break;
case OSFramework.DataGrid.Enum.ColumnType.Date:
case OSFramework.DataGrid.Enum.ColumnType.DateTime:
_formattedValue = new Date(conditionValue);
_formattedValue = new Date(
conditionValue as string | number
);
break;
default:
_formattedValue = conditionValue;
Expand Down Expand Up @@ -202,20 +216,23 @@ namespace Providers.DataGrid.Wijmo.Feature {
public byValue(columnId: string, values: Array<string>): void {
const column = this._grid.getColumn(columnId);
if (column) {
const isColumnTypeCheckbox =
column.columnType ===
OSFramework.DataGrid.Enum.ColumnType.Checkbox;
const columnFilter = this._filter.getColumnFilter(
column.config.binding
).valueFilter;

// we receive values as an array ["Brazil", "Portugal"], but wijmo expects an object
// eg.: {Brazil: true, Portugal: true}. So let's transform this to the desired input
columnFilter.showValues = values
.map((val) => {
if (val === null) return '';
return val;
columnFilter.showValues = Object.fromEntries(
values.map((val) => {
if (val === null) return [];
if (isColumnTypeCheckbox)
return [val.toLowerCase(), true];
return [val, true];
})
.reduce((obj, cur) => {
return { ...obj, [cur]: true };
}, {});
);

this._filter.apply();
// trigger event
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/DataGrid/Wijmo/Helper/FilterFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Providers.DataGrid.Wijmo.Helper.FilterFactory {
/**
* The type below represents the wijmo filter condition value
*/
export type WijmoFilterConditionValue = number | string | Date;
export type WijmoFilterConditionValue = number | string | Date | boolean;

/**
* Function that creates a condition for for the filter to send to OutSystems.
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "amd", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
"allowJs": false, /* Allow javascript files to be compiled. */
Expand Down

0 comments on commit 2157d94

Please sign in to comment.