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

Show All Animals on Manage Animals Page #1482

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open

Show All Animals on Manage Animals Page #1482

wants to merge 7 commits into from

Conversation

AMEIJER1
Copy link
Collaborator

@AMEIJER1 AMEIJER1 commented Feb 6, 2025

Description of Changes

  • When an animal is not selected on the Manage Animals page, show the map/table of all Animals in the Survey

@AMEIJER1 AMEIJER1 added the Ready For Review PR is ready for review label Feb 6, 2025
@AMEIJER1 AMEIJER1 requested a review from mauberti-bc February 6, 2025 20:16
@AMEIJER1 AMEIJER1 self-assigned this Feb 6, 2025
@AMEIJER1 AMEIJER1 changed the title Animal landing Animal landing page Feb 6, 2025
Copy link

sonarqubecloud bot commented Feb 6, 2025

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 46.90%. Comparing base (aafa2c7) to head (2f8e6f8).

Files with missing lines Patch % Lines
...-spatial/components/animal/SurveySpatialAnimal.tsx 0.00% 4 Missing ⚠️
app/src/features/surveys/animals/AnimalPage.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1482      +/-   ##
==========================================
- Coverage   47.56%   46.90%   -0.66%     
==========================================
  Files         930      921       -9     
  Lines       25641    23818    -1823     
  Branches     3954     3540     -414     
==========================================
- Hits        12195    11173    -1022     
+ Misses      12794    12044     -750     
+ Partials      652      601      -51     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +39 to +40
if (critterIds.length) {
geometryDataLoader.load(critterIds);
Copy link
Collaborator

@NickPhura NickPhura Feb 6, 2025

Choose a reason for hiding this comment

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

(No change needed, just some context around the way this was written before, with the negative length check and early return)

In general, It is considered best practice to keep code as flat as possible (with as little nesting as possible, when its reasonable to do so).


In this case, we have to do the if check for the length no matter what, but it is slightly nicer to not nest 'real' code when possible. Hence writing it like this:

if (what_we_dont_want) {
  return; // end early
}

if (also_what_we_dont_want) {
  return; // end early
}

return what_we_do_want();

In a similar vein:

if (some_condition) {
  return 1;
} else {
  return 2;
}

is better written as:

if (some_condition) {
  return 1;
}

return 2;

Since the else is implied, we can remove that extra level of nesting and reduce how many brackets you have to parse to understand the code.


In this case, the useEffect has so little code that no one is seriously going to worry about it. Just more of a heads up for future, especially if you have more than one if/else statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi! Thank you so much for taking the time to provide insightful, detailed feedback! I will review and revise :)

*/
staticLayers: IStaticLayer[];
interface ISurveySpatialAnimalMapProps {
staticLayers?: IStaticLayer[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add the JSDoc back?

Copy link
Collaborator

Choose a reason for hiding this comment

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

More documentation is always a win

}

geometryDataLoader.load(critterIds);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [critterIds]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing dependency: geometryDataLoader

Copy link
Collaborator

@NickPhura NickPhura Feb 6, 2025

Choose a reason for hiding this comment

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

It is quite possible that including that dependency will result in an infinite loop of requests. In which case we need to include that comment // eslint-disable-next-line react-hooks/exhaustive-deps which tells the linter (eslint) to ignore the fact that there is a missing dependency.

Copy link
Collaborator

@NickPhura NickPhura Feb 6, 2025

Choose a reason for hiding this comment

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

In this case it may be fine to include it, as the load function is designed to only run once. So even if the useEffect is triggered more than once, the load function internally will only actually make the request one time ever.

@mauberti-bc mauberti-bc added Early Feedback Welcome PR is not finished, but early review feedback is welcomed and removed Ready For Review PR is ready for review labels Feb 6, 2025
@mauberti-bc mauberti-bc changed the title Animal landing page Show All Animals on Manage Animals Page Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Early Feedback Welcome PR is not finished, but early review feedback is welcomed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants