Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Implement Plant Seasonality Filters #17

Merged

Conversation

kylezryr
Copy link
Collaborator

What's new in this PR 🧑‍🌾

Description

  • Created Filter Dropdowns in seasonal-planting-guide to filter through the PlantList component
  • Filters are by growing_season, harvest_season, and planting_type
  • Added a clear filters button to remove all filters and display the default list

Screenshots

image
image

How to review

  • Go to the seasonal-planting-guide page
  • Check that all plants are displayed by default
  • Change some of the filters and verify that the result is correct
  • Check that clear filters displays the original list

Next steps

  • Styling

Relevant links

Online sources

Related PRs

CC: @ccatherinetan

kylezryr and others added 3 commits October 20, 2024 12:35
Co-authored-by: Catherine Tan <[email protected]>
Co-authored-by: rachaelch3n <[email protected]>
Co-authored-by: Catherine Tan <[email protected]>
Copy link
Collaborator

@ccatherinetan ccatherinetan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking so great, thanks kyle! a couple comments, esp about the growing season filtering logic, but this is a great start!

we'll keep building on this in the next sprint by (1) adding a state filter, (2) making all filters except the state filter multi-select

components/FilterDropdown.tsx Outdated Show resolved Hide resolved
components/PlantList.tsx Outdated Show resolved Hide resolved
components/PlantList.tsx Outdated Show resolved Hide resolved
components/PlantList.tsx Outdated Show resolved Hide resolved
components/PlantList.tsx Outdated Show resolved Hide resolved

const filterPlantList = (plant: Plant) => {
return (
checkGrowingSeason(plant) &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i rlly like this structure! it's super clean; great job!
quick note: in the next sprint we'll add a state filter too

Comment on lines 37 to 41
return (
months?.includes(plant.indoors_start) ||
months?.includes(plant.indoors_end) ||
months?.includes(plant.outdoors_start) ||
months?.includes(plant.outdoors_end)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm wondering if we need to modify the logic here. what if the growing season is Summer, but the indoor time is April-Sept (i.e. it includes all Summer months, but the start and end times are not in the summer months), and outdoors is August-August? I don't think this example would realistically happen, but we also have to account for LATE_MONTH values which aren't included in the growingSeasonToMonth map.
Perhaps we should try to all seasons that the growing season elapses and check if the inputted growing_season is in the list of elapsed seasons.
Perhaps using actual enums might help here? (The type enums that we're using rn are just types and not actual enums oops)

components/PlantList.tsx Outdated Show resolved Hide resolved
@ccatherinetan ccatherinetan linked an issue Oct 22, 2024 that may be closed by this pull request
Copy link
Collaborator

@ccatherinetan ccatherinetan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking fantastic!

we may need to move all the filter checks to utils!
EDIT: we'll move to utils in the multi-select sprint, since we'll be refactoring the filter funcs to take in a list of plants
checkGrowingSeason, checkHarvestSeason, checkPlantingType

Comment on lines +43 to +45
const us_state = 'TENNESSEE';
const filteredPlantList = plantList.filter(
plant => plant.us_state === us_state,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we'll make us_state camelCase in the future

// Check if growingSeason matches the plant's growing season
const checkGrowingSeason = (plant: Plant) => {
// Automatically returns true if selected growing season is ''
if (!growingSeason) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename all filter values to e.g. growingSeasonFilterValue

Comment on lines 62 to 70
const validIndexes = growingSeasonToIndex.get(growingSeason);

const isInRange = (start: number, end: number, validIndexes: number[]) => {
// Checks if the start and end months are within the valid range
if (start <= end) {
return validIndexes.some(index => index >= start && index <= end);
} else {
// Handle wrap-around case (e.g. NOVEMBER to FEBRUARY)
return validIndexes.some(index => index >= start || index <= end);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great! just a quick note, we might move checkGrowingSeason and other filter util funcs to /utils in the future since Sashank will also need it for filters on VIew Plants

Comment on lines 82 to 87
if (
indoorsStart &&
(indoorsStart.startsWith('LATE') || indoorsStart.startsWith('EARLY'))
) {
indoorsStart = indoorsStart.substring(5);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe create a util func that gets the month value, to repeat code repetition with indoorsStart, indoorsEnd etc.?
Also, for 'EARLY', you'd probably need to do indoorsStart.substring(6) instead indoorsStart.substring(5) so let's make separate checks for that!

Comment on lines +111 to +119
isInRange(
monthToIndex.get(indoorsStart)!,
monthToIndex.get(indoorsEnd)!,
validIndexes!,
) ||
isInRange(
monthToIndex.get(outdoorsStart)!,
monthToIndex.get(outdoorsEnd)!,
validIndexes!,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great handle! i was originally thinking that we'd only check

isInRange(
        monthToIndex.get(indoorsStart)!,
        monthToIndex.get(outdoorsEnd)!,
        validIndexes!)

However, this logic seems more accurate. i'll check w POC, but this is great for now

Comment on lines +166 to +171
.filter(filterPlantList)
.sort((a, b) => a.plant_name.localeCompare(b.plant_name))
.map((plant, key) => (
//this should display PlantCalendarRows instead of this temporary div
<div key={key}>{plant.plant_name}</div>
))}
Copy link
Collaborator

@ccatherinetan ccatherinetan Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm wondering if we should use a useMemo or do the alphabetical sorting outside of the returned html, i.e. before filtering? @ronniebeggs @pragyakallanagoudar
but this is all right for now!

@ccatherinetan ccatherinetan merged commit 0d236b9 into main Oct 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Plant Seasonality Filters
3 participants