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

Select/unselect all functionality to captured apis table #1523

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Yibaebi
Copy link
Contributor

@Yibaebi Yibaebi commented Jan 23, 2025

No description provided.

Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

The pull request modifies the file details API scan component to introduce functionality for selecting and unselecting all captured APIs. Changes include updates to the Handlebars template, TypeScript component, translations, and tests. The implementation enhances the loading state rendering and adds UI elements for bulk selection, alongside backend logic to manage the selection state and server interactions.

Changes

File Change Summary
app/components/file-details/api-scan/captured-apis/index.hbs Modified conditional rendering for loading state; added AkStack with AkCheckbox and AkTypography for selecting/unselecting all APIs.
app/components/file-details/api-scan/captured-apis/index.ts Introduced tracked properties allAPIsSelected and showAPIListLoadingState; added methods and tasks for managing API selection state.
tests/acceptance/file-details/api-scan-test.js Added new test case for verifying select/unselect functionality for all captured APIs.
translations/en.json Added new translation key "selectAll" with value "Select All".
translations/ja.json Added new translation key "selectAll" with value "Select All".
app/components/file-details/api-scan/captured-apis/index.scss Added new class .select-all-captured-api-cta for styling.
app/styles/_component-variables.scss Renamed variable --file-details-api-scan-captured-apis-title-background to --file-details-api-scan-select-all-captured-api-background.

Possibly related PRs

  • api scan full page implementation #1409: The changes in this PR involve modifications to the Handlebars template and TypeScript files related to the FileDetailsApiScanCapturedApisComponent, which directly connects to the changes made in the main PR regarding the rendering logic and properties of the same component.
  • added vulnerable api request response download raw button #1504: This PR introduces a download button for raw API findings, which is related to the changes in the main PR that enhance the API scan functionality and user interface, including the handling of API findings.
  • Fix: Changes in Component Variable CSS File #1509: The modifications to the CSS variables in this PR include updates relevant to the styling of components involved in the API scan, which aligns with the changes made in the main PR regarding the visual presentation of captured APIs.

Suggested reviewers

  • future-pirate-king

Poem

🐰 Hop, hop, APIs galore!
A checkbox to select them all, what's in store?
Click once, select with glee
Uncheck to set them free
CodeRabbit's magic at the core! 🔍✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

@Yibaebi Yibaebi force-pushed the update-api-scan-page branch from 0bf7183 to e4612d7 Compare January 23, 2025 17:52
Copy link

cloudflare-workers-and-pages bot commented Jan 23, 2025

Deploying irenestaging with  Cloudflare Pages  Cloudflare Pages

Latest commit: d385b08
Status: ✅  Deploy successful!
Preview URL: https://a2ec29ef.irenestaging.pages.dev
Branch Preview URL: https://update-api-scan-page.irenestaging.pages.dev

View logs

Copy link

cypress bot commented Jan 23, 2025

Irene    Run #572

Run Properties:  status check failed Failed #572  •  git commit 2476c27979 ℹ️: Merge 0bf71836b1193d114ea67452723b4b1a7f680a35 into 2e5b84423aa1849994ad22c4ee29...
Project Irene
Branch Review update-api-scan-page
Run status status check failed Failed #572
Run duration 04m 59s
Commit git commit 2476c27979 ℹ️: Merge 0bf71836b1193d114ea67452723b4b1a7f680a35 into 2e5b84423aa1849994ad22c4ee29...
Committer Yibaebi Elliot
View all properties for this run ↗︎

Test results
Tests that failed  Failures 1
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 31
View all changes introduced in this branch ↗︎

Tests for review

Failed  cypress/tests/dynamic-scan.spec.ts • 1 failed test

View Output

Test Artifacts
Dynamic Scan > it tests dynamic scan for an ipa file: 58061 Test Replay Screenshots

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e5b844 and e4612d7.

📒 Files selected for processing (5)
  • app/components/file-details/api-scan/captured-apis/index.hbs (1 hunks)
  • app/components/file-details/api-scan/captured-apis/index.ts (6 hunks)
  • tests/acceptance/file-details/api-scan-test.js (1 hunks)
  • translations/en.json (1 hunks)
  • translations/ja.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Push Docker image to GitHub Packages
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (8)
translations/en.json (1)

1406-1406: LGTM! Clear and consistent translation entry.

The translation key and value follow the established conventions and clearly communicate the bulk selection action.

app/components/file-details/api-scan/captured-apis/index.hbs (1)

35-48: LGTM! Well-structured UI implementation for bulk selection.

