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

Disable links #84

Merged
merged 8 commits into from
Sep 25, 2024
Merged

Disable links #84

merged 8 commits into from
Sep 25, 2024

Conversation

amalessid
Copy link
Collaborator

@amalessid amalessid commented Sep 23, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new action column in the Links Table for deactivating links.
    • Users can now confirm the deactivation of links through a new Confirmation Dialog.
  • Bug Fixes

    • Ensured that the links are automatically refreshed after a link is deactivated.
  • Documentation

    • Updated data structure to include an active status for links, enhancing clarity on link states.

@amalessid amalessid linked an issue Sep 23, 2024 that may be closed by this pull request
Copy link

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes introduce an action column in the LinksTable component, allowing users to deactivate links. This includes defining a new interface and functions for handling deactivation, updating the API class to support this functionality, and enhancing the data structure with an active status property in the relevant data transfer objects and mappers. A confirmation dialog component is also added for user interaction during the deactivation process.

Changes

Files Change Summary
src/app/shared-links/Components/LinksTable.tsx Added an action column for link deactivation, defined IActionColumn, and implemented handleDeactivate and createActionColumn functions. Updated rendering logic to include a deactivation button.
src/app/shared-links/Components/ConfirmationDialog.tsx Introduced a new ConfirmationDialog component for user confirmation before deactivating a link, including props for handling dialog state and actions.
src/app/utils/api.class.ts Introduced async deactivateLink(id: string) method to perform a DELETE request for link deactivation.
src/domain/dtos/shlink.ts Updated the active property in SHLinkMiniDto class to include a semicolon for syntactical correctness.
src/mappers/shlink-mapper.ts Updated mapModelToMiniDto function to include the active property from shlinkModel.

Possibly related PRs

Suggested reviewers

  • BMartinos
  • yassinedorbozgithub

Poem

In the meadow, links do play,
With buttons bright to save the day.
A hop, a click, they come alive,
Deactivation helps them thrive!
So let us cheer, with joy and glee,
For links that dance so happily! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between febf0f7 and 8b47489.

