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: enhance demo data loading #1574

Merged
merged 4 commits into from
Mar 5, 2025

Conversation

melinoix
Copy link
Contributor

@melinoix melinoix commented Feb 28, 2025

The demo data domain is created always with the same name. If the domain already exists a popup will say that demo data is already existing.

Additionally, during loading of data, an animation is shown.

Summary by CodeRabbit

  • New Features

    • Consistent Demo Data: The demo data import process now uses a simplified, consistent identifier.
    • Localized Notifications: Added English and French messages to notify users when demo data has already been imported.
    • Enhanced User Experience: The sidebar shows a loading spinner and provides clearer error notifications during demo operations.
  • Bug Fixes

    • Improved error handling for demo data loading, distinguishing between different error types.

Copy link
Contributor

coderabbitai bot commented Feb 28, 2025

Walkthrough

This update modifies both the backend and frontend. In the backend, the import_dummy_domain method in the FolderViewSet now assigns a static domain name ("DEMO") instead of appending a timestamp, and error logging has been adjusted to exclude traceback information. On the frontend, new message entries for demo data import status have been added in both English and French localization files. Additionally, the SideBar.svelte component now implements a loading state with enhanced error handling and a conditional rendering of a loading spinner during asynchronous demo domain import operations.

Changes

File(s) Summary
backend/core/views.py Simplified import_dummy_domain in FolderViewSet (static "DEMO" instead of timestamp) and modified error logging.
frontend/messages/en.json, fr.json Added new key demoDataAlreadyImported for English and French translations providing user feedback for demo data importation.
frontend/src/lib/components/SideBar/... Introduced a writable loading store, improved error handling in loadDemoDomain, and added conditional rendering for a LoadingSpinner.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SideBar
    participant Backend
    User->>SideBar: Request demo domain import
    SideBar->>SideBar: Set loading = true
    SideBar->>Backend: Fetch demo domain data
    Backend-->>SideBar: Respond with success or error
    alt Success
        SideBar->>SideBar: Trigger flash success message
    else Failure
        SideBar->>SideBar: Trigger flash error message
    end
    SideBar->>SideBar: Set loading = false
Loading

Possibly related PRs

Suggested reviewers

  • ab-smith
  • Mohamed-Hacene

Poem

I’m a bunny, soft and keen,
Hoping through these lines so clean,
A static “DEMO” now rings true,
And loading spinners show us through,
Hopping on code with carrot cheer!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 generate docstrings to generate docstrings for this 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
Contributor

@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: 0

🧹 Nitpick comments (2)
backend/core/views.py (2)

2493-2493: Simplify the static string assignment in import_dummy_domain.
The line

domain_name = f"DEMO"

uses an f-string even though there are no placeholders. For clarity and to satisfy style guidelines, please remove the extraneous f prefix (i.e. use "DEMO" instead).

[minor]

🧰 Tools
🪛 Ruff (0.8.2)

2493-2493: f-string without any placeholders

Remove extraneous f prefix

(F541)


4476-4476: Ensure explicit import of Finding in FindingViewSet.status.
The code returns

return Response(dict(Finding.Status.choices))

but static analysis indicates that Finding may be undefined or only available via a star import. For robustness and clarity, explicitly import the Finding model at the top of this file rather than relying on ambiguous star imports.

🧰 Tools
🪛 Ruff (0.8.2)

4476-4476: Finding may be undefined, or defined from star imports

(F405)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b82801 and 51ea4eb.