The implementation follows good practices:

  • Uses consistent component library (Ak* components)
  • Has proper layout structure with AkStack
  • Includes data-test attributes for testing
  • Places the select all control logically before the list
app/components/file-details/api-scan/captured-apis/index.ts (5)

45-45: LGTM! Well-typed tracked property.

The tracked property is properly declared for managing the bulk selection state.


73-79: LGTM! Clean endpoint construction.

The endpoint construction method follows good practices:

  • Uses array join for clean URL construction
  • Leverages environment configuration
  • Has clear naming

110-113: LGTM! Well-structured event handler.

The event handler follows good practices:

  • Uses proper typing for event and checked parameters
  • Delegates to a task for async operations

170-185: LGTM! Robust task implementation for bulk selection.

The task implementation follows best practices:

  • Uses proper error handling with parseError
  • Updates UI state after API calls
  • Refreshes the list to reflect changes

187-203: LGTM! Well-implemented status check task.

The task implementation:

  • Uses proper typing for the API response
  • Handles errors appropriately
  • Updates the UI state correctly
tests/acceptance/file-details/api-scan-test.js (1)

264-350: LGTM! Comprehensive test coverage for bulk selection.

The test implementation follows best practices:

  • Uses test.each for testing both selection states
  • Has proper server mocks
  • Includes thorough assertions
  • Verifies UI state changes

translations/ja.json Outdated Show resolved Hide resolved
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

🧹 Nitpick comments (2)
app/components/file-details/api-scan/captured-apis/index.ts (2)

111-114: Consider refining the event parameter type.

While the implementation is correct, consider using a more specific type for the event parameter:

