-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Implement Plant Seasonality Filters (#17)
Co-authored-by: Catherine Tan <[email protected]> Co-authored-by: rachaelch3n <[email protected]> Co-authored-by: Catherine Tan <[email protected]> Co-authored-by: Sashank Balusu <[email protected]>
- Loading branch information
1 parent
f5c5120
commit 0d236b9
Showing
6 changed files
with
243 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Plant } from '@/types/schema'; | ||
import supabase from '../createClient'; | ||
|
||
export async function getPlantSeasonality( | ||
input_state: string, | ||
): Promise<Plant[]> { | ||
const { data, error } = await supabase | ||
.from('plants') | ||
.select('*') | ||
.eq('us_state', input_state); | ||
if (error) | ||
throw new Error(`Error fetching plant seasonality: ${error.message}`); | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { useState } from 'react'; | ||
|
||
interface FilterDropdownProps { | ||
name: string; | ||
id: string; | ||
value: string; | ||
setStateAction: React.Dispatch<React.SetStateAction<string>>; | ||
options: string[]; | ||
placeholder: string; | ||
} | ||
|
||
export default function FilterDropdown({ | ||
name, | ||
id, | ||
value, | ||
setStateAction, | ||
options, | ||
placeholder, | ||
}: FilterDropdownProps) { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
const handleChange = (event: React.ChangeEvent<HTMLSelectElement>) => { | ||
setStateAction(event.target.value); | ||
setIsOpen(false); | ||
}; | ||
|
||
const handleToggle = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
return ( | ||
<select | ||
name={name} | ||
id={id} | ||
onChange={handleChange} | ||
onClick={handleToggle} | ||
onBlur={() => setIsOpen(false)} | ||
value={value} | ||
> | ||
{/*Default placeholder text*/} | ||
<option value="" disabled hidden> | ||
{placeholder} | ||
</option> | ||
{options.map((option, index) => ( | ||
<option key={index} value={option}> | ||
{option} | ||
</option> | ||
))} | ||
</select> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export function processPlantMonth(month: string) { | ||
// If field is not null and starts with 'LATE' or 'EARLY, | ||
// get substring after 'LATE_ or 'EARLY_' | ||
if (!month) { | ||
return month; | ||
} | ||
|
||
if (month.startsWith('LATE')) { | ||
return month.substring(5); | ||
} else if (month.startsWith('EARLY')) { | ||
return month.substring(6); | ||
} else { | ||
return month; | ||
} | ||
} |