Skip to content

Commit

Permalink
Added owner to project search parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaamanen committed Mar 27, 2023
1 parent 66b1abf commit 899093a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
8 changes: 8 additions & 0 deletions backend/src/components/project/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,19 @@ function orderByFragment(input: ProjectSearch) {
return sql.fragment`ORDER BY project.start_date DESC`;
}

function ownerFragment(input: ProjectSearch) {
if (input.owners.length === 0) {
return sql.fragment`true`;
}
return sql.fragment`owner = ANY(${sql.array(input.owners, 'text')})`;
}

export function getFilterFragment(input: ProjectSearch) {
return sql.fragment`
AND ${textSearchFragment(input.text)}
AND ${mapExtentFragment(input)}
AND ${timePeriodFragment(input)}
AND ${ownerFragment(input)}
AND ${
input.lifecycleStates && input.lifecycleStates?.length > 0
? sql.fragment`(project.lifecycle_state).id = ANY(${sql.array(
Expand Down
1 change: 1 addition & 0 deletions backend/src/components/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const userSelectFragment = sql.fragment`
export async function getAllUsers() {
const users = await getPool().many(sql.type(userSchema)`
${userSelectFragment}
ORDER BY name ASC
`);
return users;
}
Expand Down
29 changes: 3 additions & 26 deletions frontend/src/stores/search/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,7 @@ import { focusAtom } from 'jotai-optics';

import { mapOptions } from '@frontend/components/Map/mapOptions';

import { MapSearch, Period } from '@shared/schema/project';

interface Filters {
investmentProject?: {
committees?: string[];
};
detailplanProject?: {
planningZones?: string[];
};
}

interface ProjectSearch {
text: string;
dateRange: Period;
lifecycleStates: string[];
map: MapSearch;
includeWithoutGeom: boolean;
filters: {
investmentProject?: {
committees?: string[];
};
detailplanProject?: {
planningZones?: string[];
};
};
}
import { ProjectSearch } from '@shared/schema/project';

export const projectSearchParamAtom = atom<ProjectSearch>({
text: '',
Expand All @@ -38,6 +13,7 @@ export const projectSearchParamAtom = atom<ProjectSearch>({
endDate: dayjs().endOf('year').format('YYYY-MM-DD'),
},
lifecycleStates: [],
owners: [],
map: {
zoom: mapOptions.tre.defaultZoom,
extent: mapOptions.tre.extent,
Expand All @@ -51,6 +27,7 @@ export const dateRangeAtom = focusAtom(projectSearchParamAtom, (o) => o.prop('da
export const lifecycleStatesAtom = focusAtom(projectSearchParamAtom, (o) =>
o.prop('lifecycleStates')
);
export const ownersAtom = focusAtom(projectSearchParamAtom, (o) => o.prop('owners'));
export const includeWithoutGeomAtom = focusAtom(projectSearchParamAtom, (o) =>
o.prop('includeWithoutGeom')
);
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/views/Project/SearchControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import { useState } from 'react';
import { CodeSelect } from '@frontend/components/forms/CodeSelect';
import { DateRange } from '@frontend/components/forms/DateRange';
import { ProjectTypeSelect } from '@frontend/components/forms/ProjectTypeSelect';
import { UserSelect } from '@frontend/components/forms/UserSelect';
import { useTranslations } from '@frontend/stores/lang';
import {
dateRangeAtom,
filtersAtom,
includeWithoutGeomAtom,
lifecycleStatesAtom,
ownersAtom,
textAtom,
} from '@frontend/stores/search/project';

Expand Down Expand Up @@ -79,6 +81,7 @@ export function SearchControls() {
const [text, setText] = useAtom(textAtom);
const [dateRange, setDateRange] = useAtom(dateRangeAtom);
const [lifecycleStates, setLifecycleStates] = useAtom(lifecycleStatesAtom);
const [owners, setOwners] = useAtom(ownersAtom);
const [filters, setFilters] = useAtom(filtersAtom);
const [includeWithoutGeom, setIncludeWithoutGeom] = useAtom(includeWithoutGeomAtom);

Expand Down Expand Up @@ -163,6 +166,10 @@ export function SearchControls() {
}}
/>
</FormControl>
<FormControl>
<FormLabel htmlFor="owner">{tr('project.ownerLabel')}</FormLabel>
<UserSelect id="owner" multiple value={owners} onChange={setOwners} />
</FormControl>
</div>
{expanded && (
<>
Expand Down
1 change: 1 addition & 0 deletions shared/src/schema/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const projectSearchSchema = z.object({
lifecycleStates: z.array(z.string()).optional(),
projectTypes: z.array(z.string()).optional(),
map: mapSearchSchema.optional(),
owners: z.array(z.string()),
includeWithoutGeom: z.boolean().optional(),
filters: z.object({
investmentProject: z
Expand Down

0 comments on commit 899093a

Please sign in to comment.