Skip to content

Commit 2e88ee6

Browse files
committed
Implement regex search for use when searching for member numbers.
1 parent 2eeea1d commit 2e88ee6

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

admin/src/Components/MessageForm.tsx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const MessageForm = ({
8787
options: (MemberOption | GroupOption | CombinedOption)[],
8888
) => void,
8989
) => {
90-
const intListMatch = inputValue.match(/^\s*(\d+[\s,]*)+\s*$/);
90+
const intListMatch = inputValue.match(/^\s*(\d\d\d\d+[\s,]*)+\s*$/);
9191
if (intListMatch) {
9292
const ids = inputValue
9393
.split(/[\s,]+/)
@@ -97,21 +97,27 @@ const MessageForm = ({
9797
get({
9898
url: "/membership/member",
9999
params: {
100-
search: ids.join(" "),
100+
search: ids.join("|"),
101101
search_column: "member_number",
102102
sort_by: "member_number",
103103
sort_order: "asc",
104+
regex: true,
104105
},
105106
}).then(({ data: members }: { data: Member[] }) => {
107+
members = members.filter(m => !recipients.some(r => r.id === m.member_id));
106108
const options = members.map(memberOption);
107-
callback([
108-
{
109-
type: "combined",
110-
label: `${options.map((o) => o.label).join(", ")}`,
111-
value: "combined-" + ids.join("-"),
112-
inner: options,
113-
},
114-
]);
109+
if (options.length > 0) {
110+
callback([
111+
{
112+
type: "combined",
113+
label: `${options.map((o) => o.label).join(", ")}`,
114+
value: "combined-" + ids.join("-"),
115+
inner: options,
116+
},
117+
]);
118+
} else {
119+
callback([]);
120+
}
115121
});
116122
return;
117123
}

api/src/service/entity.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def list(
218218
related_entity_id=None,
219219
include_deleted=Arg(boolean, required=False),
220220
search_column=Arg(str, required=False),
221+
regex=Arg(boolean, required=False),
221222
):
222223
query = db_session.query(self.model)
223224

@@ -241,7 +242,11 @@ def list(
241242

242243
if search:
243244
for term in search.split():
244-
expression = or_(*[self.columns[column_name].like(f"%{term}%") for column_name in search_columns])
245+
if regex:
246+
expression = or_(*[self.columns[column_name].regexp_match(term) for column_name in search_columns])
247+
else:
248+
expression = or_(*[self.columns[column_name].like(f"%{term}%") for column_name in search_columns])
249+
245250
query = query.filter(expression)
246251

247252
if expand:

0 commit comments

Comments
 (0)