# All files / src/components/features/snippet-display SnippetCardActions.tsx

98.46% Statements 128/130
33.33% Branches 1/3
33.33% Functions 1/3
98.46% Lines 128/130

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    1311x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x

    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
    8x
     import { Button } from '@/components/ui/button'
    import {
      DropdownMenu,
      DropdownMenuContent,
      DropdownMenuItem,
      DropdownMenuSeparator,
      DropdownMenuSub,
      DropdownMenuSubContent,
      DropdownMenuSubTrigger,
      DropdownMenuTrigger,
    } from '@/components/ui/dropdown-menu'
    import { Copy, Pencil, Trash, Eye, DotsThree, FolderOpen } from '@phosphor-icons/react'
    import { Namespace } from '@/lib/types'
    import { strings } from '@/lib/config'

    interface SnippetCardActionsProps {
      isCopied: boolean
      isMoving: boolean
      availableNamespaces: Namespace[]
      onView: (e: React.MouseEvent) => void
      onCopy: (e: React.MouseEvent) => void
      onEdit: (e: React.MouseEvent) => void
      onDelete: (e: React.MouseEvent) => void
      onMoveToNamespace: (namespaceId: string) => void
    }

    export function SnippetCardActions({
      isCopied,
      isMoving,
      availableNamespaces,
      onView,
      onCopy,
      onEdit,
      onDelete,
      onMoveToNamespace,
    }: SnippetCardActionsProps) {
      return (
        <div className="flex items-center justify-between gap-2 pt-2">
          <div className="flex-1 flex items-center gap-2">
            <Button
              variant="ghost"
              size="sm"
              onClick={onView}
              className="gap-2"
              data-testid="snippet-card-view-btn"
              aria-label="View snippet"
            >
              <Eye className="h-4 w-4" aria-hidden="true" />
              {strings.snippetCard.viewButton}
            </Button>
          </div>
          <div className="flex items-center gap-2">
            <Button
              variant="ghost"
              size="sm"
              onClick={onCopy}
              className="gap-2"
              data-testid="snippet-card-copy-btn"
              aria-label={strings.snippetCard.ariaLabels.copy}
            >
              <Copy className="h-4 w-4" aria-hidden="true" />
              {isCopied ? strings.snippetCard.copiedButton : strings.snippetCard.copyButton}
            </Button>
            <Button
              variant="ghost"
              size="sm"
              onClick={onEdit}
              data-testid="snippet-card-edit-btn"
              aria-label={strings.snippetCard.ariaLabels.edit}
            >
              <Pencil className="h-4 w-4" aria-hidden="true" />
            </Button>

            <DropdownMenu>
              <DropdownMenuTrigger asChild>
                <Button
                  variant="ghost"
                  size="sm"
                  onClick={(e) => e.stopPropagation()}
                  data-testid="snippet-card-actions-menu"
                  aria-label="More options"
                >
                  <DotsThree className="h-4 w-4" weight="bold" aria-hidden="true" />
                </Button>
              </DropdownMenuTrigger>
              <DropdownMenuContent align="end" onClick={(e) => e.stopPropagation()}>
                <DropdownMenuSub>
                  <DropdownMenuSubTrigger
                    disabled={isMoving || availableNamespaces.length === 0}
                    data-testid="snippet-card-move-submenu"
                  >
                    <FolderOpen className="h-4 w-4 mr-2" aria-hidden="true" />
                    <span>Move to...</span>
                  </DropdownMenuSubTrigger>
                  <DropdownMenuSubContent>
                    {availableNamespaces.length === 0 ? (
                      <DropdownMenuItem disabled>
                        No other namespaces
                      </DropdownMenuItem>
                    ) : (
                      availableNamespaces.map((namespace) => (
                        <DropdownMenuItem
                          key={namespace.id}
                          onClick={() => onMoveToNamespace(namespace.id)}
                          data-testid={`move-to-namespace-${namespace.id}`}
                        >
                          {namespace.name}
                          {namespace.isDefault && (
                            <span className="ml-2 text-xs text-muted-foreground">(Default)</span>
                          )}
                        </DropdownMenuItem>
                      ))
                    )}
                  </DropdownMenuSubContent>
                </DropdownMenuSub>
                <DropdownMenuSeparator />
                <DropdownMenuItem
                  onClick={onDelete}
                  className="text-destructive focus:text-destructive"
                  data-testid="snippet-card-delete-btn"
                >
                  <Trash className="h-4 w-4 mr-2" aria-hidden="true" />
                  Delete
                </DropdownMenuItem>
              </DropdownMenuContent>
            </DropdownMenu>
          </div>
        </div>
      )
    }