Skip to content

Conversation

ZendeAditya
Copy link
Contributor

Date:

Developer Name: aditya-zende

Issue Ticket Number

#2399

Description

Change a state field in the request to status.

change all required occourances of state to status in frontend

Documentation Updated?

  • Yes
  • No

Under Feature Flag

  • Yes
  • No

Database Changes

  • Yes
  • No

Breaking Changes

  • Yes
  • No

Development Tested?

  • Yes
  • No

Screenshots

Screenshot 1

Test Coverage

Screenshot 1

Additional Notes

Copy link

coderabbitai bot commented May 10, 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

    • Added a chevron icon next to the user image in the navigation bar when the "dev" URL flag is enabled.
    • The user dropdown menu now closes when clicking outside, but only if the "dev" flag is active.
    • Request status handling in the UI adapts to different environments based on the "dev" flag, supporting both "state" and "status" fields.
  • Tests

    • Enhanced navbar tests to verify chevron icon visibility and dropdown behavior based on the "dev" feature flag.

Walkthrough

The changes introduce conditional behavior throughout the navbar and request management scripts based on a dev flag in the URL. When the flag is active, a chevron icon appears in the navbar, and the dropdown menu gains a click-outside-to-close feature. Request status handling is also unified to support different API schemas depending on the flag.

Changes

File(s) Change Summary
tests/navbar/navbar.test.js Enhanced tests to check for chevron icon and dropdown close-on-click-outside behavior, both conditional on the dev flag in the URL.
navbar.global.js Added logic to display a chevron icon next to the user image in the navbar when dev=true is present in the URL.
userLogin.js Added logic to close the user dropdown on outside click only when the dev flag is set in the URL.
requests/script.js Refactored all request status handling to use either status or state keys based on the isDev flag, supporting two API schemas.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser
    participant NavbarScript
    participant UserLoginScript

    User->>Browser: Loads page with or without ?dev=true
    Browser->>NavbarScript: Initialize navbar
    NavbarScript->>NavbarScript: Check URL for dev flag
    alt dev flag is true
        NavbarScript->>Browser: Render user image + chevron icon
    else dev flag is false
        NavbarScript->>Browser: Render user image only
    end
    User->>UserLoginScript: Clicks user info
    UserLoginScript->>UserLoginScript: Toggle dropdown
    User->>Browser: Clicks outside dropdown
    UserLoginScript->>UserLoginScript: If dev flag, close dropdown
Loading
sequenceDiagram
    participant Browser
    participant RequestsScript
    participant API

    Browser->>RequestsScript: Load requests page
    RequestsScript->>RequestsScript: Check URL for dev flag
    RequestsScript->>API: Fetch requests
    API-->>RequestsScript: Return requests with 'state' or 'status'
    RequestsScript->>RequestsScript: Use appropriate key for status
    RequestsScript->>Browser: Render request cards with correct status
Loading

Possibly related PRs

Suggested reviewers

  • AnujChhikara
  • MayankBansal12

Poem

A chevron appears when dev is near,
Dropdowns now close if you click elsewhere,
Status or state, the code knows the fate,
With flags in the URL, new features await!
🐇✨


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.

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 comments (1)
requests/script.js (1)

592-592: 🧹 Nitpick (assertive)

Consider using the dynamic key in the initial request.

The initial call to renderRequestCards uses a hardcoded state parameter rather than the dynamic key based on isDev that's used elsewhere.

-renderRequestCards({ state: statusValue, sort: sortByValue });
+renderRequestCards({ [isDev ? 'status' : 'state']: statusValue, sort: sortByValue });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 958860d and 77053ea.

