use-bulk-operate-dataset.tsx


Overview

The useBulkOperateDataset file exports a React custom hook designed for managing bulk operations on a dataset of documents within a table or list UI. It provides a standardized interface to perform batch actions on selected documents, such as enabling/disabling, running, cancelling, or deleting them. This hook integrates with various document-related APIs and application state hooks, facilitating user interactions and feedback through toast notifications and localized labels.

This hook is particularly useful in UI components that support multi-row selection and bulk manipulation, helping to encapsulate the logic required to handle multiple documents and their different states in an efficient and user-friendly manner.


Detailed Documentation

useBulkOperateDataset

Description

A React hook that manages bulk operations on a list of documents based on the currently selected rows in a UI table or list.

Parameters

Returns

Usage Example

const { list } = useBulkOperateDataset({
  rowSelection,
  setRowSelection,
  documents,
});

// Example usage in a toolbar
return (
  <div>
    {list.map(({ id, label, icon, onClick }) => (
      <button key={id} onClick={onClick} title={label}>
        {icon} {label}
      </button>
    ))}
  </div>
);

Internal Functions and Methods

1. runDocument(run: number): void


2. handleRunClick(): void


3. handleCancelClick(): void


4. onChangeStatus(enabled: boolean): void


5. handleEnableClick(): void


6. handleDisableClick(): void


7. handleDelete(): Promise<number | void>


Important Implementation Details


Interaction with Other System Parts


Mermaid Diagram: Component Interaction Diagram

componentDiagram
    component useBulkOperateDataset {
        +rowSelection
        +setRowSelection
        +documents
        --
        +list[]
    }

    component useSelectedIds {
        +selectedIds
    }

    component useRunDocument {
        +runDocumentByIds()
    }

    component useSetDocumentStatus {
        +setDocumentStatus()
    }

    component useRemoveDocument {
        +removeDocument()
    }

    useBulkOperateDataset --> useSelectedIds : get selectedRowKeys
    useBulkOperateDataset --> useRunDocument : runDocumentByIds()
    useBulkOperateDataset --> useSetDocumentStatus : setDocumentStatus()
    useBulkOperateDataset --> useRemoveDocument : removeDocument()

Summary

The useBulkOperateDataset hook is a focused utility for managing batch operations on datasets of documents, providing a clean API for UI components to trigger enabling, disabling, running, cancelling, and deleting multiple documents with proper validation and feedback. It leverages multiple custom hooks for state management and API interactions, ensuring robust and consistent behavior in document management scenarios.