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

Website/test config changes #2166

Closed
wants to merge 9 commits into from
Closed

Conversation

OchiengPaul442
Copy link
Contributor

@OchiengPaul442 OchiengPaul442 commented Sep 16, 2024

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included issue number in the "Closes #ISSUE-NUMBER" part of the "What are the relevant tickets?" section to link the issue.
  • I've updated corresponding documentation for the changes in this PR.
  • I have written unit and/or e2e tests for my change(s).

How should this be manually tested?

  • Please include the steps to be done inorder to setup and test this PR.

What are the relevant tickets?

Screenshots (optional)

Summary by CodeRabbit

  • New Features

    • Introduced an ErrorBoundary component in the MiniHighlights section for improved error handling.
    • Updated script tags in index.html to enhance loading behavior and security.
    • Added a new start script for concurrent server and application running.
  • Bug Fixes

    • Improved link handling in the SubSection component for better user experience.
  • Chores

    • Streamlined build and development workflow with updated scripts and dependencies in package.json.
    • Removed outdated Webpack configuration files to simplify the project structure.
    • Enhanced template and static file handling for improved clarity and functionality.

Copy link

coderabbitai bot commented Sep 16, 2024

Warning

Rate limit exceeded

@OchiengPaul442 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 3 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 19e6d32 and e29e0e8.

Walkthrough

Walkthrough

The pull request introduces several changes across multiple files, primarily focusing on enhancing the Django backend and React frontend configurations. Key updates include modifications to the Django settings for template and static file handling, the introduction of an ErrorBoundary in a React component, and adjustments to the Webpack configuration for improved build processes. Additionally, several deprecated configuration files have been removed, streamlining the overall project structure.

Changes

File Change Summary
website/backend/settings.py Updated TEMPLATES to include the path to index.html and modified STATICFILES_DIRS to reference the entire frontend directory.
website/frontend/NetworkStatus.js Added an import statement for React, indicating future enhancements to the component.
website/frontend/src/components/MiniHighlights.js Introduced an ErrorBoundary component for error handling, updated anchor tag for security, and modified link handling in SubSection.
website/frontend/templates/index.html Enhanced script tags with defer and crossorigin attributes for better loading behavior and security.
website/package.json Updated scripts to use a new Webpack configuration, added a new start script, and included new dependencies (cross-env, strip-loader).
website/webpack.config.js Significant modifications to enhance Webpack configuration, including the addition of HtmlWebpackPlugin and improved environment variable handling.
website/webpack.dev.config.js Deleted the file, indicating a shift away from specific development configurations.
website/webpack.fullapp.config.js Deleted the file, suggesting a change in the build process for the frontend application.

Possibly related PRs

  • fix: Redux Persist issue #2161: Changes in package.json regarding the removal of redux-persist may connect to the updates in settings.py, as both involve configurations affecting the application structure.

Suggested labels

ready for review

Poem

In code we weave, a tapestry bright,
With Django and React, we take flight.
Error boundaries catch what may fall,
While scripts now load with a secure call.
A cleaner path, our project sings,
In harmony, the future brings! 🎉


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

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai generate interesting stats about this repository and render them as a table.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (4c9957b) to head (e29e0e8).
Report is 21 commits behind head on staging.

Additional details and impacted files
@@            Coverage Diff            @@
##           staging     #2166   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines            5         5           
  Branches         2         2           
=========================================
  Hits             5         5           

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

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.

Actionable comments posted: 1

Outside diff range and nitpick comments (3)
website/frontend/src/components/MiniHighlights.js (1)

25-27: Consider providing a more informative error message to the user.

The current error message "Something went wrong." is a good fallback, but it may not provide enough information to the user about what went wrong and how to recover.

Consider providing a more specific error message or a way for the user to report the error to the development team.

For example, you could display an error code and a link to a support page:

if (this.state.hasError) {
  return (
    <div>
      <h1>Oops! Something went wrong.</h1>
      <p>Error code: {error.code}</p>
      <p>Please <a href="/support">contact support</a> and provide the error code above.</p>
    </div>
  );
}
website/package.json (2)

11-11: Consider using a process manager for a more robust solution.

The addition of the start script to concurrently run a Python server and the serve script is a good idea to facilitate a smoother development experience. However, for a more robust solution, consider using a process manager like PM2 or Forever to manage these processes. This will provide additional features like automatic restarts on crashes, logging, and more.


49-49: Consider moving the dependencies to devDependencies.

The addition of cross-env and strip-loader to the dependencies section is fine. However, since these packages are only used during the build process and not in production, consider moving them to the devDependencies section instead.

