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

feat(platform): Edit secret in your project #684

Merged
merged 12 commits into from
Feb 5, 2025

Conversation

poswalsameer
Copy link
Contributor

@poswalsameer poswalsameer commented Jan 31, 2025

User description

Description

This PR adds the feature of editing a secret in your project.

Mentions

@kriptonian1 @rajdip-b

Screenshots of relevant screens

edit-secret-keyshade.mp4

Developer's checklist

  • My PR follows the style guidelines of this project
  • I have performed a self-check on my work

If changes are made in the code:

  • I have followed the coding guidelines
  • My changes in code generate no new warnings
  • My changes are breaking another fix/feature of the project
  • I have added test cases to show that my feature works
  • I have added relevant screenshots in my PR
  • There are no UI/UX issues

Documentation Update

  • This PR requires an update to the documentation at docs.keyshade.xyz
  • I have made the necessary updates to the documentation, or no documentation changes are required.

PR Type

Enhancement, Bug fix


Description

  • Added functionality to edit and delete secrets.

    • Integrated EditSecretSheet for editing secrets.
    • Added ConfirmDeleteSecret for deleting secrets with confirmation.
  • Enhanced UI/UX with context menus and improved layouts.

    • Updated SecretCard to include context menu for edit/delete options.
    • Improved table and accordion styling for better readability.
  • Fixed state management issues for selected secrets.

    • Reset selectedSecret after deletion to avoid stale state.

Changes walkthrough 📝

Relevant files
Enhancement
page.tsx
Integrate edit and delete functionality in secret page     

apps/platform/src/app/(main)/project/[project]/@secret/page.tsx

  • Added EditSecretSheet and ConfirmDeleteSecret components.
  • Integrated state management for editing and deleting secrets.
  • Updated layout to handle inert state during delete confirmation.
  • +39/-16 
    index.tsx
    Add delete confirmation dialog for secrets                             

    apps/platform/src/components/dashboard/secret/confirmDeleteSecret/index.tsx

  • Added ConfirmDeleteSecret component for delete confirmation.
  • Implemented toast notifications for success and error states.
  • Managed state cleanup after dialog closure.
  • +136/-0 
    index.tsx
    Add edit sheet for modifying secrets                                         

    apps/platform/src/components/dashboard/secret/editSecretSheet/index.tsx

  • Added EditSecretSheet component for editing secrets.
  • Implemented form handling for secret name and note updates.
  • Added toast notifications for success and error states.
  • +171/-0 
    index.tsx
    Enhance secret card with context menu and actions               

    apps/platform/src/components/dashboard/secret/secretCard/index.tsx

  • Added context menu for edit and delete actions.
  • Updated table and accordion styles for better UI.
  • Integrated state management for selected secrets.
  • +109/-72

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 Security concerns

    Sensitive information exposure:
    The secret values are displayed in plain text when decrypted (secretCard/index.tsx line 118). Consider masking sensitive values even when decrypted, or adding additional confirmation steps before showing decrypted values.

    ⚡ Recommended focus areas for review

    Input Validation

    The secret name and note fields lack proper input validation. Empty or invalid values could be submitted.

    onChange={(e) => {
    	setRequestData((prev) => ({
    		...prev,
    		name: e.target.value
    	}))
    }}
    value={requestData.name}
    State Management

    The component does not handle API errors gracefully - it closes the dialog even when deletion fails.

      handleClose()
    }, [setSecrets, selectedSecret, handleClose])

    Copy link
    Contributor

    codiumai-pr-agent-free bot commented Jan 31, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    ✅ Prevent empty secret name updates

    Add input validation to prevent empty secret names. The current code allows updating
    a secret with an empty name which could cause issues.

    apps/platform/src/components/dashboard/secret/editSecretSheet/index.tsx [51-59]

     const request: UpdateSecretRequest = {
       secretSlug: secret.slug,
    -  name:
    -    requestData.name === secret.name || requestData.name === ''
    -      ? undefined 
    -      : requestData.name,
    -  note: requestData.note === '' ? undefined : requestData.note,
    +  name: 
    +    !requestData.name?.trim() || requestData.name === secret.name
    +      ? undefined
    +      : requestData.name.trim(),
    +  note: requestData.note?.trim() || undefined,
       entries: undefined
     }

    [Suggestion has been applied]

    Suggestion importance[1-10]: 8

    Why: The suggestion adds important validation to prevent empty secret names by properly trimming whitespace and handling undefined values. This helps maintain data integrity and prevents potential bugs.

    8
    Prevent duplicate delete operations

    Add a loading state during secret deletion to prevent multiple delete requests and
    improve UX feedback.

    apps/platform/src/components/dashboard/secret/confirmDeleteSecret/index.tsx [33-44]

    +const [isDeleting, setIsDeleting] = useState(false)
     const deleteSecret = useCallback(async () => {
    +  if (isDeleting) return
       if (selectedSecret === null) {
         toast.error('No secret selected', {
           description: (
             <p className="text-xs text-red-300">
               No secret selected. Please select a secret.
             </p>
           )
         })
         return
       }
    +  setIsDeleting(true)
    +  try {
    +    // deletion logic
    +  } finally {
    +    setIsDeleting(false)
    +  }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Adding a loading state during deletion prevents duplicate requests and improves user feedback, which is important for critical operations like deletion. This enhances both UX and prevents potential race conditions.

    7

    @Swastik19Nit
    Copy link
    Contributor

    @poswalsameer can you tell me how did you manage to get rid of cors issue.. i just did the same way as per doc but nestjs backend is not running

    @poswalsameer
    Copy link
    Contributor Author

    @rajdip-b the tab size is 2 in my local. Nothing to commit from my side.

    …index.tsx
    
    Co-authored-by: codiumai-pr-agent-free[bot] <138128286+codiumai-pr-agent-free[bot]@users.noreply.github.com>
    @rajdip-b
    Copy link
    Member

    rajdip-b commented Feb 4, 2025

    Need to update the tab size of this file. I'll add this to my to-do

    @rajdip-b
    Copy link
    Member

    rajdip-b commented Feb 5, 2025

    There were a lot of linting errors in your code. Please make sure to double-check that before pushing the code.

    @rajdip-b rajdip-b merged commit 1e34030 into keyshade-xyz:develop Feb 5, 2025
    4 checks passed
    rajdip-b pushed a commit that referenced this pull request Feb 5, 2025
    ## [2.11.0-stage.13](v2.11.0-stage.12...v2.11.0-stage.13) (2025-02-05)
    
    ### 🚀 Features
    
    * **platform:** Edit [secure] in project ([#684](#684)) ([1e34030](1e34030))
    @rajdip-b
    Copy link
    Member

    rajdip-b commented Feb 5, 2025

    🎉 This PR is included in version 2.11.0-stage.13 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants