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

Creating banner script in js agent #449

Merged
merged 13 commits into from
Jan 3, 2025
Merged

Conversation

swoopertr
Copy link
Contributor

Describe your changes

Creating a banner agent script,
refactor code that gets all configurable values from the backend.
adding up style fixes.
Briefly describe the changes you made and their purpose.

Issue number

#421
Mention the issue number(s) this PR addresses (e.g., #123).

Please ensure all items are checked off before requesting a review:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • I made sure font sizes, color choices etc are all referenced from the theme.
  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.

@swoopertr swoopertr requested a review from erenfn December 31, 2024 10:46
Copy link
Contributor

coderabbitai bot commented Dec 31, 2024

Walkthrough

This pull request encompasses modifications across multiple components of the application, including backend configuration, route handling, model definitions, and frontend helper utilities. The changes primarily focus on environment configuration, database model adjustments, route method modifications, and the removal of several frontend helper scripts. The updates aim to enhance the application's flexibility, improve data handling, and streamline the codebase.

Changes

File/Path Change Summary
backend/.env Changed DEV_DB_HOST from db to localhost
backend/src/controllers/guidelog.controller.js Modified response status code in addGuideLog from 201 to 200
backend/src/models/Popup.js Updated content field type to DataTypes.STRING(1024)
backend/src/routes/guide.routes.js Changed /get_incomplete_guides_by_url route from GET to POST
backend/src/server.js Added CORS preflight request middleware
frontend/helper/* Removed banner.js, links.js, main.js, popup.js, tour.js
frontend/src/scenes/settings/CodeTab/CodeTab.jsx Added agentUrl state and related functionality
jsAgent/banner.js Introduced new banner functionality with bw.banner object
jsAgent/links.js Enhanced links module with new methods and styling
jsAgent/main.js Updated server endpoints and added guide logging functionality
jsAgent/popup.js Refactored popup modal implementation

Sequence Diagram

sequenceDiagram
    participant Client
    participant Server
    participant PopupModel
    participant GuideLogController

    Client->>Server: POST /get_incomplete_guides_by_url
    Server->>GuideLogController: Process request
    GuideLogController-->>Server: Return guide logs
    Server-->>Client: Respond with guide logs (Status 200)

    Client->>Server: Create popup
    Server->>PopupModel: Validate content (max 1024 chars)
    PopupModel-->>Server: Validation result
    Server-->>Client: Respond with popup details
Loading

Possibly Related PRs

Suggested Reviewers

  • erenfn
  • gorkem-bwl

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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. (Beta)
  • @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.

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

🔭 Outside diff range comments (1)
jsAgent/popup.js (1)

Line range hint 84-105: Parameters btnEvent and btnlink are well-handled, but watch for expansions.

Different logic branches handle navigation vs. no action. A new feature could require further branching—like adding meatballs on top. Consider a more extensible approach, e.g. a config object for future expansions.

🧹 Nitpick comments (11)
jsAgent/banner.js (3)

1-2: Debugging log found.

Your code is stepping on stage, microphone in hand. The console log ensures the banner script is recognized. If you plan on leaving it in production, make sure it doesn’t clutter the console. Could be best to remove or demote to debug level.


3-12: HTML template is structured well.

The banner styles are on point and keep that design fresh, just like dropping a new verse. Watch out for repeated width statements—a single mention might suffice to keep your code shorter than a rap freestyle. Also ensure you handle dynamic positions gracefully across various screen sizes.


19-35: Putting the banner HTML in the DOM.

The method replacing placeholders shows strong hustle. However, your repeated usage of new RegExp('{{...}}', 'g') could be replaced by literal patterns /{{...}}/g. This is a known best practice for clarity and performance—like clearing the stage so your rap is heard clearly.

- temp_html = temp_html.replace(new RegExp('{{backGroundColor}}', 'g'), item.backgroundColor);
+ temp_html = temp_html.replace(/{{backGroundColor}}/g, item.backgroundColor);

(Similar for the other placeholders.)

🧰 Tools
🪛 Biome (1.9.4)

[error] 25-25: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 26-26: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 27-27: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 28-28: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 29-29: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)

jsAgent/popup.js (3)

63-64: Send data call is correct, but confirm error handling.

Awaiting bw.data.sendData is great, but have a fallback if the request fails—like a napkin for sauce spills.


67-70: Simplify the header’s absolute positioning.

The SVG close button is absolutely positioned. Keep an eye on different screen sizes to ensure it doesn't float into the spaghetti. A minor responsiveness check might help.


76-83: Use consistent naming for param "text" vs. "btnText."

addButton uses text as a param, though other references mention “actionButtonText.” A single naming convention might save new devs from tripping mid-lyric.

frontend/src/scenes/settings/CodeTab/CodeTab.jsx (3)

60-62: Consistent naming for event handlers across fields.

handleAgentUrlChange parallels handleUrlChange. Keep it symmetrical for clarity—like consistent chef methods in the kitchen.


132-140: Reflected the same Save logic for agent URL?

The new “Agent Base URL” uses the same Save button. Consider a separate or combined approach if you’d like different server responses or validations—like dividing sauce storage to ensure each jar is saved properly.


145-145: Revamp the copy instruction.

The mention “Base API URL” is correct. It might help to clarify that the snippet also includes the “Agent Base URL,” so users remember to tweak both for their final website—like reminding them to add both sauce and noodles in the recipe.

jsAgent/main.js (2)

113-113: Minor quibble: method name “getData” is somewhat vague.

Consider a more descriptive name (e.g. “getGuideData” or “fetchGuideLogs”), so your devs don’t toss the sauce across the kitchen in confusion.


117-136: sendData method is crisp, but handle potential network failures.

You might want to wrap your fetch call in a try-catch block or handle non-200 statuses. No one wants to see sauce spilled over a 500 error.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dcb99e0 and cc2aad0.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (15)
  • backend/.env (1 hunks)
  • backend/src/controllers/guidelog.controller.js (1 hunks)
  • backend/src/models/Popup.js (1 hunks)
  • backend/src/routes/guide.routes.js (1 hunks)
  • backend/src/server.js (1 hunks)
  • frontend/helper/banner.js (0 hunks)
  • frontend/helper/links.js (0 hunks)
  • frontend/helper/main.js (0 hunks)
  • frontend/helper/popup.js (0 hunks)
  • frontend/helper/tour.js (0 hunks)
  • frontend/src/scenes/settings/CodeTab/CodeTab.jsx (5 hunks)
  • jsAgent/banner.js (1 hunks)
  • jsAgent/links.js (1 hunks)
  • jsAgent/main.js (5 hunks)
  • jsAgent/popup.js (3 hunks)
💤 Files with no reviewable changes (5)
  • frontend/helper/banner.js
  • frontend/helper/links.js
  • frontend/helper/tour.js
  • frontend/helper/popup.js
  • frontend/helper/main.js
✅ Files skipped from review due to trivial changes (1)
  • backend/.env
🧰 Additional context used
🪛 Biome (1.9.4)
jsAgent/banner.js

[error] 25-25: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 26-26: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 27-27: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 28-28: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)


[error] 29-29: Use a regular expression literal instead of the RegExp constructor.

Regular expression literals avoid some escaping required in a string literal, and are easier to analyze statically.
Safe fix: Use a literal notation instead.

(lint/complexity/useRegexLiterals)

🔇 Additional comments (18)
backend/src/routes/guide.routes.js (1)

7-7: Route method changed successfully!

Palms are sweaty, but no regrets here, homie. Changing the route to POST is well-aligned with the existing logic and ensures consistency across the endpoints. Good job keeping it DRY so your code doesn’t get spaghetti-stained.

backend/src/controllers/guidelog.controller.js (1)

12-12: Status code downgraded to 200?

Arms are weak, but let's keep the code strong. Using 200 implies a general success; 201 might be more semantically correct when a resource is newly created. If your requirements say it's just “OK,” we’re good. Otherwise, double-check you’re not missing that “Created” nuance.

backend/src/server.js (1)

31-31: CORS preflight requests enabled.

Knees may be knocking, but adding app.options('*', cors()) is a wise move to handle preflight checks properly, so your cross-origin requests won’t be vomiting 403 errors. This fosters a more open and secure environment.

jsAgent/banner.js (3)

14-18: Clean banner initialization.

Love how it’s short and to the point, no extra bars spitting confusion. This organizes the code effectively, so no sweaty confusion remains. Keep your script performing with minimal overhead.


36-47: User interaction is on point.

When the close icon is clicked, logging the user’s action is a dope idea. This ensures the track data gets properly recorded as the user bails on the banner. Just be sure the aggregator is tested well so you don’t miss a beat.


49-53: Immediate invocation for initialization.

Mom’s spaghetti might be short and sweet, but your IIFE is a neat finishing touch. This ensures the banner logic loads right away and runs seamlessly. No final bar needed; the code just ends with style.

backend/src/models/Popup.js (1)

107-107: Extend string length to accommodate more sauce.

Changing DataTypes.STRING to DataTypes.STRING(1024) is a solid way to handle heftier content. This update allows for more textual data without compromising model integrity—like making extra room for mom’s spaghetti.

jsAgent/popup.js (3)

34-36: Ensure that overlay creation completes before modal addition.

Marking init as async and awaiting addModal() is a smooth approach. This prevents visual flickers by guaranteeing the overlay is properly in place—like serving the plate before pouring the sauce.


40-40: Overlay styling might hamper some user interactions.

Setting the overlay’s background to rgba(0, 0, 0, 0.x) with a z-index of 999 could accidentally overshadow certain site elements. Confirm that this z-index doesn’t hamper essential UI interactions—like ensuring your mom’s spaghetti is still clickable.


Line range hint 42-59: Watch for the dynamic usage of default options.

You're merging custom popup options with popupDefaultOptions, then constructing the modal. Ensure that your logic for merging doesn’t inadvertently override needed fields—like mixing too much water into the sauce.

frontend/src/scenes/settings/CodeTab/CodeTab.jsx (3)

12-13: Introducing a new state is a savoury move.

Variables serverUrl and agentUrl keep them flexible. This sets a strong foundation for dynamic agent addresses—like switching sauces in your recipe mid-cooking.


89-90: Dynamically embedding the agent URL prevents stale references.

Using window.bwAgentBaseUrl is an excellent improvement. This ensures less spaghetti-coded constants if you need varying agent endpoints.


119-119: Labelling consistency for “Server Base URL.”

Renaming from “Server URL” to “Server Base URL” clarifies usage. We’ll keep our labels as coherent as possible—like plating consistently sized pasta portions.

jsAgent/main.js (3)

2-4: Dynamic endpoints keep your script fresh, no more stale sauce.

Using window.bwApiBaseUrl for BW_SERVER_ENDPOINT_BASE, BW_GET_GUIDE_LOG_URL, and BW_ADD_GUIDE_LOG_URL is a flexible approach that eases environment-based changes.


39-39: Refined script state checks for loading.

You consolidated readyState checks gracefully. That helps you avoid half-baked states—like pasta that’s still crunchy.


88-96: Establishing a shared GuideType constant.

This is a helpful enumeration that clarifies usage. It’s easier to read than magic numbers, offering that final garnish on your spaghetti dish.

jsAgent/links.js (2)

13-13: Use of margin-right is acceptable
Replacing padding-right with margin-right is a valid styling choice and can often provide more consistent layout spacing across parent containers.


14-14: Confirm removal of clip path
Looks like the clipPath was removed here. If advanced clipping was previously required, ensure this won’t visually affect any SVG overflows or interactions. Otherwise, everything seems fine.

erenfn
erenfn previously approved these changes Dec 31, 2024
@erenfn erenfn merged commit 84f2039 into develop Jan 3, 2025
2 checks passed
@erenfn erenfn deleted the creating-banner-script-in-jsAgent branch January 16, 2025 23:51
@coderabbitai coderabbitai bot mentioned this pull request Jan 28, 2025
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.

2 participants