dataset-filter.tsx


Overview

dataset-filter.tsx is a React functional component that provides an interactive filter and search interface specifically designed for filtering and toggling between different log views in a dataset context. It supports toggling between two main log tabs (File Logs and Dataset Logs), applying multiple filter criteria through a popover interface, and searching within the selected logs.

The component is intended for use in applications dealing with dataset logs management or visualization, allowing users to efficiently locate and filter log entries with a combination of tab selection, multi-filters, and text search.


Component: DatasetFilter

Description

DatasetFilter is the main and only exported component in this file. It combines:

This combination facilitates a rich and flexible dataset log filtering UI.

Props

The component takes a combination of its own props (IProps) and props from CheckboxFormMultipleProps (excluding setOpen).

IProps

Prop Name

Type

Optional

Description

searchString

string

Yes

Current search input string used to filter logs by text.

onSearchChange

ChangeEventHandler

Yes

Callback fired on search input changes.

active

(typeof LogTabs)[keyof typeof LogTabs]

Yes

Currently active log tab, either FILE_LOGS or DATASET_LOGS. Defaults to FILE_LOGS.

setActive

(active: (typeof LogTabs)[keyof typeof LogTabs]) => void

Yes

Callback to update the active log tab when the user toggles between tabs.

CheckboxFormMultipleProps (Partial)

These props are spread in and control the multi-checkbox filter popover:

Prop Name

Type

Description

value

object

Current filter selections (keyed by filter name).

onChange

func

Callback when filter selections change.

filters

array

Available filter options.

onOpenChange

func

Callback when the filter popover is opened/closed.

Return Value

The component returns JSX elements representing the UI controls for filtering and searching dataset logs.


Detailed Implementation

Tab Buttons

Filter Popover

Search Input

Localization


Usage Example

import { DatasetFilter } from './dataset-filter';
import { LogTabs } from './dataset-common';
import { useState } from 'react';

const MyComponent = () => {
  const [activeTab, setActiveTab] = useState(LogTabs.FILE_LOGS);
  const [search, setSearch] = useState('');
  const [filters, setFilters] = useState({});

  return (
    <DatasetFilter
      active={activeTab}
      setActive={setActiveTab}
      searchString={search}
      onSearchChange={e => setSearch(e.target.value)}
      value={filters}
      onChange={newFilters => setFilters(newFilters)}
      filters={[/* array of filter options */]}
    />
  );
};

Important Implementation Details


Interaction with Other Parts of the System

This file is primarily a UI component and interacts with the application state via props and callbacks, relying on parent components or contexts to supply data and handle user input.


Mermaid Component Diagram

componentDiagram
    component DatasetFilter {
        +props: IProps & Omit<CheckboxFormMultipleProps, 'setOpen'>
        +render()
    }
    component FilterPopover {
        +value
        +onChange
        +filters
        +onOpenChange
    }
    component FilterButton {
        +count
    }
    component Button {
        +onClick
        +className
    }
    component SearchInput {
        +value
        +onChange
        +className
    }
    DatasetFilter --> Button : "File Logs Button"
    DatasetFilter --> Button : "Dataset Logs Button"
    DatasetFilter --> FilterPopover
    FilterPopover --> FilterButton
    DatasetFilter --> SearchInput

Summary

dataset-filter.tsx is a reusable React component that provides a tabbed interface for toggling between log types, a filter popover for multi-select filters, and a search input, making it a central UI element for dataset log filtering functionality. The component is well-structured with clear separation of concerns and integrates smoothly with external localization, UI libraries, and filter handling mechanisms.