⛔ Files ignored due to path filters (1)
  • images/chevron-down.svg is excluded by !**/*.svg
📒 Files selected for processing (4)
  • __tests__/navbar/navbar.test.js (2 hunks)
  • navbar.global.js (2 hunks)
  • requests/script.js (8 hunks)
  • userLogin.js (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
__tests__/navbar/navbar.test.js (3)
navbar.global.js (2)
  • devFlag (2-2)
  • chevronIcon (3-5)
mock-data/constants.js (1)
  • LOCAL_TEST_PAGE_URL (2-2)
userLogin.js (2)
  • userInfo (33-33)
  • dropdown (32-32)
requests/script.js (2)
task-requests/script.js (1)
  • isDev (21-21)
extension-requests/script.js (1)
  • state (21-23)
🪛 Biome (1.9.4)
__tests__/navbar/navbar.test.js

[error] 143-143: This let declares a variable that is only assigned once.

'dropdownIsActive' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

🔇 Additional comments (10)
navbar.global.js (2)

1-5: Cleanly implemented feature flag for UI changes.

The implementation correctly retrieves the dev flag from URL parameters and conditionally renders the chevron icon based on that flag.


39-39: LGTM for the chevron icon integration.

The insertion of the conditional chevron icon is done correctly using template literals.

__tests__/navbar/navbar.test.js (2)

19-28: Well-structured test for conditional UI elements.

The test correctly checks for the presence/absence of the chevron icon based on the dev flag value.


113-133: Good test coverage for new conditional behavior.

This test effectively verifies the dropdown closing behavior when clicking outside with the dev flag enabled.

userLogin.js (2)

1-2: Clean implementation of feature flag check.

The code correctly retrieves the dev flag from URL parameters.


94-103: Effective conditional dropdown behavior.

The implementation correctly adds a document-level click listener that closes the dropdown when clicking outside, but only when the dev flag is enabled. This matches the behavior tested in the navbar test file.

requests/script.js (4)

6-6: Cleanly implemented feature flag for API requests.

The implementation correctly sets the isDev flag based on the URL parameter.


30-30: Good implementation of conditional field names.

The code correctly uses computed property names to dynamically choose between status and state based on the isDev flag.

Also applies to: 52-52, 63-63


168-169: Good approach for handling both field names.

The code extracts both status and state from the request object and then sets up a variable that conditionally references the appropriate one based on the feature flag.

Also applies to: 178-178


182-182: Consistent usage of conditional field names.

All references to the status field have been updated to use the conditional approach.

Also applies to: 188-188, 425-428, 452-452, 527-528, 532-533

Comment on lines 134 to 157
it('should keep the dropdown open when clicking outside when feature flag is off', async () => {
await page.goto(`${LOCAL_TEST_PAGE_URL}?dev=false`);
await page.waitForSelector('#dropdown');
await page.evaluate(() => {
const dropdown = document.getElementById('dropdown');
if (dropdown && !dropdown.classList.contains('active')) {
dropdown.classList.add('active');
}
});
let dropdownIsActive = await page.evaluate(() => {
const dropdown = document.getElementById('dropdown');
return dropdown?.classList.contains('active') ?? false;
});
expect(dropdownIsActive).toBe(true);
await page.evaluate(() => {
document.body.click();
});
await page.waitForTimeout(200);
const newDropdownHandle = await page.$('#dropdown');
const newDropdownIsActive = await newDropdownHandle.evaluate((el) =>
el.classList.contains('active'),
);
expect(newDropdownIsActive).toBe(true);
});
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use const instead of let for immutable variables.

The variable dropdownIsActive is never reassigned and should use const instead of let.

-    let dropdownIsActive = await page.evaluate(() => {
+    const dropdownIsActive = await page.evaluate(() => {
📝 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
it('should keep the dropdown open when clicking outside when feature flag is off', async () => {
await page.goto(`${LOCAL_TEST_PAGE_URL}?dev=false`);
await page.waitForSelector('#dropdown');
await page.evaluate(() => {
const dropdown = document.getElementById('dropdown');
if (dropdown && !dropdown.classList.contains('active')) {
dropdown.classList.add('active');
}
});
let dropdownIsActive = await page.evaluate(() => {
const dropdown = document.getElementById('dropdown');
return dropdown?.classList.contains('active') ?? false;
});
expect(dropdownIsActive).toBe(true);
await page.evaluate(() => {
document.body.click();
});
await page.waitForTimeout(200);
const newDropdownHandle = await page.$('#dropdown');
const newDropdownIsActive = await newDropdownHandle.evaluate((el) =>
el.classList.contains('active'),
);
expect(newDropdownIsActive).toBe(true);
});
it('should keep the dropdown open when clicking outside when feature flag is off', async () => {
await page.goto(`${LOCAL_TEST_PAGE_URL}?dev=false`);
await page.waitForSelector('#dropdown');
await page.evaluate(() => {
const dropdown = document.getElementById('dropdown');
if (dropdown && !dropdown.classList.contains('active')) {
dropdown.classList.add('active');
}
});
const dropdownIsActive = await page.evaluate(() => {
const dropdown = document.getElementById('dropdown');
return dropdown?.classList.contains('active') ?? false;
});
expect(dropdownIsActive).toBe(true);
await page.evaluate(() => {
document.body.click();
});
await page.waitForTimeout(200);
const newDropdownHandle = await page.$('#dropdown');
const newDropdownIsActive = await newDropdownHandle.evaluate((el) =>
el.classList.contains('active'),
);
expect(newDropdownIsActive).toBe(true);
});
🧰 Tools
🪛 Biome (1.9.4)

[error] 143-143: This let declares a variable that is only assigned once.

'dropdownIsActive' is never reassigned.

Safe fix: Use const instead.

(lint/style/useConst)

@ZendeAditya ZendeAditya force-pushed the update/state-change branch from ab5ca6a to 94588f8 Compare May 10, 2025 13:26
Copy link
Member

@AnujChhikara AnujChhikara left a comment

Choose a reason for hiding this comment

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

  • Could you add some working proof showing your changes?

  • Also, please create a separate issue or sub-issue for this — let’s not use the backend PR as the issue reference.

Copy link
Member

@AnujChhikara AnujChhikara left a comment

Choose a reason for hiding this comment

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

also please resolve conflict

Comment on lines +499 to +503

let requesterUserDetails = await getUserDetails(request.requestedBy);
if ((isDev ? request.status : request.state) !== 'PENDING') {
superUserDetails = await getUserDetails(request.lastModifiedBy);
}
Copy link

Choose a reason for hiding this comment

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

Duplicate declaration of requesterUserDetails variable

There are two declarations of the requesterUserDetails variable in this code section:

// First declaration
let requesterUserDetails = await getUserDetails(request.requestedBy);

// Second declaration (a few lines later)
let requesterUserDetails = await getUserDetails(
  request.type === 'OOO' ? request.requestedBy : request.userId,
);

This will cause a syntax error as variables cannot be declared twice in the same scope.

Consider either:

  1. Removing the first declaration and keeping the more specific second one, or
  2. Merging the logic into a single declaration that handles both cases appropriately

This needs to be resolved before merging to prevent runtime errors.

Suggested change
let requesterUserDetails = await getUserDetails(request.requestedBy);
if ((isDev ? request.status : request.state) !== 'PENDING') {
superUserDetails = await getUserDetails(request.lastModifiedBy);
}
let requesterUserDetails;
if ((isDev ? request.status : request.state) !== 'PENDING') {
superUserDetails = await getUserDetails(request.lastModifiedBy);
}

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

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