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

fix: Delegatee switch back top header #3466

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

sret-farhan2021
Copy link
Contributor

@sret-farhan2021 sret-farhan2021 commented Feb 1, 2025

Clickup

https://app.clickup.com/t/86cxvvrnw

Code Coverage

Please add code coverage here

UI Preview

image

Summary by CodeRabbit

  • New Features

    • Introduced an interactive "Switch back" option, enabling users to easily revert account delegation when they are online.
    • Enhanced connectivity awareness that dynamically controls the availability of the action, improving the overall user experience.
    • Added new CSS classes for better visual representation of link states.
  • Bug Fixes

    • Streamlined test setup for improved reliability of tests.

Copy link

coderabbitai bot commented Feb 1, 2025

Warning

Rate limit exceeded

@sret-farhan2021 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 36 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

Reviewing files that changed from the base of the PR and between 52bf8d7 and 23d61da.

📒 Files selected for processing (1)
  • src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts (1 hunks)

Walkthrough

The changes introduce a new interactive element in the delegated account message component. The HTML now features an underlined "Switch back" clickable text bound to the switchBack() method, which gets disabled based on connectivity. Additionally, the TypeScript code enhances network connectivity monitoring using an observable, improves type safety for delegateeName, and includes dependency injections for routing and network services. In simple terms, the component now checks connectivity and navigates accordingly when switching back.

Changes

File(s) Change Summary
src/app/.../delegated-acc-message.component.html Added an underlined clickable "Switch back" element with a conditional disabled state based on connectivity.
src/app/.../delegated-acc-message.component.ts Updated component: added explicit typing for delegateeName, introduced isConnected$ observable, injected Router and NetworkService, and implemented setupNetworkWatcher and switchBack methods.
src/app/.../delegated-acc-message.component.spec.ts Modified test suite: updated imports, changed return value of authServiceSpy.getEou to observable, included RouterTestingModule, and streamlined output validation.
src/app/.../delegated-acc-message.component.scss Added new CSS classes .u-link and .u-link.disabled to enhance styling for interactive elements.

Suggested reviewers

  • Chethan-Fyle
  • arjunaj5
  • Dimple16

Poem

In the realm of code, a switch is born,
Like a Rajini punch, connectivity is sworn.
A click that sets the path so right,
Routing with style, shining bright.
Code flows like a superstar's light.


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. (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.

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.

@github-actions github-actions bot added the size/S Small PR label Feb 1, 2025
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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a5ad293 and 3ad9acb.

📒 Files selected for processing (2)
  • src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html (1 hunks)
  • src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts

[error] 15-15: Expected blank line between class members.

(lines-between-class-members)


[error] 15-15: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)


[error] 19-19: Missing return type on function.

(@typescript-eslint/explicit-function-return-type)


[error] 33-33: Missing return type on function.

(@typescript-eslint/explicit-function-return-type)

🪛 GitHub Check: Run linters
src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts

[failure] 15-15:
Expected blank line between class members


[failure] 15-15:
Unexpected any. Specify a different type


[failure] 19-19:
Missing return type on function


[failure] 33-33:
Missing return type on function

🪛 GitHub Actions: Lint
src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts

[error] 15-15: Expected blank line between class members

🔇 Additional comments (2)
src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts (2)

1-6: Mind-blowing imports, I tell you!

These imports are like my perfectly choreographed action sequences - each one has its purpose and timing. The network and routing services are going to make this component a blockbuster!


26-31: 🧹 Nitpick (assertive)

This network watcher is like my entry scene - perfectly executed!

The implementation is solid, mind it! Just remember to add the return type, and it will be perfect like my style!