Apply this diff to move the dependencies to devDependencies:

  "dependencies": {
    "@babel/runtime": "^7.20.13",
    "@emotion/react": "^11.10.5",
    "@emotion/styled": "^11.10.5",
    "@mui/icons-material": "^5.11.0",
    "@mui/material": "^5.11.8",
    "axios": "^1.3.2",
    "dompurify": "^3.1.6",
    "i18next": "^23.5.1",
    "i18next-http-backend": "^2.2.2",
    "react": "^18.2.0",
    "react-device-detect": "^2.2.3",
    "react-dom": "^18.2.0",
    "react-helmet": "^6.1.0",
    "react-icons": "^5.2.1",
    "react-player": "^2.12.0",
    "react-router-dom": "^6.8.1",
    "react-scroll": "^1.8.9",
    "sass": "^1.77.8",
    "underscore": "^1.13.6",
-   "cross-env": "^7.0.3",
-   "strip-loader": "^0.1.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.12",
    "@babel/plugin-transform-runtime": "^7.19.6",
    "@babel/preset-env": "^7.22.10",
    "@babel/preset-react": "^7.22.5",
    "@redux-devtools/extension": "^3.3.0",
    "@reduxjs/toolkit": "^2.2.6",
    "@svgr/webpack": "^8.1.0",
    "@testing-library/jest-dom": "^6.4.8",
    "@testing-library/react": "^16.0.0",
    "babel-jest": "^29.6.4",
    "babel-loader": "^9.1.2",
    "classnames": "^2.3.2",
    "css-loader": "^7.1.2",
    "date-fns": "^3.6.0",
    "dotenv": "^16.0.3",
    "eslint": "^9.8.0",
    "file-loader": "^6.2.0",
    "html-webpack-plugin": "^5.5.0",
    "i18next-browser-languagedetector": "^8.0.0",
    "jest": "^29.6.2",
    "jest-environment-jsdom": "^29.6.2",
    "jest-svg-transformer": "^1.0.0",
    "mini-css-extract-plugin": "^2.9.0",
    "postcss": "^8.4.21",
    "postcss-loader": "^8.1.1",
    "postcss-preset-env": "^9.6.0",
    "prettier": "^3.3.3",
    "react-i18next": "^15.0.0",
    "react-redux": "^9.1.2",
    "react-test-renderer": "^18.2.0",
    "redux": "^5.0.1",
    "redux-thunk": "^3.1.0",
    "sass-loader": "^16.0.0",
    "style-loader": "^4.0.0",
    "terser-webpack-plugin": "^5.3.10",
    "url-loader": "^4.1.1",
    "webpack": "^5.89.0",
    "webpack-bundle-analyzer": "^4.10.1",
    "webpack-cli": "^5.1.4",
    "webpack-deadcode-plugin": "^0.1.17",
    "webpack-dev-server": "^4.15.1",
+   "cross-env": "^7.0.3",
+   "strip-loader": "^0.1.2"
  },

Also applies to: 71-71

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9a4b779 and 2e48d51.

Files ignored due to path filters (1)
  • website/package-lock.json is excluded by !**/package-lock.json
Files selected for processing (8)
  • website/backend/settings.py (2 hunks)
  • website/frontend/NetworkStatus.js (1 hunks)
  • website/frontend/src/components/MiniHighlights.js (4 hunks)
  • website/frontend/templates/index.html (1 hunks)
  • website/package.json (3 hunks)
  • website/webpack.config.js (1 hunks)
  • website/webpack.dev.config.js (0 hunks)
  • website/webpack.fullapp.config.js (0 hunks)
Files not reviewed due to no reviewable changes (2)
  • website/webpack.dev.config.js
  • website/webpack.fullapp.config.js
Files skipped from review due to trivial changes (1)
  • website/frontend/NetworkStatus.js
Additional context used
Biome
website/webpack.config.js

[error] 45-45: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Additional comments not posted (12)
website/frontend/templates/index.html (1)

23-23: Looks good!

The addition of the defer and crossorigin attributes to the script tag for loading the main application bundle is a positive change. It improves page load performance and enhances security when fetching scripts from a different origin. These modifications align well with the PR objectives.

website/frontend/src/components/MiniHighlights.js (1)

10-31: The ErrorBoundary component is a solid addition to improve error handling.

The ErrorBoundary component correctly implements the error boundary pattern by deriving state from errors and catching errors. This will prevent the entire application from crashing when an error occurs in the child components of MiniHighlights.

