index.tsx

Overview

This file defines a React functional component, GoogleScholarForm, which renders a form interface for configuring search parameters tailored to Google Scholar data queries. The form includes inputs for sorting options, year range selection using custom year pickers, toggling patent inclusion, and dynamic variable input. It leverages Ant Design (antd) components for UI elements and integrates with custom hooks and components (useTranslate, useBuildSortOptions, DynamicInputVariable, TopNItem) to provide localized labels, sort option building, and dynamic input management.

Additionally, the file defines a reusable YearPicker component, a wrapper around Ant Design's DatePicker configured to select only years, with logic to convert between dayjs objects and plain year numbers suitable for backend storage.


Detailed Component and Function Documentation

YearPicker Component

const YearPicker = ({
  onChange,
  value,
}: {
  onChange?: (val: number | undefined) => void;
  value?: number | undefined;
}) => { ... }

Purpose

A specialized date picker component that allows users to select only the year (not month or day). It handles the conversion between the display format (dayjs objects) and a simple number (YYYY), which is more suitable for backend processing and storage.

Props

Prop

Type

Description

onChange

`(val: number \

undefined) => void` (optional)

value

`number \

undefined` (optional)

Behavior

Usage Example

<YearPicker
  value={2023}
  onChange={(year) => console.log("Selected year:", year)}
/>

GoogleScholarForm Component

const GoogleScholarForm = ({ onValuesChange, form, node }: IOperatorForm) => { ... }

Purpose

This is the main form component for configuring Google Scholar search query parameters. It allows users to:

Props

GoogleScholarForm conforms to the IOperatorForm interface, which includes:

Prop

Type

Description

onValuesChange

(changedValues, allValues) => void

Callback invoked whenever any form field value changes.

form

Ant Design FormInstance

The form instance used to control form behaviors and values.

node

Object (type not fully detailed)

Represents the current node or context for dynamic variable input.

Internal Logic and Hooks

Form Structure

Field Name

UI Component

Default / Initial Value

Additional Info

Dynamic variables

<DynamicInputVariable />

N/A

Custom component linked to node.

Top N results

<TopNItem />

5

Number of top results to fetch.

sort_by

<Select />

'relevance'

Sorting criteria, options from hook.

year_low

<YearPicker />

undefined

Lower bound of year range.

year_high

<YearPicker />

undefined

Upper bound of year range.

patents

<Switch />

true

Whether to include patents in results.

Usage Example

<GoogleScholarForm
  form={formInstance}
  node={currentNode}
  onValuesChange={(changed, all) => {
    console.log('Form changed:', changed, all);
  }}
/>

Important Implementation Details


Interaction with Other Parts of the System

This file primarily functions as a UI layer for constructing search parameters for Google Scholar queries and interacts with various UI components and hooks that manage localization, dynamic input generation, and sorting options.


Visual Diagram

componentDiagram
    component GoogleScholarForm {
        +onValuesChange
        +form
        +node
        ---
        +DynamicInputVariable(node)
        +TopNItem(initialValue=5)
        +Select(options=useBuildSortOptions())
        +YearPicker(value=year_low)
        +YearPicker(value=year_high)
        +Switch(initialValue=true)
    }

    component YearPicker {
        +value (number | undefined)
        +onChange((number | undefined) => void)
    }

    GoogleScholarForm --> DynamicInputVariable : renders
    GoogleScholarForm --> TopNItem : renders
    GoogleScholarForm --> Select : renders (sort options)
    GoogleScholarForm --> YearPicker : renders (year_low & year_high)
    GoogleScholarForm --> Switch : renders (patents toggle)

Summary

This component is a critical UI part of a larger system that configures and executes Google Scholar search queries or related data retrieval workflows.