📒 Files selected for processing (4)
  • backend/core/views.py (2 hunks)
  • frontend/messages/en.json (2 hunks)
  • frontend/messages/fr.json (2 hunks)
  • frontend/src/lib/components/SideBar/SideBar.svelte (4 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
backend/core/views.py

2493-2493: f-string without any placeholders

Remove extraneous f prefix

(F541)


4476-4476: Finding may be undefined, or defined from star imports

(F405)

🪛 GitHub Actions: Backend Linters
backend/core/views.py

[error] 1-1: Ruff formatting check failed. 1 file would be reformatted. Please run 'ruff format' to fix code style issues in this file.

⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: migrations-check (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: build (3.12)
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: test (3.12)
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: enterprise-startup-docker-compose-test
🔇 Additional comments (8)
frontend/messages/en.json (1)

1175-1175: New localization message added for demo data import status.

This message will inform users when they attempt to import demo data that has already been imported, preventing redundant imports and improving user experience.

frontend/messages/fr.json (1)

1165-1165: French translation for demo data import status message.

The French translation has been properly added for the demo data import message, maintaining consistent internationalization.

frontend/src/lib/components/SideBar/SideBar.svelte (6)

7-7: Added necessary imports for new functionality.

The imports for the writable store and LoadingSpinner component are needed for the loading animation feature implementation.

Also applies to: 22-22


223-224: Added loading state management.

A writable store is created to track loading state, which will be used to display the loading animation during demo data import.


226-226: Implementing loading state control.

Loading state is set to true at the start of the import process and reset to false at all exit points (both success and error paths), ensuring the loading spinner is only displayed while the import is in progress.

Also applies to: 235-235, 247-247


229-233: Enhanced error handling for demo data import.

The error handling now differentiates between a 500 status code (which indicates the demo data is already imported) and other errors, displaying an appropriate message in each case.


238-239: Improved success message handling.

The success message is now sent to the flash store, providing consistent feedback to the user when the demo data is successfully imported.


288-294: Added loading spinner overlay during import.

This conditional rendering block displays a loading spinner when the import process is active, providing visual feedback to the user and improving the overall user experience.

@nas-tabchiche nas-tabchiche changed the title Fix: Avoid multiple loads of demo data + feat: loading animation during import of demo data feat: enhance demo data loading Feb 28, 2025
Copy link
Collaborator

@eric-intuitem eric-intuitem left a comment

Choose a reason for hiding this comment

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

LGTM

and avoid ugly error message in console
Copy link
Contributor

@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: 0

🧹 Nitpick comments (1)
backend/core/views.py (1)

2493-2493: Remove unnecessary f-string prefix

The string "DEMO" doesn't contain any variables or expressions to interpolate, so the f prefix is redundant.

-        domain_name = f"DEMO"
+        domain_name = "DEMO"
🧰 Tools
🪛 Ruff (0.8.2)

2493-2493: f-string without any placeholders

Remove extraneous f prefix

(F541)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51ea4eb and 5af84fb.

📒 Files selected for processing (4)
  • backend/core/views.py (2 hunks)
  • frontend/messages/en.json (1 hunks)
  • frontend/messages/fr.json (1 hunks)
  • frontend/src/lib/components/SideBar/SideBar.svelte (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • frontend/messages/en.json
  • frontend/messages/fr.json
  • frontend/src/lib/components/SideBar/SideBar.svelte
🧰 Additional context used
🪛 Ruff (0.8.2)
backend/core/views.py

2493-2493: f-string without any placeholders

Remove extraneous f prefix

(F541)

⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: startup-functional-test (3.12)
  • GitHub Check: startup-docker-compose-test
  • GitHub Check: enterprise-startup-functional-test (3.12)
  • GitHub Check: enterprise-startup-docker-compose-test
  • GitHub Check: build (3.12)
  • GitHub Check: enterprise-functional-tests (3.12, chromium)
  • GitHub Check: test (3.12)
  • GitHub Check: functional-tests (3.12, chromium)
  • GitHub Check: Analyze (python)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
backend/core/views.py (3)

2493-2523: Solid implementation for preventing duplicate demo data imports

The change from dynamic timestamps to a static domain name ("DEMO") effectively enables the application to prevent multiple imports of the same demo data, as mentioned in the PR objectives. This is a good approach since it allows the frontend to easily check if the demo data already exists.

🧰 Tools
🪛 Ruff (0.8.2)

2493-2493: f-string without any placeholders

Remove extraneous f prefix

(F541)


2512-2512: Consider the impact of removing exception tracebacks

Removing exc_info=True from the logger call means that stack traces won't be included in the logs. While this makes logs cleaner, it might make troubleshooting more difficult if unexpected issues occur with JSON parsing.

Is this change intentional? Consider whether this information might be useful for debugging in production environments.


2518-2518: Consider the impact of removing exception tracebacks

Similar to the previous comment, removing exc_info=True from this general exception logger will result in less detailed error information in the logs.

Confirm that this is an intentional change to reduce log verbosity rather than an accidental omission.

@Mohamed-Hacene Mohamed-Hacene merged commit ed1fce6 into main Mar 5, 2025
21 checks passed
@Mohamed-Hacene Mohamed-Hacene deleted the avoid-multiple-loads-of-demo-data-clean branch March 5, 2025 11:48
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants