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

Add race filter #140

Merged
merged 6 commits into from
Oct 5, 2020
Merged

Add race filter #140

merged 6 commits into from
Oct 5, 2020

Conversation

shariq1989
Copy link
Contributor

  • Added columns for filters on currentProsecutors page
  • Added UI for race filtering
  • I used the National Center for Educational Statistics Standards for coming up with the race/ethnicity list
  • Webstorm performed some auto-indenting
  • Added logic in the backend and db to handle race filter
  • Tested race filter functionality by locally adding attorneys with different races and no specified race.

@billimarie
Copy link
Owner

Hero! Confirmed QA. Merging; will be live within the hour. Thank you for your work on this.

@billimarie billimarie merged commit 4b1eb9b into billimarie:hacktober2020 Oct 5, 2020
This was referenced Oct 5, 2020
billimarie pushed a commit that referenced this pull request Oct 5, 2020
Adds additional filter for prosecutor race via @shariq1989
? Attorneys.find({ "role": { $in: selectedRoleFilters } }).fetch()
: Attorneys.find().fetch()
const selectedRaceFilters = Template.instance().state.get("selectedRaceFilters")
if (selectedRoleFilters.length > 0 && selectedRaceFilters.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, I think there is a more elegant way to do this, which also would scale a lot better as we add filters. Something like:

  let filter = null;

  if (selectedRoleFilters.length > 0) {
    filter = { ...filter, role: { $in: selectedRoleFilters } };
  }
  if (selectedRaceFilters.length > 0) {
    filter = { ...filter, race: { $in: selectedRaceFilters } };
  }

  return filter ? Attorneys.find(filter).fetch() : Attorneys.find().fetch()
  }

I haven't actually tried that code, but I'm pretty sure that should work. If Meteor supports passing in empty objects or null as filter then the return can be simplified even further by simply returning Attorneys.find(filter).fetch(), but I have no clue about that as I'm quite noob as Meteor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm glad you reached out. I wanted to have this exact conversation with you. I have never worked with Meteor before/also was tired and couldnt find a better paradigm online at the time. This looks like a good solution. Do you think I should go add this in or should @CodeSmitty as a part of his work? He might end up having to pull down from upstream which as a newer dev may be a pain for him.

Choose a reason for hiding this comment

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

Seems like you guys go this down. Don't wait on me, if you can fix it. Like I said, I'm fairly new to this only a year and a half into javascript. 2nd Day trying to understand Meteor. I joined to the hactoberfest and I'm not sure if I'm over my head.

Copy link
Contributor

@Zoe7 Zoe7 Oct 6, 2020

Choose a reason for hiding this comment

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

Just to be clear, the code snippet that I posted above is mostly javascript functionality, the only "meteor" specific thing in there is the Attorneys.find(filter).fetch() part.
What I'm using to build up the filter object is a javascript feature called spread operator. It allows us to build a new object based on the content of another object, which is what I'm doing with this line: filter = { ...filter, race: { $in: selectedRaceFilters } }. I'm basically saying: take whatever was in the old filter object, add race: { $in: selectedRaceFilters } to it and make a new object out of that.
If you don't know that syntax, I would highly recommand looking at some tutorials for it and playing around with it a little, it's super useful!

Do you think I should go add this?

You're very welcome to do so! I just started a new job yesterday so I'm a bit busy and mentally overloaded right now 😅

He might end up having to pull down from upstream

At this point, he's going to have to do that anyway, since his changes would conflict with ours and they need to be resolved 😕 Github has a lot of good guides on how to handle forks and one in particular explaining how to keep a forked repository in sync. And I'm happy to answer questions and help with it if needed 😄

I joined to the hactoberfest and I'm not sure if I'm over my head.

Meteor definitely got me challenged, and I haved worked in the industry for 6 years now 😄 It works, but it's definitely a little more oldschool and harder to get started with than newer frameworks. But I think it's super cool that you're joining hacktoberfest, it's a great way to learn new stuff and get a little challenged! Let me know if you have any questions in particular that I can answer, I'd be happy to help!

Choose a reason for hiding this comment

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

Yea I understand spread operators, I'm not the best at it. But working with react, did help me use them in other cases. What I ment is, how to give Meteor my changes so I can see them live. I'm reading through it all though, I just pulled what you two added to it. Looking at it from there. One line that did confuse me a little was the race:{$in: selectedRaceFilter.

Which for me it means give the new object data and store in the race object of.. the $in it's kinda what I didn't know if that's a variable name chosen. I'm used to seeing the $ symbol in more of a back tick. string add ${data} string.
Apologies for my typos, also I appreciate you all taking the time to explain things to me, and not letting me quit lol.
I'm at least playing with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$in is a mongoDB operator. It selects records that match any of the values provided in the selectedRaceFilter. So if we have "Black" and "Hispanic" in the selectedRaceFilter, the query would pull all attorneys that have those set in the "race" field.

https://docs.mongodb.com/manual/reference/operator/query/in/

Choose a reason for hiding this comment

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

Ok, that makes much more sense. I'll play around with it after work and see what I get. Thank you!

Copy link
Owner

Choose a reason for hiding this comment

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

Inviting @rohitkswat to the party, as he untangled this logic with #157

@billimarie billimarie added the hacktoberfest-accepted To count toward Hacktoberfest 2020 credit label Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted To count toward Hacktoberfest 2020 credit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants