ragflow-pagination.tsx


Overview

ragflow-pagination.tsx defines a reusable React functional component RAGFlowPagination that provides a complete pagination UI control. It enables users to navigate through pages of data, jump between pages, and optionally adjust the page size (number of items per page). The component is designed to be flexible, customizable, and internationalized, making it suitable for use in a data-driven interface where paginated content is displayed.


Exports

RAGFlowPaginationType (Type)

This TypeScript type defines the props accepted by the RAGFlowPagination component:

Prop

Type

Optional

Description

showQuickJumper

boolean

Yes

(Unused in current implementation) Intended for a quick jump to page input.

onChange

(page: number, pageSize: number) => void

Yes

Callback invoked when the current page or page size changes. Receives new page and pageSize.

total

number

Yes

Total number of items across all pages. Defaults to 0.

current

number

Yes

The currently selected page. Defaults to 1.

pageSize

number

Yes

Number of items per page. Defaults to 10.

showSizeChanger

boolean

Yes

Whether to show a dropdown for changing page size. Defaults to true.


RAGFlowPagination (Function Component)

Description

Renders a pagination control with previous/next buttons, page number buttons (with ellipsis for gaps), and optionally a page size selector dropdown.

Props

Uses RAGFlowPaginationType (see above).

Defaults:

State

Key Functionalities

Parameters

RAGFlowPagination(props: RAGFlowPaginationType): JSX.Element

Returns

Usage Example

<RAGFlowPagination
  current={2}
  pageSize={20}
  total={100}
  onChange={(page, size) => {
    console.log(`Page changed to ${page} with size ${size}`);
    // Fetch new data based on page and size
  }}
  showSizeChanger={true}
/>

Implementation Details

Pagination Logic and Displayed Pages

State Synchronization

Event Handlers

Each handler calls the onChange callback with updated values to allow the parent component to react (e.g., fetching new data).

UI Components Usage


Interaction with Other Parts of the System


Mermaid Diagram

classDiagram
    class RAGFlowPagination {
        - currentPage: number
        - currentPageSize: string
        - sizeChangerOptions: RAGFlowSelectOptionType[]
        - pages: number[]
        - displayedPages: number[]
        + RAGFlowPagination(props: RAGFlowPaginationType)
        + changePage(page: number): void
        + handlePreviousPageChange(): void
        + handlePageChange(page: number): () => void
        + handleNextPageChange(): void
        + handlePageSizeChange(size: string): void
    }
    RAGFlowPagination ..> Pagination
    RAGFlowPagination ..> PaginationContent
    RAGFlowPagination ..> PaginationItem
    RAGFlowPagination ..> PaginationLink
    RAGFlowPagination ..> PaginationPrevious
    RAGFlowPagination ..> PaginationNext
    RAGFlowPagination ..> PaginationEllipsis
    RAGFlowPagination ..> RAGFlowSelect

Summary

The RAGFlowPagination component in ragflow-pagination.tsx is a sophisticated, localized React pagination control that supports page navigation, ellipsis for skipped pages, and optional page size selection. It maintains internal state synchronized with props and informs parent components of changes via callbacks, facilitating effective pagination in data-driven applications. The component integrates with shared UI elements and localization utilities for consistent styling and internationalized user experience.