Skip to content

Commit 1b52dee

Browse files
committed
[IMP] Data filter: Trim whitespace
[Data filter] Trim whitespace and don't bother of caps vs low case when filtering Task:5375214
1 parent 04b8575 commit 1b52dee

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/o-spreadsheet-engine/src/helpers/text_helper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,11 @@ export function toLowerCase(str: string | undefined): string {
297297
return str ? str.toLowerCase() : "";
298298
}
299299

300+
/** Removes whitespace from both ends of the string. If the string is undefined, return an empty string */
301+
export function trim(str: string | undefined): string {
302+
return str ? str.trim() : "";
303+
}
304+
300305
/**
301306
* Extract the fontSize from a context font string
302307
* @param font The (context) font string to parse

src/components/filters/filter_menu_value_list/filter_menu_value_list.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SpreadsheetChildEnv } from "@odoo/o-spreadsheet-engine/types/spreadsheet_env";
22
import { Component, onWillUpdateProps, useRef, useState } from "@odoo/owl";
3-
import { deepEquals, positions, toLowerCase } from "../../../helpers";
3+
import { deepEquals, positions, toLowerCase, trim } from "../../../helpers";
44
import { fuzzyLookup } from "../../../helpers/search";
55
import { Position } from "../../../types";
66
import { FilterMenuValueItem } from "../filter_menu_item/filter_menu_value_item";
@@ -76,12 +76,12 @@ export class FilterMenuValueList extends Component<Props, SpreadsheetChildEnv> {
7676

7777
const cellValues = cells.map((val) => val.cellValue);
7878
const filterValues = filterValue?.filterType === "values" ? filterValue.hiddenValues : [];
79-
const normalizedFilteredValues = new Set(filterValues.map(toLowerCase));
79+
const normalizedFilteredValues = new Set(filterValues.map(toLowerCase).map(trim));
8080

8181
const set = new Set<string>();
8282
const values: (Value & { normalizedValue: string })[] = [];
8383
const addValue = (value: string) => {
84-
const normalizedValue = toLowerCase(value);
84+
const normalizedValue = trim(toLowerCase(value));
8585
if (!set.has(normalizedValue)) {
8686
values.push({
8787
string: value || "",

0 commit comments

Comments
 (0)