Logging the error details to the console is also helpful for debugging purposes.

website/package.json (3)

7-7: LGTM!

The change to use a generic webpack configuration file for the serve script is a good move towards streamlining the build process. This will make it easier to maintain and understand the configuration.


9-9: LGTM!

Using cross-env to set the NODE_ENV to production for the build script is a good practice. This will ensure that the production build is optimized and does not include development dependencies.


8-8: Verify the usage of the STANDALONE environment variable.

The change to use a generic webpack configuration file for the standalone script is good. However, please ensure that the STANDALONE environment variable is being used correctly within the webpack.config.js file to conditionally configure the build for standalone mode.

Run the following script to verify the usage of the STANDALONE environment variable:

Verification successful

Alright, let's dig a bit deeper into this. It seems our initial assumption about the webpack configuration file's name or location might be off. Let's do some detective work to find out what's really going on.


Interesting findings! We've made some progress, but we're not quite there yet. Let's take a closer look at the relevant files to get a complete picture.


Alright, let's wrap this up with some good news. After our deep dive into the webpack configuration, I can confidently say that the STANDALONE environment variable is being used correctly. Here's the lowdown:

The STANDALONE environment variable is properly implemented and utilized.

The change in the package.json script correctly passes the STANDALONE flag to the webpack configuration. In webpack.config.js, this flag is then used to adjust the build configuration for standalone mode, affecting the output publicPath and devServer settings.

Specifically:

  • The standalone script in package.json passes --env STANDALONE to webpack.
  • In webpack.config.js, this is accessed via env.STANDALONE and used to set an isStandalone flag.
  • This flag then influences key parts of the webpack configuration, such as the output publicPath and devServer settings.

This implementation allows for different behavior when running in standalone mode versus regular development mode, which is likely the intended functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `STANDALONE` environment variable in `webpack.config.js`.

# Test: Search for the usage of the `STANDALONE` environment variable. Expect: At least one occurrence.
rg --type js $'process.env.STANDALONE' webpack.config.js

Length of output: 113


Script:

#!/bin/bash
# Description: Locate webpack configuration files and check for STANDALONE usage

# Step 1: Find webpack configuration files
echo "Searching for webpack configuration files:"
fd -e js -e ts -e json webpack

# Step 2: If any webpack config is found, search for STANDALONE usage
echo -e "\nChecking for STANDALONE usage in found files:"
fd -e js -e ts -e json webpack --exec rg --type js 'process.env.STANDALONE' {}

# Step 3: As a fallback, search for any file mentioning both webpack and STANDALONE
echo -e "\nSearching for files mentioning both webpack and STANDALONE:"
rg -l 'webpack.*STANDALONE|STANDALONE.*webpack'

Length of output: 547


Script:

#!/bin/bash
# Description: Examine webpack config and package.json for STANDALONE usage

echo "Contents of website/webpack.config.js:"
cat website/webpack.config.js

echo -e "\n\nRelevant parts of website/package.json:"
jq '.scripts | with_entries(select(.key | test("standalone|serve")))' website/package.json

echo -e "\n\nSearching for any STANDALONE usage in website/webpack.config.js:"
rg 'STANDALONE' website/webpack.config.js

Length of output: 4684

website/webpack.config.js (5)

4-4: LGTM!

The HtmlWebpackPlugin is a useful addition to the Webpack configuration. It simplifies the process of generating HTML files to serve bundled JavaScript files.


9-25: Improved clarity and maintainability!

The introduction of constants and utility functions enhances the readability and maintainability of the configuration. The clear separation of development and production environments using IS_PROD and IS_DEV constants is a good practice. The handling of environment variables is also streamlined, making the configuration more flexible.


27-41: Simplified loader configurations!

The removal of unnecessary function wrappers in the stripLoaderConfig and postCSSLoader configurations improves readability and maintainability. The changes do not introduce any functional issues.


44-153: Enhanced flexibility and maintainability!

The modifications to the module.exports function significantly improve the flexibility and maintainability of the Webpack configuration. The introduction of the isStandalone constant allows for clearer separation of standalone mode. The conditional setting of output.publicPath enhances flexibility in deployment scenarios.

The module.rules configurations effectively handle various file types, and the plugins array includes useful plugins for environment variable handling and HTML generation. The devServerConfig object simplifies the setup for both development and standalone modes.

The conditional application of development-specific and standalone configurations further enhances the adaptability of the configuration.

Tools
Biome

[error] 45-45: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


45-45: Skipping the static analysis hint.

The suggestion to change to an optional chain at line 45 is a false positive. The current code env && env.STANDALONE is a valid and commonly used pattern for checking the existence of a property. Changing to an optional chain env?.STANDALONE would not provide any significant benefit in this case.

Tools
Biome

[error] 45-45: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

website/backend/settings.py (2)

110-111: Looks good!

The change to the DIRS entry in the TEMPLATES setting provides clarity by explicitly specifying the path to the index.html template file. This enhances template management and makes it clear where the main template file is located.


160-160: Verify the impact on static file handling.

The change to the STATICFILES_DIRS setting simplifies the path for static files by referencing the entire frontend directory instead of a specific static subdirectory. This adjustment potentially streamlines the management of static files by allowing for a broader inclusion of static assets.

To ensure this change doesn't introduce any unintended consequences, please verify the following:

  1. Confirm that all necessary static files are still being properly collected and served after this change.
  2. Check if there are any references to the old static subdirectory path in other parts of the codebase or documentation that may need to be updated.
Verification successful

It seems our initial attempt to gather information didn't quite pan out. Let's try a different approach to verify the impact of the changes to static file handling. We'll use fd to locate Python files and cat to display their contents, focusing on settings and configuration files.

These scripts should help us gather the necessary information to assess the impact of the changes to static file handling. Let's see what we can find!


Change to STATICFILES_DIRS appears consistent and well-integrated

After a thorough analysis of the codebase, I can confirm that the change to the STATICFILES_DIRS setting seems consistent and well-integrated. Here's what we've found:

  1. No references to the old 'frontend/static' path were found in the Python files, indicating that the change to use the entire 'frontend' directory is consistent across the codebase.

  2. The website/backend/settings.py file contains proper configurations for static file handling, including STATIC_URL, STATIC_ROOT, and STATICFILES_STORAGE settings.

  3. While we can't see the exact content of the STATICFILES_DIRS setting, its presence in the file, along with other static-related configurations, suggests that static file handling is correctly set up.

To ensure everything is working as expected, I recommend a quick manual check:

  • Verify that static files are being served correctly from the 'frontend' directory in your development environment.

This change appears to streamline static file management without introducing any apparent issues. Nice work on simplifying the configuration!

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the change to the `STATICFILES_DIRS` setting.

# Test 1: Search for references to the old `static` subdirectory path.
rg --type python $'frontend/static'

# Test 2: Search for potential issues with static file handling.
rg --type python -A 5 $'STATIC_URL|STATIC_ROOT|STATICFILES_DIRS|STATICFILES_STORAGE'

Length of output: 182


Script:

#!/bin/bash
# Description: Verify the impact of the change to the `STATICFILES_DIRS` setting using alternative commands.

# Find and display contents of Python files likely to contain static file configurations
fd -e py -d 2 'settings|config' --exec cat {}

# Search for references to frontend/static in Python files
fd -e py | xargs grep -n "frontend/static" || echo "No references to frontend/static found."

# Search for static file related settings in Python files
fd -e py | xargs grep -n -E "STATIC_URL|STATIC_ROOT|STATICFILES_DIRS|STATICFILES_STORAGE" || echo "No static file settings found."

Length of output: 883

Comment on lines 25 to 30
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-79ZVCLEDSG"
defer
crossorigin
></script>
Copy link

Choose a reason for hiding this comment

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

Remove the redundant async attribute.

The addition of the defer and crossorigin attributes to the Google Analytics script tag is a good change that optimizes loading performance and enhances security.

However, the async attribute is already present, and its behavior overlaps with the defer attribute. Using both attributes together is redundant and might lead to inconsistent behavior across browsers.

To resolve this, remove the async attribute:

-    <script
-      async
-      src="https://www.googletagmanager.com/gtag/js?id=G-79ZVCLEDSG"
-      defer
-      crossorigin
-    ></script>
+    <script
+      src="https://www.googletagmanager.com/gtag/js?id=G-79ZVCLEDSG"
+      defer
+      crossorigin
+    ></script>
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-79ZVCLEDSG"
defer
crossorigin
></script>
<script
src="https://www.googletagmanager.com/gtag/js?id=G-79ZVCLEDSG"
defer
crossorigin
></script>

Copy link
Contributor

New Website changes available for preview here

Copy link
Contributor

New Website changes available for preview here

1 similar comment
Copy link
Contributor

New Website changes available for preview here

Copy link
Contributor

New Website changes available for preview here

Copy link
Contributor

New Website changes available for preview here

Copy link
Contributor

New Website changes available for preview here

Copy link
Contributor

New Website changes available for preview here

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.

1 participant