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/bug-snowflake-key-pair-auth-private-key-does-not-get-removed-upon… #36270

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

Conversation

Jagadeesh-90
Copy link

@Jagadeesh-90 Jagadeesh-90 commented Sep 12, 2024

Issue Link

image
image

Summary by CodeRabbit

  • New Features

    • Introduced the FilePickerControl component for improved file selection in forms.
    • Added the RenderFilePicker component to enhance user interaction with file uploads.
  • Bug Fixes

    • Improved handling of file input state to clear when no file is selected, preventing stale data.
  • Tests

    • Added a comprehensive suite of unit tests for the FilePickerControl component to ensure correct rendering and functionality.

Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes introduced in this pull request include the addition of a test suite for the FilePickerControl component and modifications to its implementation. The newly created test file verifies the rendering and functionality of the file picker, ensuring proper interaction with user inputs. Additionally, the FilePickerControl.tsx file was updated to enhance its lifecycle management and improve the handling of file selection, specifically addressing scenarios where no file is uploaded.

Changes

File Path Change Summary
app/client/src/components/formControls/FilePickerControl.test.tsx Added a test suite for FilePickerControl, validating rendering and file selection functionality.
app/client/src/components/formControls/FilePickerControl.tsx Modified import statements and updated RenderFilePicker logic to handle cases with no file selected.

Poem

In the land of code where components dwell,
A file picker emerged, casting its spell.
With tests to ensure it behaves just right,
Users can browse with pure delight.
So here’s to the changes, both clear and bright,
Enhancing our app, making it 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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 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 and nitpick comments (1)
app/client/src/components/formControls/FilePickerControl.test.tsx (1)

57-84: Excellent test case for file selection!

This test case thoroughly covers the file selection functionality by simulating a user selecting a file and verifying that the file name appears in the component. The use of act and waitFor is appropriate for handling the asynchronous nature of file selection.

One small suggestion:

Consider removing the console.log statements as they are not necessary for the test case. Apply this diff to remove them:

-    console.log('File input found, uploading file...');
     await userEvent.upload(fileInput, file);
-    console.log('File uploaded.');
...
-    console.log('Waiting for file name to appear...');
     expect(screen.getByText("example.txt")).toBeInTheDocument();
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8a9af79 and 66afab0.

Files selected for processing (2)
  • app/client/src/components/formControls/FilePickerControl.test.tsx (1 hunks)
  • app/client/src/components/formControls/FilePickerControl.tsx (3 hunks)
Additional comments not posted (4)
app/client/src/components/formControls/FilePickerControl.test.tsx (1)

52-55: Great work on the rendering test case!

This test case provides a solid foundation by ensuring that the FilePickerControl component renders correctly and the "Select" text is present in the rendered output.

app/client/src/components/formControls/FilePickerControl.tsx (3)

2-2: Great job importing the necessary React hooks!

The addition of useState, useEffect, and useCallback hooks is a step in the right direction to enhance the component's lifecycle management and optimize performance. Keep up the good work!


50-50: Excellent work defining and exporting the RenderFilePicker function!

The function is correctly defined with the appropriate props type, and it follows the TypeScript syntax. Exporting this function aligns with the list of alterations, indicating that it will be used in other parts of the codebase. Well done!


86-88: Fantastic work handling the case when no file is uploaded!

The addition of the else block within the useEffect hook is a great improvement to the control flow. By explicitly calling props.input?.onChange("") when appFileToBeUploaded is not set, you ensure that the input is cleared, preventing stale data from being retained in the input state. This enhances the user experience and maintains data consistency.

Moreover, the use of the optional chaining operator ?. is a good practice to safely access the onChange method, avoiding potential errors if props.input is undefined.

Keep up the excellent work in improving the component's behavior and user experience!

@sneha122
Copy link
Contributor

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10881060896.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36270.
recreate: .

@@ -48,7 +47,7 @@ type RenderFilePickerProps = FilePickerControlProps & {
onChange: (event: any) => void;
};

function RenderFilePicker(props: RenderFilePickerProps) {
export function RenderFilePicker(props: RenderFilePickerProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Jagadeesh-90 Is this export needed here? As we are already exporting this whole component at the bottom

@@ -1,5 +1,5 @@
import * as React from "react";
import { useState } from "react";
import { useState, useEffect, useCallback } from "react";
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these useEffect and useCallback imports needed?

userEvent.click(screen.getByText("Select"));
userEvent.click(screen.getByText("Browse"));

const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using as, can we define type for fileInput?

Copy link

Deploy-Preview-URL: https://ce-36270.dp.appsmith.com


await act(async () => {
if (fileInput) {
console.log('File input found, uploading file...');
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these console logs needed here?

}
});

await waitFor(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add a test case for when we remove the file from file picker? Asserting that input is blank?

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