📒 Files selected for processing (1)
  • src/app/shared-links/Components/LinksTable.tsx (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/shared-links/Components/LinksTable.tsx

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

Outside diff range and nitpick comments (5)
src/app/utils/api.class.ts (1)

46-48: LGTM! Consider minor improvements for robustness.

The deactivateLink method is well-implemented and aligns with the PR objective to disable links. It correctly uses the delete method from the base class and follows RESTful conventions.

To further enhance the code:

  1. Consider adding a specific return type for better type safety.
  2. A brief comment explaining the method's purpose could improve documentation.

Example improvement:

/**
 * Deactivates a share link with the given ID.
 * @param id The ID of the share link to deactivate.
 * @returns A promise that resolves to the API response.
 */
async deactivateLink(id: string): Promise<AxiosResponse> {
  return await this.delete({ url: `/share-links/${id}/deactivate` });
}
src/mappers/shlink-mapper.ts (1)

71-71: LGTM! Consider a minor improvement for consistency.

The addition of the active property to the mapModelToMiniDto function aligns well with the PR objective of "Disable links" and is consistent with other mapper functions in this file. This change allows the active status of a link to be included in the mini DTO, which can be used to determine if a link is disabled.

For consistency with other properties in this object, consider moving the active property closer to the top of the object, perhaps right after the url property. This would group similar metadata properties together:

 url: encodeSHLink(shlinkModel),
+active: shlinkModel.getActive(),
 files: files?.map((x) => {
   return {
     location: `${EXTERNAL_URL}/api/v1/share-links/${shlinkModel.getId()}/endpoints/${x.getId()}?ticket=${ticket}`,
     contentType: 'application/smart-api-access',
     embedded: null,
   };
 }),
-active: shlinkModel.getActive(),
src/app/shared-links/Components/LinksTable.tsx (3)

Line range hint 130-148: Ensure consistency by using combinedCols in TableHead

Currently, the action column header is added manually, which can lead to inconsistencies if columns change. Consider iterating over combinedCols in TableHead to keep the headers consistent with the data columns.

Apply this diff to update the TableHead:

<TableHead>
  <TableRow>
-   {columns.map((column) => (
+   {combinedCols.map((column) => (
      <TableCell
        key={column.id}
        align={column.align}
        style={{ minWidth: column.minWidth }}
      >
        {column.label}
      </TableCell>
    ))}
-   <TableCell>Actions</TableCell>
  </TableRow>
</TableHead>

160-160: Improve the key prop for TableCell to ensure uniqueness

Using column.id + row.active as a key may not guarantee uniqueness and could lead to rendering issues. It's better to use a combination of row.id and column.id.

Apply this diff to modify the key:

-   key={column.id + row.active}
+   key={`${row.id}-${column.id}`}

166-170: Add aria-label to the Button for better accessibility

Since the Button contains only an icon, screen readers might not convey its purpose effectively. Adding an aria-label will improve accessibility for users relying on assistive technologies.

Apply this diff to include the aria-label:

<Button
  disabled={!row.active}
  onClick={() => column.action(row.id)}
+ aria-label="Deactivate Link"
>
  {column.label}
</Button>
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 401eb2f and 9caafc6.

Files selected for processing (4)
  • src/app/shared-links/Components/LinksTable.tsx (6 hunks)
  • src/app/utils/api.class.ts (1 hunks)
  • src/domain/dtos/shlink.ts (1 hunks)
  • src/mappers/shlink-mapper.ts (1 hunks)
Additional comments not posted (2)
src/app/utils/api.class.ts (1)

46-48: Verify usage of the new deactivateLink method

The new deactivateLink method has been successfully added to the ApiSHLink class. To ensure its proper integration:

  1. Verify that this method is called in the appropriate places where link deactivation is required.
  2. Check if any existing UI components or other parts of the codebase need to be updated to use this new functionality.

Run the following script to check for potential usage of the new method:

This will help identify areas where the new method should be integrated or where updates might be necessary.

Verification successful

Run updated script to verify usage of deactivateLink method

The previous script encountered issues recognizing file types. Please execute the following updated script to search for usages of the deactivateLink method and any related TODO comments:


Verified usage of the new deactivateLink method

The deactivateLink method has been successfully added to the ApiSHLink class. It is not referenced elsewhere in the codebase, and there are no pending TODO comments related to its usage. This confirms that the method is properly integrated without requiring further updates.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for potential usage or needed updates for the new deactivateLink method

# Test: Search for files that might need to use the new deactivateLink method
echo "Files that might need to use deactivateLink:"
rg --type typescript --type javascript -l 'apiSharedLink|ApiSHLink'

# Test: Check if there are any TODO comments related to link deactivation
echo "\nTODO comments related to link deactivation:"
rg --type typescript --type javascript 'TODO.*deactivate.*link'

Length of output: 405


Script:

# Modified script to search for potential usage or needed updates for the new deactivateLink method

# Description: Search for .ts and .js files that might need to use the new deactivateLink method
echo "Files that might need to use deactivateLink:"
rg --glob "*.ts" --glob "*.js" -l 'deactivateLink'

# Check if there are any TODO comments related to link deactivation
echo "\nTODO comments related to link deactivation:"
rg --glob "*.ts" --glob "*.js" 'TODO.*deactivate.*link'

Length of output: 335

src/domain/dtos/shlink.ts (1)

146-146: LGTM! Consider updating Swagger documentation.

The addition of the active property to SHLinkMiniDto is a good improvement. It allows for better representation of the share link's current status.

Consider updating the Swagger documentation above the class to include the new active property. You can add it like this:

 *         active:
 *           type: boolean
 *           description: A boolean indicating whether the share link is currently active.
 *           example: true

To ensure consistency, let's check if this change is reflected in related components or services:

Please review the output of this script to ensure that all necessary updates have been made in related components or services to handle the new active property.

src/app/shared-links/Components/LinksTable.tsx Outdated Show resolved Hide resolved
src/app/shared-links/Components/LinksTable.tsx Outdated Show resolved Hide resolved
src/app/shared-links/Components/LinksTable.tsx Outdated Show resolved Hide resolved
@medchedli
Copy link
Member

Because once a link is deactivated, it cannot be reactivated, I suggest adding a confirmation dialog to the link deactivation process. This will prevent accidental deactivation and provide clarity to the user.

For example, you can display an alert to the user with the following message :

Are you sure you want to deactivate this link?
Deactivating will permanently disable the link, and you will need to create a new one.

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

Outside diff range and nitpick comments (4)
src/app/shared-links/Components/ConfirmationDialog.tsx (3)

10-18: LGTM: Component definition and props are well-structured.

The component is correctly defined with appropriate TypeScript types for the props. This ensures type safety and improves code maintainability.

Consider using an interface for the props to improve readability and reusability:

interface ConfirmationDialogProps {
  confirmDeactivate: () => void;
  confirmDialogOpen: boolean;
  setConfirmDialogOpen: (arg: boolean) => void;
}

export const ConfirmationDialog = ({
  confirmDeactivate,
  confirmDialogOpen,
  setConfirmDialogOpen,
}: ConfirmationDialogProps) => {
  // ...
}

19-38: LGTM: Dialog implementation matches requirements and follows best practices.

The ConfirmationDialog component is well-implemented using Material-UI components. The content accurately reflects the requirements specified in the PR comments, and the button actions are correctly set up.

To improve accessibility, consider adding an aria-label to the Deactivate button to emphasize its destructive nature:

-        <Button onClick={confirmDeactivate} color="error" variant="contained">
+        <Button onClick={confirmDeactivate} color="error" variant="contained" aria-label="Confirm link deactivation">
           Deactivate
         </Button>

41-41: Consider removing the default export.

The ConfirmationDialog component is already exported as a named export on line 10. Having both named and default exports for the same component can lead to inconsistent import styles across the project.

Remove the default export to encourage consistent use of named imports:

- export default ConfirmationDialog;

This change promotes a more consistent import style throughout the project:

import { ConfirmationDialog } from './ConfirmationDialog';
src/app/shared-links/Components/LinksTable.tsx (1)

112-115: LGTM: Action column implementation with room for expansion.

The actionColumn is correctly implemented using the createActionColumn function. The TODO comment indicates plans for future actions.

Would you like me to create a GitHub issue to track the TODO for adding other actions to the actionColumn?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9caafc6 and a6f0d74.

Files selected for processing (2)
  • src/app/shared-links/Components/ConfirmationDialog.tsx (1 hunks)
  • src/app/shared-links/Components/LinksTable.tsx (8 hunks)
Additional comments not posted (6)
src/app/shared-links/Components/ConfirmationDialog.tsx (2)

1-8: LGTM: Imports are correct and concise.

The imports are well-structured, only including the necessary components from Material-UI. This approach helps to keep the bundle size optimized.


1-41: Overall assessment: Well-implemented component meeting PR requirements.

The ConfirmationDialog component has been successfully implemented, addressing the need for a confirmation step before deactivating links. The code follows React and TypeScript best practices, and the dialog content accurately reflects the requirements specified in the PR comments.

Key points:

  1. Proper use of Material-UI components
  2. TypeScript for type safety
  3. Adherence to the specified dialog content
  4. Correct handling of dialog open/close states and actions

The suggested minor improvements (using an interface for props, adding an aria-label, and removing the default export) will further enhance the code quality and maintainability.

Great job on implementing this feature!

src/app/shared-links/Components/LinksTable.tsx (4)

4-4: LGTM: New imports for deactivation functionality.

The added imports are appropriate for implementing the link deactivation feature and confirmation dialog.

Also applies to: 16-21, 32-32


44-59: LGTM: Well-structured interface and function for action columns.

The IActionColumn interface and createActionColumn function are well-defined and promote code reusability for action columns.


132-133: LGTM: Action column successfully integrated into the table.

The changes correctly add the "Actions" column to the table header and render the action buttons in the table body. The implementation looks good and consistent with the rest of the table structure.

Also applies to: 166-166, 174-194


213-217: LGTM: ConfirmationDialog integration for link deactivation.

The ConfirmationDialog component is correctly integrated, addressing the PR objective to prevent accidental link deactivation.

To ensure the dialog message matches the suggested text in the PR objectives, please run the following script:

src/app/shared-links/Components/LinksTable.tsx Outdated Show resolved Hide resolved
src/app/shared-links/Components/LinksTable.tsx Outdated Show resolved Hide resolved
@amalessid amalessid requested a review from medchedli September 24, 2024 15:59
@medchedli
Copy link
Member

@amalessid 👍 looks good. I just left a small comment regarding the Tooltip component. Also make sure to resolve the conflict before merging.

@yassinedorbozgithub yassinedorbozgithub merged commit 81439e1 into main Sep 25, 2024
3 checks passed
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.

Deactivate link
4 participants