Skip to content

Commit 603a5a6

Browse files
committed
ntee code
1 parent 8307b3e commit 603a5a6

File tree

3 files changed

+48
-20
lines changed

3 files changed

+48
-20
lines changed

src/pages/nonprofit-outreach/api.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Filter {
4343
return vals;
4444
}
4545

46-
set_opts<T extends string>(kv: { [key in T]: T }) {
46+
opts<T extends string>(kv: { [key in T]: T }) {
4747
const [[k, v]] = Object.entries(kv);
4848
if (!v) return;
4949
const opts = this.extract_blank_exists(k, v as string);
@@ -52,7 +52,7 @@ class Filter {
5252
this.filter.$and.push({ [k]: { $in: opts } });
5353
}
5454
}
55-
set_texts<T extends string>(kv: { [key in T]: T }) {
55+
texts<T extends string>(kv: { [key in T]: T }) {
5656
const [[k, v]] = Object.entries(kv);
5757
if (!v) return;
5858
const texts = this.extract_blank_exists(k, v as string);
@@ -64,6 +64,17 @@ class Filter {
6464
});
6565
}
6666
}
67+
starts_with<T extends string>(kv: { [key in T]: T }) {
68+
const [[k, v]] = Object.entries(kv);
69+
if (!v) return;
70+
const starts = this.extract_blank_exists(k, v as string);
71+
if (starts.length > 0) {
72+
this.filter.$and ||= [];
73+
this.filter.$and.push({
74+
$and: starts.map((t) => ({ [k]: { $regex: `^${t}`, $options: "i" } })),
75+
});
76+
}
77+
}
6778

6879
get all() {
6980
return this.filter;
@@ -94,22 +105,22 @@ export const loader: LoaderFunction = async ({ request }) => {
94105
} = Object.fromEntries(url.searchParams.entries());
95106

96107
const filter = new Filter();
97-
filter.set_opts({ asset_code });
98-
filter.set_opts({ income_code });
99-
filter.set_opts({ website_url });
100-
filter.set_opts({ state });
101-
filter.set_opts({ country });
102-
filter.set_opts({ subsection_code });
103-
filter.set_opts({ affilation_code });
104-
filter.set_opts({ deductibility_code });
105-
filter.set_opts({ deductibility_code_pub78 });
106-
filter.set_opts({ ntee_code });
107-
filter.set_texts({ classification_code });
108-
filter.set_texts({ activity_code });
109-
filter.set_opts({ foundation_code });
110-
filter.set_opts({ organization_code });
111-
filter.set_opts({ exempt_organization_status_code });
112-
filter.set_opts({ filing_requirement_code });
108+
filter.opts({ asset_code });
109+
filter.opts({ income_code });
110+
filter.opts({ website_url });
111+
filter.opts({ state });
112+
filter.opts({ country });
113+
filter.opts({ subsection_code });
114+
filter.opts({ affilation_code });
115+
filter.opts({ deductibility_code });
116+
filter.opts({ deductibility_code_pub78 });
117+
filter.texts({ classification_code });
118+
filter.texts({ activity_code });
119+
filter.opts({ foundation_code });
120+
filter.opts({ organization_code });
121+
filter.opts({ exempt_organization_status_code });
122+
filter.opts({ filing_requirement_code });
123+
filter.starts_with({ ntee_code });
113124

114125
const skip = (+page - 1) * +limit;
115126

src/pages/nonprofit-outreach/index.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,24 @@ export default function Page() {
166166
}}
167167
/>
168168
</th>
169-
<th>NTEE code</th>
169+
<th>
170+
<TextFilter
171+
num={1}
172+
label="NTEE code"
173+
_key="ntee_code"
174+
values={(k) => params.get(k)?.split(",") || []}
175+
onChange={(vs, k) => {
176+
setParams((p) => {
177+
if (vs.length === 0) {
178+
p.delete(k);
179+
return p;
180+
}
181+
p.set(k, vs.join(","));
182+
return p;
183+
});
184+
}}
185+
/>
186+
</th>
170187
<th>In care of</th>
171188
<th>Principal officer</th>
172189
<th>Group exemption number</th>

src/pages/nonprofit-outreach/text-filter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export function TextFilter(props: Props) {
7474
{Array.from({ length: props.num }, (_, i) => (
7575
<Field
7676
key={i}
77+
label=""
7778
{...register(`text${i}` as any)}
78-
label={`Code ${i + 1}`}
7979
classes={{ input: "text-xs py-1 px-2", label: "mb-0! text-xs" }}
8080
/>
8181
))}

0 commit comments

Comments
 (0)