Merge pull request #352 from incubateur-territoires/filter-search-insentive-diacritics

Add normalizetext to filter search
This commit is contained in:
jarek 2022-11-17 09:55:13 +01:00 committed by GitHub
commit f0e0714a2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import { ColumnFilter } from "app/client/models/ColumnFilter"; import { ColumnFilter } from "app/client/models/ColumnFilter";
import { CellValue } from "app/plugin/GristData"; import { CellValue } from "app/plugin/GristData";
import { normalizeText } from "app/client/lib/ACIndex";
import { Computed, Disposable, Observable } from "grainjs"; import { Computed, Disposable, Observable } from "grainjs";
import escapeRegExp = require("lodash/escapeRegExp"); import escapeRegExp = require("lodash/escapeRegExp");
import isNull = require("lodash/isNull"); import isNull = require("lodash/isNull");
@ -31,11 +32,11 @@ export class ColumnFilterMenuModel extends Disposable {
// computes a set of all keys that matches the search text. // computes a set of all keys that matches the search text.
public readonly filterSet = Computed.create(this, this.searchValue, (_use, searchValue) => { public readonly filterSet = Computed.create(this, this.searchValue, (_use, searchValue) => {
const searchRegex = new RegExp(escapeRegExp(searchValue), 'i'); const searchRegex = new RegExp(escapeRegExp(normalizeText(searchValue)), 'i');
const showAllOptions = ['Bool', 'Choice', 'ChoiceList'].includes(this.columnFilter.columnType); const showAllOptions = ['Bool', 'Choice', 'ChoiceList'].includes(this.columnFilter.columnType);
return new Set( return new Set(
this._valueCount this._valueCount
.filter(([_, {label, count}]) => (showAllOptions ? true : count) && searchRegex.test(label)) .filter(([_, {label, count}]) => (showAllOptions ? true : count) && searchRegex.test(normalizeText(label)))
.map(([key]) => key) .map(([key]) => key)
); );
}); });