-  handleSelectAllCapturedApis(_: Event, checked: boolean) {
+  handleSelectAllCapturedApis(_: MouseEvent | KeyboardEvent, checked: boolean) {

192-208: Improve error handling and add specific error messages.

The error handling could be improved with better type annotations and more specific error messages.

   getAllAPIsSelectedStatus = task(async () => {
     try {
       const allAPIsSelected = await this.ajax.request<{ is_active: boolean }>(
         this.modAllSelectedAPIsEndpoint,
         {
           namespace: ENV.namespace_v2,
         }
       );
 
       this.allAPIsSelected = allAPIsSelected.is_active;
     } catch (err) {
-      const error = err as AdapterError;
+      const error = err as AjaxError;
-      const errMsg = this.intl.t('tPleaseTryAgain');
+      const errMsg = this.intl.t('errorFetchingSelectionStatus');
 
       this.notify.error(parseError(error, errMsg));
     }
   });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e4612d7 and b23ca58.

📒 Files selected for processing (6)
  • app/components/file-details/api-scan/captured-apis/index.hbs (2 hunks)
  • app/components/file-details/api-scan/captured-apis/index.scss (1 hunks)
  • app/components/file-details/api-scan/captured-apis/index.ts (6 hunks)
  • tests/acceptance/file-details/api-scan-test.js (1 hunks)
  • translations/en.json (1 hunks)
  • translations/ja.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • app/components/file-details/api-scan/captured-apis/index.scss
🚧 Files skipped from review as they are similar to previous changes (3)
  • translations/en.json
  • translations/ja.json
  • app/components/file-details/api-scan/captured-apis/index.hbs
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Run Integration Tests - Part 8
  • GitHub Check: Run Integration Tests - Part 7
  • GitHub Check: Run Integration Tests - Part 6
  • GitHub Check: Run Integration Tests - Part 5
  • GitHub Check: Run Integration Tests - Part 4
  • GitHub Check: Run Integration Tests - Part 3
  • GitHub Check: Run Integration Tests - Part 2
  • GitHub Check: Run Integration Tests - Part 1
  • GitHub Check: Run Acceptance Tests
  • GitHub Check: Run Linting
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
tests/acceptance/file-details/api-scan-test.js (1)

264-350: LGTM! Comprehensive test coverage for select/unselect functionality.

The test implementation is thorough and well-structured:

  • Uses test.each to verify both selection states
  • Properly mocks server responses
  • Verifies UI state changes
  • Checks checkbox states for all API endpoints
app/components/file-details/api-scan/captured-apis/index.ts (3)

13-13: LGTM! Well-typed tracked properties.

The new tracked properties and import are properly defined with appropriate types for managing the selection and loading states.

Also applies to: 45-46


57-57: LGTM! Proper initialization sequence.

The constructor correctly initializes the selection state by performing the getAllAPIsSelectedStatus task.


74-80: LGTM! Safe URL construction.

The endpoint URL is constructed safely using array join with proper typing.

@Yibaebi Yibaebi force-pushed the update-api-scan-page branch from c9133a5 to d385b08 Compare January 27, 2025 08:18
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: 0

♻️ Duplicate comments (1)
app/components/file-details/api-scan/captured-apis/index.ts (1)

173-190: ⚠️ Potential issue

Fix loading state management.

The loading state management is reversed:

  • showAPIListLoadingState = false before operation starts
  • showAPIListLoadingState = true in finally block
   selectAllCapturedApis = task(async (is_active: boolean) => {
-    this.showAPIListLoadingState = false;
+    this.showAPIListLoadingState = true;
 
     try {
       await this.ajax.put(this.modAllSelectedAPIsEndpoint, {
         data: { is_active: is_active },
         namespace: ENV.namespace_v2,
       });
 
       await this.fetchCapturedApis.perform(this.limit, this.offset);
       await this.getAllAPIsSelectedStatus.perform();
       this.setSelectedApiCount.perform();
     } catch (err) {
       this.notify.error(parseError(err, this.intl.t('tPleaseTryAgain')));
     } finally {
-      this.showAPIListLoadingState = true;
+      this.showAPIListLoadingState = false;
     }
   });
🧹 Nitpick comments (3)
app/components/file-details/api-scan/captured-apis/index.ts (3)

74-80: Consider a more descriptive property name.

The property name could be more specific about its purpose, e.g., toggleAllCapturedApisEndpoint or bulkSelectionEndpoint.


111-114: Improve type safety of the event parameter.

Consider using a more specific event type for better type safety:

-  handleSelectAllCapturedApis(_: Event, checked: boolean) {
+  handleSelectAllCapturedApis(_: MouseEvent | KeyboardEvent, checked: boolean) {

Line range hint 157-169: Simplify error handling using parseError utility.

For consistency with other error handlers in the component, consider using the parseError utility:

     } catch (err) {
-      const error = err as AdapterError;
-      let errMsg = this.intl.t('tPleaseTryAgain');
-
-      if (error.errors && error.errors.length) {
-        errMsg = error.errors[0]?.detail || errMsg;
-      } else if (error.message) {
-        errMsg = error.message;
-      }
-
-      this.notify.error(errMsg);
+      this.notify.error(parseError(err, this.intl.t('tPleaseTryAgain')));
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9133a5 and d385b08.

📒 Files selected for processing (7)
  • app/components/file-details/api-scan/captured-apis/index.hbs (2 hunks)
  • app/components/file-details/api-scan/captured-apis/index.scss (1 hunks)
  • app/components/file-details/api-scan/captured-apis/index.ts (7 hunks)
  • app/styles/_component-variables.scss (1 hunks)
  • tests/acceptance/file-details/api-scan-test.js (1 hunks)
  • translations/en.json (1 hunks)
  • translations/ja.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • app/styles/_component-variables.scss
  • app/components/file-details/api-scan/captured-apis/index.scss
  • app/components/file-details/api-scan/captured-apis/index.hbs
  • translations/ja.json
  • translations/en.json
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Push Docker image to GitHub Packages
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (3)
tests/acceptance/file-details/api-scan-test.js (1)

264-348: LGTM! Well-structured test case.

The test case thoroughly verifies the select/unselect all functionality by:

  • Testing both selection states
  • Setting up appropriate server responses
  • Verifying UI state changes
app/components/file-details/api-scan/captured-apis/index.ts (2)

45-46: LGTM! Well-structured initialization.

The tracked properties are appropriately named and the constructor correctly initializes the component state by fetching the selection status.

Also applies to: 57-57


192-205: LGTM! Well-implemented status check.

The task has proper error handling using parseError and good type safety with the response type annotation.


await this.fetchCapturedApis.perform(this.limit, this.offset);
await this.getAllAPIsSelectedStatus.perform();
this.setSelectedApiCount.perform();
Copy link
Contributor

Choose a reason for hiding this comment

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

add a new line above

@@ -901,7 +901,7 @@ body {
--file-details-api-scan-captured-apis-border-radius: var(--border-radius);
--file-details-api-scan-captured-apis-card-box-shadow: var(--box-shadow-3);
--file-details-api-scan-captured-apis-card-background: var(--background-main);
--file-details-api-scan-captured-apis-title-background: var(
--file-details-api-scan-select-all-captured-api-background: var(
Copy link
Contributor

Choose a reason for hiding this comment

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

name should be --file-details-api-scan-captured-apis-select-all-background

});

await this.fetchCapturedApis.perform(this.limit, this.offset);
await this.getAllAPIsSelectedStatus.perform();
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we require this call ?

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