dataset-dropdown.tsx


Overview

dataset-dropdown.tsx defines a React functional component named DatasetDropdown that provides a contextual dropdown menu for managing a dataset entity (IKnowledge). The dropdown menu offers options to rename or delete the dataset, integrating user interaction with backend operations via custom hooks. It leverages reusable UI components such as dropdown menus and confirmation dialogs to ensure a consistent and accessible user experience.

This component is primarily used within dataset management views or lists, where each dataset item can be interacted with through this dropdown menu.


Detailed Description

DatasetDropdown Component

Purpose

Renders a dropdown menu attached to any passed child element. This menu allows users to rename or delete a specific dataset (IKnowledge).


Props

{
  children: React.ReactNode;
  showDatasetRenameModal: (dataset: IKnowledge) => void;
  dataset: IKnowledge;
}

Internal Hooks & State


Event Handlers


JSX Structure and UI Components

The menu includes:

  1. Rename Option

    • Label: localized "Rename"

    • Icon: <PenLine />

    • Action: Opens rename modal

  2. Separator

  3. Delete Option

    • Label: localized "Delete"

    • Icon: <Trash2 />

    • Wrapped in a confirmation dialog to prevent accidental deletion

    • Styled with text-state-error to indicate destructive action


Usage Example

import { DatasetDropdown } from './dataset-dropdown';
import { IKnowledge } from '@/interfaces/database/knowledge';

function DatasetItem({ dataset }: { dataset: IKnowledge }) {
  const { showDatasetRenameModal } = useRenameDataset();

  return (
    <DatasetDropdown dataset={dataset} showDatasetRenameModal={showDatasetRenameModal}>
      <button>Options</button>
    </DatasetDropdown>
  );
}

Important Implementation Details


Interaction with Other Parts of the System


Mermaid Component Diagram

componentDiagram
    component DatasetDropdown {
      +children: ReactNode
      +dataset: IKnowledge
      +showDatasetRenameModal(dataset)
      +handleShowDatasetRenameModal(e)
      +handleDelete()
    }
    component DropdownMenu
    component DropdownMenuTrigger
    component DropdownMenuContent
    component DropdownMenuItem
    component DropdownMenuSeparator
    component ConfirmDeleteDialog
    component useDeleteKnowledge
    component useRenameDataset
    component useTranslation

    DatasetDropdown --> DropdownMenu
    DropdownMenu --> DropdownMenuTrigger
    DropdownMenu --> DropdownMenuContent
    DropdownMenuContent --> DropdownMenuItem
    DropdownMenuContent --> DropdownMenuSeparator
    DropdownMenuContent --> ConfirmDeleteDialog
    ConfirmDeleteDialog --> DropdownMenuItem
    DatasetDropdown ..> useDeleteKnowledge : uses
    DatasetDropdown ..> useRenameDataset : uses
    DatasetDropdown ..> useTranslation : uses

Summary

dataset-dropdown.tsx provides a compact, reusable dropdown menu component tailored for dataset entities. It integrates UI controls for renaming and deleting datasets with proper user confirmation and localization. Through clean separation of concerns—delegating rename modal control and deletion logic to hooks and external components—it fits modularly into a larger dataset management system.

This component enhances user experience by providing an intuitive and safe interface for dataset operations while maintaining consistency with the app's UI/UX standards.