index.tsx

Overview

This file defines a React functional component named ChunkPage. It serves as a page layout that provides navigation and UI controls related to a data chunk or dataset view within a larger application. The component integrates breadcrumb navigation, segmented controls for switching views, and action buttons, while rendering nested routes using React Router's <Outlet />.

The primary purpose of this file is to create a user interface that allows users to navigate between different result views (Parsed results, Chunk result, Result view) related to a dataset or chunk and to provide contextual breadcrumbs for easy navigation back to higher-level pages.


Component: ChunkPage

Description

ChunkPage is a React component that renders:

It uses hooks to manage navigation, reads the current URL location to determine the active segment, and dynamically generates UI options.


Imports and Dependencies


Functions and Hooks Used

useNavigatePage()

useLocation()


Component Implementation Details

export default function ChunkPage() {
  const { navigateToDataset, getQueryString, navigateToChunk } = useNavigatePage();
  const location = useLocation();

  // Memoized options for the segmented control (tabs)
  const options = useMemo(() => {
    return [
      { label: 'Parsed results', value: Routes.ParsedResult },
      { label: 'Chunk result', value: Routes.ChunkResult },
      { label: 'Result view', value: Routes.ResultView },
    ];
  }, []);

  // Extract base path from current location for segmented control value
  const path = useMemo(() => {
    return location.pathname.split('/').slice(0, 3).join('/');
  }, [location.pathname]);

  return (
    <section>
      <PageHeader>
        {/* Breadcrumb navigation */}
        <Breadcrumb>
          <BreadcrumbList>
            <BreadcrumbItem>
              <BreadcrumbLink
                onClick={navigateToDataset(getQueryString(QueryStringMap.KnowledgeId) as string)}
              >
                Agent
              </BreadcrumbLink>
            </BreadcrumbItem>
            <BreadcrumbSeparator />
            <BreadcrumbItem>
              <BreadcrumbPage>xxx</BreadcrumbPage>
            </BreadcrumbItem>
          </BreadcrumbList>
        </Breadcrumb>

        {/* Segmented control for switching views */}
        <div>
          <Segmented
            options={options}
            value={path}
            onChange={navigateToChunk as (val: SegmentedValue) => void}
          />
        </div>

        {/* Action buttons */}
        <div className="flex items-center gap-2">
          <Button variant={'icon'} size={'icon'}>
            <EllipsisVertical />
          </Button>
          <Button size={'sm'}>
            <Save />
            Save
          </Button>
        </div>
      </PageHeader>

      {/* Render nested routes */}
      <Outlet />
    </section>
  );
}

Parameters


Return Value


Usage Example

This component is typically used as a page route in the application's routing configuration:

{
  path: '/chunk',
  component: ChunkPage,
  routes: [
    { path: 'parsed-result', component: ParsedResultComponent },
    { path: 'chunk-result', component: ChunkResultComponent },
    { path: 'result-view', component: ResultViewComponent },
  ],
}

Rendering ChunkPage will display the header and segmented controls, and the nested child route component will be rendered inside <Outlet /> based on the current path.


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram: Component Structure and Interaction

componentDiagram
    ChunkPage <|-- PageHeader
    PageHeader <|-- Breadcrumb
    Breadcrumb *-- BreadcrumbList
    BreadcrumbList *-- BreadcrumbItem
    BreadcrumbItem *-- BreadcrumbLink
    BreadcrumbItem *-- BreadcrumbPage
    BreadcrumbList *-- BreadcrumbSeparator

    PageHeader *-- Segmented
    PageHeader *-- Button

    ChunkPage *-- Outlet

    note right of ChunkPage
      - Uses useNavigatePage hook
      - Uses useLocation hook
      - Controls navigation and UI state
    end note

Summary


This documentation provides a thorough understanding of the file's purpose, components, and interactions, enabling easy maintenance and enhancement by developers.