Skip to content

Comments

Feature: create reusable request card - added utility functions#976

Merged
iamitprakash merged 6 commits intoRealDevSquad:developfrom
AnujChhikara:feature/create-reusable-request-card-01
May 24, 2025
Merged

Feature: create reusable request card - added utility functions#976
iamitprakash merged 6 commits intoRealDevSquad:developfrom
AnujChhikara:feature/create-reusable-request-card-01

Conversation

@AnujChhikara
Copy link
Contributor

@AnujChhikara AnujChhikara commented Apr 14, 2025

Date: 14 April 2025

Developer Name: @AnujChhikara


Issue Ticket Number

Description

  • This PR refactors the codebase by extracting reusable DOM creation logic and utility functions related to request handling (like fetching extension request details) into separate helper modules. This improves code modularity, readability, and reuse across different request types.

Changes made:

  • Moved createElement, createActionContainer, and related UI logic to utils.js

  • Moved data fetching logic like getExtensionRequestDetails to utils.js

  • Updated createRequestCardComponent to use these new helpers

  • Test PR test: add test for request card component #994

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1
  • Note: these are final Changes after all the PRs of this request card merged
  • Extension Request
brave_Wvd4QGQdA8.mp4
brave_5ZdF3b4Crh.mp4
brave_6dHlJo2kGe.mp4
  • OOO and Onboarding Requests
brave_cMuGGLoJBQ.mp4
brave_UHzBMcVK3p.mp4

Test Coverage

Screenshot 1

image
image

Additional Notes

Test PR: #994

@coderabbitai
Copy link

coderabbitai bot commented Apr 14, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Summary by CodeRabbit

  • New Features
    • Enhanced the display of request details with refined date and time formatting.
    • Introduced smoother, interactive UI transitions including loading animations, expandable panels, and animated card removals.
    • Added visual feedback cues for successful and error outcomes during user interactions.

Walkthrough

A new JavaScript utility module has been added to the request-card component. This module includes multiple helper functions for handling date and time formatting, assigning color codes based on deadlines, and managing user interface interactions such as loading spinners, accordion toggles, and visual highlights. Additionally, asynchronous functions are implemented to update request statuses and animate card removals, with supplementary methods generating structured HTML elements for request details.

Changes

File Change Summary
components/request-card/utils.js Added functions for converting time units, formatting dates, managing UI elements (loading spinner, accordion panels, success/error highlights), updating request statuses asynchronously, and animating card removals.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant UI as Web UI
    participant Utils as Request-Card Utils
    participant S as Server

    U->>UI: Initiate request status update
    UI->>Utils: Call updateRequestStatus({id, body, type})
    Utils->>S: Send update request (async)
    S-->>Utils: Return update response
    alt Success
      Utils->>UI: Call showSuccessHighlight()
      UI->>Utils: Call removeCard() to animate removal
    else Error
      Utils->>UI: Call showErrorHighlight()
    end
Loading

Poem

I'm a rabbit hopping with delight,
New code helpers shining bright,
From dates to spinners, all in a row,
UI and requests now smoothly flow.
A joyful leap in code I share – hop, hop, hop!


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@AnujChhikara AnujChhikara self-assigned this Apr 14, 2025
@AnujChhikara AnujChhikara marked this pull request as ready for review April 14, 2025 11:42
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: 7

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 42858e2 and 5c3607c.

📒 Files selected for processing (1)
  • components/request-card/utils.js (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
components/request-card/utils.js (1)
extension-requests/script.js (2)
  • newDeadlineDays (521-525)
  • isNewDeadLineCrossed (505-506)
🪛 Biome (1.9.4)
components/request-card/utils.js

[error] 83-83: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 87-87: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

🔇 Additional comments (8)
components/request-card/utils.js (8)

4-14: Verify the logic for wasDeadlineBreached.
The expression const wasDeadlineBreached = createdTime > deadline; indicates the deadline was already passed relative to createdTime. This might be correct if createdTime represents the current time, but please confirm it's the intended comparison. If deadline is supposed to be compared with the current time (Date.now()), you may need a different approach.


37-43: Implementation of formatToDateOnly looks good.
The function outputs the standard ISO YYYY-MM-DD format, making it suitable for date input fields and general processing. No immediate issues found here.


44-51: getFormEntries is straightforward and functional.
This utility correctly maps FormData entries into an object, a common need in web forms. No concerns.


52-65: addLoadingSpinner returning a cleanup function is a nice design.
It neatly encapsulates the spinner logic and makes removal straightforward. No further changes needed.


86-88: expandAccordionPanel is straightforward.
No major issues. Just remember to adjust line 87 for the template literal change as indicated.

🧰 Tools
🪛 Biome (1.9.4)

[error] 87-87: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


97-122: Confirm the existence of API_BASE_URL.
updateRequestStatus relies on API_BASE_URL and presumably window.API_BASE_URL or an imported constant. Ensure this variable is defined before usage, and confirm the endpoint paths (extension-requests vs. requests) are correct.


123-163: Ensure addDelay(800) is defined and accessible.
The removeCard function references addDelay(800) before initiating the final animation. Verify that addDelay is a globally or locally defined helper. If it's external, consider including it in this file or an import.


317-457: createDateContainer logic appears comprehensive.
The function effectively handles both extension and request scenarios. No immediate issues stand out.

@MayankBansal12
Copy link
Member

Hello @AnujChhikara,
The PR doesn't include any test changes, so which tests does the coverage screenshot include? Also, are the screen recordings included above all places where the request card is being used?

@AnujChhikara
Copy link
Contributor Author

AnujChhikara commented Apr 14, 2025

The PR doesn't include any test changes, so which tests does the coverage screenshot include? Also, are the screen recordings included above all places where the request card is being used?

Just setting up the card component and utils here — UPDATE the screenshot of tests after the test pr merged with the coverage.

@AnujChhikara AnujChhikara requested a review from yesyash April 15, 2025 18:02
@iamitprakash iamitprakash merged commit 7500937 into RealDevSquad:develop May 24, 2025
5 checks passed
@AnujChhikara AnujChhikara deleted the feature/create-reusable-request-card-01 branch May 25, 2025 15:38
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.

4 participants