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

Added a conditional dendering for the regionMap #141

Closed
wants to merge 2 commits into from

Conversation

pbelokon
Copy link
Contributor

@pbelokon pbelokon commented Dec 12, 2023

Description

Added a conditional rendering for RegionMap based on if the region has geometry data, added a button that calls getGeometry with farce set to true when there is not geometry data.

Related Issues

Closes: #51

How Was This Tested?

This will be tested by loading regions with no geometry data to see if the button appearance. Currently my db works incorrect so I will test this one I figure that out.

Checklist

Before submitting your PR, please review the following:

  • Commit messages follow the standard template.
  • All commits are signed.
  • Related issues are mentioned in the description above.
  • I have followed the project's directory structure.
  • Linter checks have been passed.

Additional Comments (if any):

Summary by CodeRabbit

  • New Features

    • Introduced a "Fetch Geometry" button for regions in the map component.
  • Enhancements

    • Improved region geometry fetching with an added force option.
  • Style

    • Integrated new button styling from Material UI.

Copy link

coderabbitai bot commented Dec 12, 2023

Walkthrough

The code changes involve enhancing the RegionMap component to handle cases where regions lack geometry data. A new import for a Button component has been added, along with a parameter to force the fetching of geometry data and a handler function for the button click. Conditional rendering is updated to show a button when no geometry data is present, allowing users to fetch aggregated data from subregions.

Changes

File Path Change Summary
frontend/src/components/.../RegionMap.jsx Added import for Button, updated fetchSelectedRegionGeometry to accept force parameter, added handleForceGeometryFetch function, and conditional rendering for the Button.

Assessment against linked issues

Objective Addressed Explanation
Implement a fallback mechanism for regions lacking geometry data in the RegionMap component (#51)
Add conditional rendering to check for geometry data presence and render a button if absent (#51)
Button triggers getGeometry with force set to true for data aggregation from subregions (#51)
Clicking the button updates the map to display aggregated geometry data (#51) It's unclear if the map is updated as the snippet does not show how the state is managed after fetching the data.
Test new functionality with various regions to validate behavior and improve user experience (#51) The snippet provided does not include tests or indicate that testing was performed.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
  • You can tag CodeRabbit on specific lines of code or entire files in the PR by tagging @coderabbitai in a comment. Examples:
    • @coderabbitai generate unit tests for this file
    • @coderabbitai modularize this function
  • You can tag @coderabbitai in a PR comment and ask questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions. Examples:
    • @coderabbitai gather interesting statistics about this repository and render them in a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai generate unit tests for the src/utils.ts file.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

sweep-ai bot commented Dec 12, 2023

Apply Sweep Rules to your PR?

  • Apply: All new business logic should have corresponding unit tests.
  • Apply: Refactor large functions to be more modular.
  • Apply: Add docstrings to all functions and file headers.
  • Apply: In the PR description, provide the Issue number that your PR fixes in a form Fixes #<Issue Number>
  • Apply: Make changes only in the directory you are working on (frontend, backend, or deployment).
  • Apply: For JavaScript (used in frontend and backend), follow the Airbnb JavaScript Style Guide
  • Apply: For Python (used in deployment scripts), use Black
  • Apply: Follow this format for all commit messages:
<Type>: <Topic>.

<Description>

[Issue: #<GitHub Issue Number>]

Type can be one of the following:

  • front: Frontend
  • back: Backend
  • deploy: Deployment
    Or leave it blank if the commit is not specific to any of the above.
    Ensure the commit message is concise yet descriptive.
    If the commit fixes an issue, add the issue number in the commit message.

@pbelokon
Copy link
Contributor Author

pbelokon commented Dec 12, 2023

@OhmSpectator you mentioned that there was a lint script I have to run, where can I find it both frontend and backend are missing it.

PS D:\track-your-regions\frontend> npm run lint
npm ERR! Missing script: "lint"

@pbelokon pbelokon marked this pull request as draft December 12, 2023 23:35
@OhmSpectator
Copy link
Owner

@pbelokon, the script can be run from the frontend or backend directory with this command:

npm run lint

I've also updated the CONTRIBUTING.md file:
frontend - https://github.com/OhmSpectator/track-your-regions/blob/main/frontend/CONTRIBUTING.md
backend - https://github.com/OhmSpectator/track-your-regions/blob/main/backend/CONTRIBUTING.md
general - https://github.com/OhmSpectator/track-your-regions/blob/main/CONTRIBUTING.md

@OhmSpectator
Copy link
Owner

PS D:\track-your-regions\frontend> npm run lint
npm ERR! Missing script: "lint"

You have to pull the latest version of main. You have the old version locally:
Screenshot 2023-12-13 at 00 41 32

@pbelokon
Copy link
Contributor Author

pbelokon commented Dec 12, 2023

PS D:\track-your-regions\frontend> npm run lint
npm ERR! Missing script: "lint"

You have to pull the latest version of main. You have the old version locally: Screenshot 2023-12-13 at 00 41 32

dam forgot to do that thk

@pbelokon
Copy link
Contributor Author

pbelokon commented Dec 12, 2023

@OhmSpectator Rebased it and did changes on the new files, sorry about that

@pbelokon
Copy link
Contributor Author

pbelokon commented Dec 13, 2023

@OhmSpectator I think there is a mistake in the front-end it says that we should run npm run linter and npm run linter:fix

since in the project we use the below:

    "lint": "eslint --ext .js,.jsx src",
    "lint:fix": "eslint --fix --ext .js,.jsx src"

@OhmSpectator
Copy link
Owner

Hey @pbelokon, I wanted to let you know that I have merged #86 and updated the main branch accordingly. Could you please rebase this PR? Thanks!

@OhmSpectator
Copy link
Owner

I think there is a mistake in the front-end

Yep, that's true! I will fix it! Thanks for the catch!

@pbelokon
Copy link
Contributor Author

Hey @pbelokon, I wanted to let you know that I have merged #86 and updated the main branch accordingly. Could you please rebase this PR? Thanks!

Just did it, thank you for teaching me how lol

@OhmSpectator OhmSpectator marked this pull request as ready for review December 14, 2023 16:38
@OhmSpectator OhmSpectator changed the title [WIP] : added a conditional dendering for the regionMap Added a conditional dendering for the regionMap Dec 14, 2023
@OhmSpectator
Copy link
Owner

@coderabbitai review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 551537d and c0bc4d9.
Files selected for processing (1)
  • frontend/src/components/RegionMap.jsx (3 hunks)
Additional comments: 5
frontend/src/components/RegionMap.jsx (5)
  • 4-4: The import of the Button component is correctly added to support the new UI functionality.

  • 15-25: The modification to fetchSelectedRegionGeometry to include a force parameter aligns with the PR's goal to fetch geometry data when necessary.

  • 124-127: The new handleForceGeometryFetch function is implemented to trigger a forced fetch of geometry data and reinitialize the map, which is in line with the PR objectives.

  • 124-127: The sequence of calling fetchSelectedRegionGeometry(true) followed by initializeMap() in handleForceGeometryFetch is correct for the intended functionality of reinitializing the map with new geometry data.

  • 121-122: The useEffect hook is correctly used to initialize the map and provide a cleanup function to remove the map when the component unmounts or dependencies change.

Comment on lines +132 to +142
{!fetchSelectedRegionGeometry() && (
<Button onClick={handleForceGeometryFetch}>Fetch Geometry</Button>
)}
Copy link

Choose a reason for hiding this comment

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

Looks like humans are talking. I'll be quiet for now. If you need me again, just tag @coderabbitai in a new comment.

@OhmSpectator
Copy link
Owner

@pbelokon, I've prepared a prepopulated DB image. You can try to get it for full-setup testing.
I've described how to get it here: https://github.com/OhmSpectator/track-your-regions/blob/main/deployment/README.md#usage-of-prepopulated-database-container
Then you can start the back and the front as described in README (in short: create .env.development and fill with proper values and then run npm run debug for the backend and npm run start for the frontend).

Comment on lines +132 to +142
{!fetchSelectedRegionGeometry() && (
<Button onClick={handleForceGeometryFetch}>Fetch Geometry</Button>
)}
Copy link

Choose a reason for hiding this comment

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

Looks like humans are talking. I'll be quiet for now. If you need me again, just tag @coderabbitai in a new comment.

Copy link
Owner

@OhmSpectator OhmSpectator left a comment

Choose a reason for hiding this comment

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

@pbelokon, I would also be happy to see that the commit messages are following the template:

front: <Topic>.

<Description>

[Issue: #<GitHub Issue Number>]

It put this into doc: https://github.com/OhmSpectator/track-your-regions/blob/main/frontend/CONTRIBUTING.md

@OhmSpectator
Copy link
Owner

@pbelokon I've rebased the branch on top of main. So, be careful when starting working on it again: do not forget to pull the latest version.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between a029b47 and 35f29e6.
Files selected for processing (1)
  • frontend/src/components/RegionMap.jsx (3 hunks)
Additional comments: 3
frontend/src/components/RegionMap.jsx (3)
  • 4-4: The addition of the Button import from @mui/material aligns with the PR objectives to enhance the UI for handling regions without geometry data.

  • 23-33: The modification of fetchSelectedRegionGeometry to include a force parameter is consistent with the PR objectives. Ensure that all calls to this function have been updated to pass this parameter when needed.

#!/bin/bash
# Search for calls to `fetchSelectedRegionGeometry` without the `force` parameter.
ast-grep --lang javascript --pattern $'fetchSelectedRegionGeometry($_)'
  • 132-134: The handleForceGeometryFetch function correctly calls fetchSelectedRegionGeometry with force set to true, and then initializes the map. This aligns with the PR objectives to allow users to fetch and visualize geometry data for regions without it.

@OhmSpectator
Copy link
Owner

@pbelokon, I've just realized that the instructions and the scripts to create/deploy the DB are Unix-specific and unsuitable for Windows... I'll try to fix it.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 5d1d4a4 and 6ad9de2.
Files selected for processing (1)
  • frontend/src/components/RegionMap.jsx (3 hunks)
Additional comments: 3
frontend/src/components/RegionMap.jsx (3)
  • 4-4: Import of Button from @mui/material is correctly added to support the new UI feature.

  • 23-33: The addition of the force parameter to fetchSelectedRegionGeometry is correctly implemented to bypass the cache when needed.

  • 132-135: The handleForceGeometryFetch function correctly forces a geometry fetch and reinitializes the map. Ensure that the state is properly updated to reflect the new geometry data.

Comment on lines +140 to +142
{!fetchSelectedRegionGeometry() && (
<Button onClick={handleForceGeometryFetch}>Fetch Geometry</Button>
)}
Copy link

Choose a reason for hiding this comment

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

The conditional rendering logic for the "Fetch Geometry" button is incorrect as it relies on the return value of an async function. This should be based on a state variable that holds the result of fetchSelectedRegionGeometry().

- {!fetchSelectedRegionGeometry() && (
+ {!regionGeometry && (

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
{!fetchSelectedRegionGeometry() && (
<Button onClick={handleForceGeometryFetch}>Fetch Geometry</Button>
)}
{!regionGeometry && (
<Button onClick={handleForceGeometryFetch}>Fetch Geometry</Button>
)}

Copy link

github-actions bot commented Jan 1, 2024

👋 Hey there! Just noticed this PR has been quiet for a week. We miss your updates! If there is no activity in the next week, we will need to close it for housekeeping. 😊🧹

@github-actions github-actions bot added stale and removed stale labels Jan 1, 2024
Copy link

👋 Hey there! Just noticed this PR has been quiet for a week. We miss your updates! If there is no activity in the next week, we will need to close it for housekeeping. 😊🧹

@github-actions github-actions bot added the stale label Jan 12, 2024
Copy link

🚪 We are doing a little housekeeping and noticed this PR has been quiet for a while. We are going to close it for now. If you are ready to pick this up again, please feel free to open a new PR or reach out to us, and we will be happy to help you reopen this one! 😄👍

@github-actions github-actions bot closed this Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a fallback mechanism for regions without geometry data
2 participants