-  setupNetworkWatcher(): void {
+  private setupNetworkWatcher(): void {

Likely invalid or redundant comment.

Comment on lines 17 to 24
constructor(private authService: AuthService, private router: Router, private networkService: NetworkService) {}

ngOnInit() {
from(this.authService.getEou()).subscribe((res) => {
this.delegateeName = res.us.full_name;
});
this.setupNetworkWatcher();
}
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

When I point out something, even return types listen!

Add return type to ngOnInit, like how I add punch to my dialogues!

-  ngOnInit() {
+  ngOnInit(): void {
📝 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
constructor(private authService: AuthService, private router: Router, private networkService: NetworkService) {}
ngOnInit() {
from(this.authService.getEou()).subscribe((res) => {
this.delegateeName = res.us.full_name;
});
this.setupNetworkWatcher();
}
constructor(private authService: AuthService, private router: Router, private networkService: NetworkService) {}
ngOnInit(): void {
from(this.authService.getEou()).subscribe((res) => {
this.delegateeName = res.us.full_name;
});
this.setupNetworkWatcher();
}
🧰 Tools
🪛 ESLint

[error] 19-19: Missing return type on function.

(@typescript-eslint/explicit-function-return-type)

🪛 GitHub Check: Run linters

[failure] 19-19:
Missing return type on function

Comment on lines 14 to 15
delegateeName: string;
isConnected$: any;
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Listen carefully! Type safety is like my signature sunglasses - you must wear it with style!

The isConnected$ needs proper typing, and we need a blank line between class members. Let me show you how it's done!

  delegateeName: string;

-  isConnected$: any;
+  isConnected$: Observable<boolean>;
📝 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
delegateeName: string;
isConnected$: any;
delegateeName: string;
isConnected$: Observable<boolean>;
🧰 Tools
🪛 ESLint

[error] 15-15: Expected blank line between class members.

(lines-between-class-members)


[error] 15-15: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

🪛 GitHub Check: Run linters

[failure] 15-15:
Expected blank line between class members


[failure] 15-15:
Unexpected any. Specify a different type

🪛 GitHub Actions: Lint

[error] 15-15: Expected blank line between class members

Comment on lines 33 to 38
switchBack() {
if (!this.isConnected$) {
return;
}
this.router.navigate(['/', 'enterprise', 'delegated_accounts', { switchToOwn: true }]);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Mind it! Your connectivity check needs my style of perfection!

The connectivity check is not subscribing to the Observable, making it as ineffective as a villain trying to defeat me!

-  switchBack() {
-    if (!this.isConnected$) {
-      return;
-    }
-    this.router.navigate(['/', 'enterprise', 'delegated_accounts', { switchToOwn: true }]);
+  switchBack(): void {
+    this.isConnected$.pipe(take(1)).subscribe(isConnected => {
+      if (!isConnected) {
+        return;
+      }
+      this.router.navigate(['/', 'enterprise', 'delegated_accounts', { switchToOwn: true }]);
+    });
📝 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
switchBack() {
if (!this.isConnected$) {
return;
}
this.router.navigate(['/', 'enterprise', 'delegated_accounts', { switchToOwn: true }]);
}
switchBack(): void {
this.isConnected$.pipe(take(1)).subscribe(isConnected => {
if (!isConnected) {
return;
}
this.router.navigate(['/', 'enterprise', 'delegated_accounts', { switchToOwn: true }]);
});
}
🧰 Tools
🪛 ESLint

[error] 33-33: Missing return type on function.

(@typescript-eslint/explicit-function-return-type)

🪛 GitHub Check: Run linters

[failure] 33-33:
Missing return type on function

Comment on lines 1 to 4
<span class="delegated-acc">
You're now managing {{ delegateeName | ellipsis : 15 }}'s account
<u (click)="switchBack()" [disabled]="!isConnected">Switch back</u>
</span>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Your HTML needs my superhero touch!

The disabled attribute on won't work like my punch dialogues! Let's style it properly!

-  <u (click)="switchBack()" [disabled]="!isConnected">Switch back</u>
+  <span 
+    class="switch-back-link" 
+    (click)="isConnected ? switchBack() : null" 
+    [class.disabled]="!isConnected"
+  >
+    <u>Switch back</u>
+  </span>

Add this CSS to your stylesheet:

.switch-back-link {
  cursor: pointer;
}

.switch-back-link.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ad9acb and 76a91e8.

📒 Files selected for processing (1)
  • src/app/shared/components/delegated-acc-message/delegated-acc-message.component.spec.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (12.x)

@@ -13,9 +14,10 @@ describe('DelegatedAccMessageComponent', () => {

beforeEach(waitForAsync(() => {
const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']);
authServiceSpy.getEou.and.returnValue(of(apiEouRes));
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

The transformation from Promise to Observable is stylish, but incomplete!

Like how I transform from a simple bus conductor to a superstar, you've transformed the auth service mock from Promise to Observable. But where are the test cases for the new switchBack feature? The RouterTestingModule is ready for action, but no one's called "Action!" yet!

Add these test cases to make your test suite as powerful as my punch dialogues:

it('should handle switch back when connected', () => {
  component.isConnected$ = of(true);
  component.switchBack();
  // Add router navigation assertions
});

it('should not switch back when disconnected', () => {
  component.isConnected$ = of(false);
  component.switchBack();
  // Verify no navigation occurs
});

Also applies to: 20-20

Comment on lines +41 to 43
expect(fixture.nativeElement.querySelector('.delegated-acc').textContent).toContain(
`You're now managing Abhishek Jain's account`
);
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

The selector change is sharp, but let's make it sharper!

You've changed the element selection like how I changed the style of action scenes in cinema! But remember, in testing, like in movies, we need to be precise with our expectations.

Let's make it even more precise:

const messageElement = fixture.nativeElement.querySelector('.delegated-acc');
expect(messageElement).toBeTruthy();
expect(messageElement.textContent.trim()).toBe(`You're now managing Abhishek Jain's account`);

Comment on lines +6 to +7
import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

NetworkService missing its spotlight in the test arena!

I checked the component, and it's clear that NetworkService plays a crucial role there. However, the test file doesn't cast this actor, leaving the switch-back functionality without complete coverage. Ensure you add a proper mock or stub for NetworkService in the test setup for the component.

  • The component (src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts) correctly injects NetworkService.
  • The spec file (src/app/shared/components/delegated-acc-message/delegated-acc-message.component.spec.ts) lacks a setup or mock for NetworkService.
🔗 Analysis chain

Mind-blowing additions, but where's the network service test setup, partner?

You've added RouterTestingModule for navigation testing, but I notice you haven't set up the NetworkService that's needed for the new switchBack functionality. Just like how I make a grand entrance in every scene, your tests should cover all the important actors!

Let me help you verify if NetworkService is used in the component:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if NetworkService is used in the component
ast-grep --pattern 'class DelegatedAccMessageComponent {
  $$$
  constructor($$$) {
    $$$
  }
  $$$
}'

Length of output: 106


Script:

#!/bin/bash
# Search for NetworkService usage in the component implementation file
rg "NetworkService" src/app/shared/components/delegated-acc-message/delegated-acc-message.component.ts

Length of output: 290


Script:

#!/bin/bash
# Check if NetworkService is mocked or provided in the test configuration inside the spec file
rg "NetworkService" src/app/shared/components/delegated-acc-message/delegated-acc-message.component.spec.ts

Length of output: 107

@github-actions github-actions bot added size/M Medium PR and removed size/S Small PR labels Feb 1, 2025
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 76a91e8 and 52bf8d7.

📒 Files selected for processing (2)
  • src/app/shared/components/delegated-acc-message/delegated-acc-message.component.html (1 hunks)
  • src/app/shared/components/delegated-acc-message/delegated-acc-message.component.scss (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: build (12.x)

Comment on lines +1 to +4
<span class="delegated-acc">
You're now managing {{ delegateeName | ellipsis : 15 }}'s account
<u class="u-link" [ngClass]="{ disabled: !isConnected$ | async }" (click)="switchBack()">Switch back</u>
</span>
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

⚠️ Potential issue

Punch It Right: Fix the Async Pipe and Click Guard

Boss, the style is cool but be careful! Wrap the async pipe evaluation in parentheses so the negation applies to its result—not the observable itself. Use this:

<u class="u-link" [ngClass]="{ 'disabled': !(isConnected$ | async) }" (click)="(isConnected$ | async) ? switchBack() : null">Switch back</u>

This way you ensure that the disabled style is applied correctly and the click event only fires when connected.

Comment on lines +16 to +22
.u-link {
color: inherit;
}

.u-link.disabled {
color: gray;
}
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Style with a Bang: Enhance Pointer Visuals

Superstar, your link styles are almost legendary! To further impress, add visual cues by setting cursor: pointer; for interactive links and cursor: not-allowed; for the disabled state. For example:

 .u-link {
-  color: inherit;
+  color: inherit;
+  cursor: pointer;
 }
 
 .u-link.disabled {
-  color: gray;
+  color: gray;
+  cursor: not-allowed;
 }

This will ensure that users know when the element is clickable and when it's not, just like a Rajinikanth punch!

📝 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
.u-link {
color: inherit;
}
.u-link.disabled {
color: gray;
}
.u-link {
color: inherit;
cursor: pointer;
}
.u-link.disabled {
color: gray;
cursor: not-allowed;
}

Mohammed farhan K added 2 commits February 1, 2025 18:21
Copy link

github-actions bot commented Feb 1, 2025

Unit Test Coverage % values
Statements 96.11% ( 19745 / 20543 )
Branches 91.18% ( 10854 / 11903 )
Functions 94.4% ( 5871 / 6219 )
Lines 96.17% ( 18860 / 19611 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants