Skip to content

Commit 37ac352

Browse files
committed
texts condition
1 parent 8021309 commit 37ac352

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

src/pages/nonprofit-outreach/api.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@ import type { LoaderFunction } from "@vercel/remix";
22
import type { NonprofitItem } from "types/mongodb/nonprofits";
33
import { nonprofits } from ".server/mongodb/db";
44

5-
interface Stats {
6-
assets: { min: number | null; max: number | null };
7-
income: { min: number | null; max: number | null };
8-
revenue: { min: number | null; max: number | null };
9-
}
10-
115
export interface LoaderData {
126
items: NonprofitItem[];
137
page: number;
148
size: number;
159
num_items: number;
16-
stats?: Stats;
1710
}
1811

1912
class Filter {
@@ -116,6 +109,7 @@ export const loader: LoaderFunction = async ({ request }) => {
116109
income_amount,
117110
asset_amount,
118111
revenue_amount,
112+
sort_name,
119113
} = Object.fromEntries(url.searchParams.entries());
120114

121115
const filter = new Filter();
@@ -134,6 +128,7 @@ export const loader: LoaderFunction = async ({ request }) => {
134128
filter.opts({ organization_code });
135129
filter.opts({ exempt_organization_status_code });
136130
filter.opts({ filing_requirement_code });
131+
filter.opts({ sort_name });
137132
filter.starts_with({ ntee_code });
138133
filter.range({ income_amount });
139134
filter.range({ asset_amount });
@@ -144,7 +139,7 @@ export const loader: LoaderFunction = async ({ request }) => {
144139
const collection = await nonprofits;
145140
const items = await collection
146141
.find(filter.all)
147-
.sort({ asset_amount: -1 })
142+
.sort({ revenue_amount: -1 })
148143
.skip(skip)
149144
.limit(+limit)
150145
.toArray();

src/pages/nonprofit-outreach/index.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const _usd = new Intl.NumberFormat("en-US", {
1717
export default function Page() {
1818
const data = useCachedLoaderData<LoaderData>();
1919
const [params, setParams] = useSearchParams();
20-
const active_filters = Array.from(params.entries()).map(([k, v]) => (
20+
const { sort, sort_direction, ...filters } = Object.fromEntries(
21+
params.entries()
22+
);
23+
const active_filters = Object.entries(filters).map(([k, v]) => (
2124
<div key={k} className="flex items-center gap-x-2">
2225
<button
2326
type="button"
@@ -54,7 +57,7 @@ export default function Page() {
5457
)}
5558
<p className="font-bold my-2"> found: {data.num_items}</p>
5659
<div className="overflow-x-auto relative">
57-
<table className="self-start border-collapse overflow-x-auto [&_th]:text-left [&_th]:align-top [&_th]:text-balance [&_td]:align-top [&_td,&_th]:p-2 [&_td,&_th]:border [&_td,&_th]:border-gray-l3">
60+
<table className="self-start border-collapse overflow-x-auto [&_th]:text-left [&_th]:align-top [&_th]:text-balance [&_td]:text-nowrap [&_td,&_th]:p-2 [&_td,&_th]:border [&_td,&_th]:border-gray-l3">
5861
<thead>
5962
<tr>
6063
<th>EIN</th>
@@ -219,6 +222,7 @@ export default function Page() {
219222
<TextFilter
220223
num={1}
221224
label="NTEE code"
225+
description="can query partial e.g. A (starts with A) or complete (A80)"
222226
_key="ntee_code"
223227
values={(k) => params.get(k)?.split(",") || []}
224228
onChange={(vs, k) => {
@@ -278,6 +282,7 @@ export default function Page() {
278282
<TextFilter
279283
num={4}
280284
label="Classification code"
285+
description="NPOs may have up to 4 classification codes"
281286
_key="classification_code"
282287
values={(k) => params.get(k)?.split(",") || []}
283288
onChange={(vs, k) => {
@@ -354,6 +359,7 @@ export default function Page() {
354359
<TextFilter
355360
num={3}
356361
label="Activity code"
362+
description="NPOs may have up to 3 activity codes"
357363
_key="activity_code"
358364
values={(k) => params.get(k)?.split(",") || []}
359365
onChange={(vs, k) => {
@@ -425,7 +431,26 @@ export default function Page() {
425431
}}
426432
/>
427433
</th>
428-
<th>Sort Name</th>
434+
<th>
435+
<ListFilter
436+
name="Sort name"
437+
_key="sort_name"
438+
filter={{
439+
values: (k) => params.get(k)?.split(",") || [],
440+
optsFn: async () => [],
441+
onChange(vs, k) {
442+
setParams((p) => {
443+
if (vs.length === 0) {
444+
p.delete(k);
445+
return p;
446+
}
447+
p.set(k, vs.join(","));
448+
return p;
449+
});
450+
},
451+
}}
452+
/>
453+
</th>
429454
</tr>
430455
</thead>
431456
<tbody>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useForm } from "react-hook-form";
88

99
interface Props {
1010
label: string;
11+
description: string;
1112
_key: string;
1213
num: number;
1314
values?: (k: string) => string[];
@@ -71,6 +72,7 @@ export function TextFilter(props: Props) {
7172
<CheckField {...register("exists")} classes="mb-2 text-xs">
7273
Exists
7374
</CheckField>
75+
<p className="text-xs text-gray max-w-40">{props.description}</p>
7476
{Array.from({ length: props.num }, (_, i) => (
7577
<Field
7678
key={i}

0 commit comments

Comments
 (0)