Skip to content

Commit 791cdcf

Browse files
authored
[ReviewEntries] Use whitespace filter for non-empty text (#3715)
1 parent f08a342 commit 791cdcf

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

docs/user_guide/docs/goals.es.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ There are icons at the top of each column to
2828

2929
In a column with predominantly text content (Vernacular, Glosses, Note, or Flag), you can sort alphabetically or filter
3030
with a text search. By default, the text search is a fuzzy match: it is not case sensitive and it allows for one or two
31-
typos. If you want exact text matches, use quotes around your filter.
31+
typos. If you want exact text matches, use quotes around your filter. To show all entries with non-empty text in the
32+
column, type a space for your filter.
3233

3334
In the Number of Senses column or Pronunciations column, you can sort or filter by the number of senses or recordings
3435
that entries have. In the Pronunciations column, you can also filter by speaker name.

docs/user_guide/docs/goals.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ There are icons at the top of each column to
2727

2828
In a column with predominantly text content (Vernacular, Glosses, Note, or Flag), you can sort alphabetically or filter
2929
with a text search. By default, the text search is a fuzzy match: it is not case sensitive and it allows for one or two
30-
typos. If you want exact text matches, use quotes around your filter.
30+
typos. If you want exact text matches, use quotes around your filter. To show all entries with non-empty text in the
31+
column, type a space for your filter.
3132

3233
In the Number of Senses column or Pronunciations column, you can sort or filter by the number of senses or recordings
3334
that entries have. In the Pronunciations column, you can also filter by speaker name.

docs/user_guide/docs/goals.zh.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ There are icons at the top of each column to
2727

2828
In a column with predominantly text content (Vernacular, Glosses, Note, or Flag), you can sort alphabetically or filter
2929
with a text search. By default, the text search is a fuzzy match: it is not case sensitive and it allows for one or two
30-
typos. If you want exact text matches, use quotes around your filter.
30+
typos. If you want exact text matches, use quotes around your filter. To show all entries with non-empty text in the
31+
column, type a space for your filter.
3132

3233
In the Number of Senses column or Pronunciations column, you can sort or filter by the number of senses or recordings
3334
that entries have. In the Pronunciations column, you can also filter by speaker name.

src/goals/ReviewEntries/ReviewEntriesTable/filterFn.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export function fuzzyContains(value: string, filter: string): boolean {
3636
/** Check if string matches filter.
3737
* If filter quoted, exact match. Otherwise, fuzzy match. */
3838
export function matchesFilter(value: string, filter: string): boolean {
39+
if (filter && !filter.trim()) {
40+
// Whitespace-only filter always matches a non-empty value.
41+
return !!value;
42+
}
43+
3944
filter = filter.trim();
4045
return isQuoted(filter)
4146
? value.includes(filter.substring(1, filter.length - 1).trim())

src/goals/ReviewEntries/ReviewEntriesTable/tests/filterFn.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ describe("filterFn", () => {
6969
const filterWrongCase = "HELLO";
7070
const filterExact = "Hello";
7171

72+
it("whitespace: matches non-empty value", () => {
73+
expect(ff.matchesFilter(value, " ")).toBeTruthy();
74+
expect(ff.matchesFilter("", " ")).toBeFalsy();
75+
});
76+
7277
it("unquoted: trims whitespace, fuzzy match", () => {
7378
expect(ff.matchesFilter(value, "goodbye")).toBeFalsy();
7479
expect(ff.matchesFilter(value, ` ${filterWithTypo}`)).toBeTruthy();
@@ -89,6 +94,12 @@ describe("filterFn", () => {
8994
mockGetValue.mockReturnValue("Hello world!");
9095
});
9196

97+
it("whitespace: matches non-empty value", () => {
98+
expect(filterFn(mockRow, mockId, " ")).toBeTruthy();
99+
mockGetValue.mockReturnValueOnce("");
100+
expect(filterFn(mockRow, mockId, " ")).toBeFalsy();
101+
});
102+
92103
it("unquoted: trims whitespace, fuzzy match", () => {
93104
expect(filterFn(mockRow, mockId, "goodbye")).toBeFalsy();
94105
expect(filterFn(mockRow, mockId, " H3LLO")).toBeTruthy();
@@ -110,6 +121,14 @@ describe("filterFn", () => {
110121
]);
111122
});
112123

124+
it("whitespace: matches non-empty definition text", () => {
125+
expect(filterFn(mockRow, mockId, " ")).toBeTruthy();
126+
mockGetValue.mockReturnValueOnce([newDefinition()]);
127+
expect(filterFn(mockRow, mockId, " ")).toBeFalsy();
128+
mockGetValue.mockReturnValueOnce([]);
129+
expect(filterFn(mockRow, mockId, " ")).toBeFalsy();
130+
});
131+
113132
it("unquoted: trims whitespace, fuzzy match", () => {
114133
expect(filterFn(mockRow, mockId, "earth")).toBeFalsy();
115134
expect(filterFn(mockRow, mockId, " wrld\t")).toBeTruthy();
@@ -128,6 +147,14 @@ describe("filterFn", () => {
128147
mockGetValue.mockReturnValue([newGloss("hello"), newGloss("WORLD")]);
129148
});
130149

150+
it("whitespace: matches non-empty gloss text", () => {
151+
expect(filterFn(mockRow, mockId, " ")).toBeTruthy();
152+
mockGetValue.mockReturnValueOnce([newGloss()]);
153+
expect(filterFn(mockRow, mockId, " ")).toBeFalsy();
154+
mockGetValue.mockReturnValueOnce([]);
155+
expect(filterFn(mockRow, mockId, " ")).toBeFalsy();
156+
});
157+
131158
it("unquoted: trims whitespace, fuzzy match", () => {
132159
expect(filterFn(mockRow, mockId, "earth")).toBeFalsy();
133160
expect(filterFn(mockRow, mockId, " wrld\t")).toBeTruthy();
@@ -223,6 +250,12 @@ describe("filterFn", () => {
223250
mockGetValue.mockReturnValue(newFlag("Hello world!"));
224251
});
225252

253+
it("whitespace: matches non-empty flag text", () => {
254+
expect(filterFn(mockRow, mockId, " ")).toBeTruthy();
255+
mockGetValue.mockReturnValueOnce(newFlag());
256+
expect(filterFn(mockRow, mockId, " ")).toBeFalsy();
257+
});
258+
226259
it("unquoted: trims whitespace, fuzzy match", () => {
227260
expect(filterFn(mockRow, mockId, "goodbye")).toBeFalsy();
228261
expect(filterFn(mockRow, mockId, " H3LLO")).toBeTruthy();

0 commit comments

Comments
 (0)