index.tsx
Overview
The index.tsx file defines a React functional component named YahooFinanceForm. This component renders a form interface that allows users to configure which types of Yahoo Finance data they want to include, such as basic info, historical data, financials, balance sheet, cash flow statement, and news. The form uses Ant Design UI components for layout and input controls, and a custom hook for translations, enabling internationalization support.
The form is designed to be controlled externally via props: it receives a form instance (form), a node object (node), and an onValuesChange callback that is triggered whenever a form field's value changes. This setup facilitates integration into a larger workflow or data processing system where these form values are used to configure an operator or node.
Component: YahooFinanceForm
Description
YahooFinanceForm is a React functional component that renders a vertical layout form with several toggle switches. Each switch corresponds to a particular type of data the user can enable or disable for the Yahoo Finance node/operator.
Props
The component accepts a single props object that matches the interface IOperatorForm:
interface IOperatorForm {
onValuesChange: (changedValues: any, allValues: any) => void;
form: FormInstance;
node: any;
}
onValuesChange
(changedValues: any, allValues: any) => void
A callback function triggered when any form field changes. It receives the changed fields and the entire form state.form
FormInstance
An Ant DesignForminstance controlling the form state externally.node
any
An object representing the current node or operator configuration, passed down to child components.
Usage Example
import React from 'react';
import { Form } from 'antd';
import YahooFinanceForm from './index';
const MyComponent = () => {
const [form] = Form.useForm();
const handleValuesChange = (changedValues, allValues) => {
console.log('Form changed:', changedValues, allValues);
};
const node = { id: 'node1', type: 'YahooFinance' };
return (
<YahooFinanceForm
form={form}
node={node}
onValuesChange={handleValuesChange}
/>
);
};
Rendered Form Fields
Dynamic Input Variable
A custom component<DynamicInputVariable>is rendered at the top, which likely allows dynamic configuration of input variables for this node. It receives thenodeprop.Switches
Six toggles control which Yahoo Finance data to fetch or process:Label (Translation Key)
Form Field Name
Description
info"info"Toggle basic info data
history"history"Toggle historical data
financials"financials"Toggle financial statements
balanceSheet"balance_sheet"Toggle balance sheet data
cashFlowStatement"cash_flow_statement"Toggle cash flow statement data
news"news"Toggle related news data
Each switch is wrapped in an Ant Design Form.Item with a translated label fetched via the useTranslate hook scoped to the "flow" namespace.
Implementation Details
Internationalization:
The component uses a custom hookuseTranslatethat returns a translation functiont. This function is called with keys such as'info'or'news'to fetch localized labels for the switches.Form Controlled by Ant Design:
The component relies on Ant Design'sFormcomponent for layout and state management. Theforminstance is passed in from a parent component, enabling external control and validation.DynamicInputVariable Integration:
The form integrates a specialized componentDynamicInputVariablewhich accepts the currentnodeobject. Though not detailed here, this component likely provides dynamic form inputs based on node context.Switch Inputs:
Each data option is represented by an Ant DesignSwitchcomponent, which is a boolean toggle input.Event Handling:
The form listens for any value changes via theonValuesChangeprop, propagating changes upward for external state sync or side effects.
Interaction with Other Parts of the System
Hooks:
useTranslatehook from'@/hooks/common-hooks'provides translation capabilities.
Interface:
IOperatorForminterface imported from'../../interface'defines the expected props shape.
Components:
DynamicInputVariablecomponent imported from'../components/dynamic-input-variable'is used to render dynamic form inputs related to the node.
UI Library:
Ant Design (
antd) components (Form,Switch) are used for layout and form controls.
Parent Components:
This form component is designed to be embedded within a larger workflow or editor interface where nodes/operators are configured. The externalforminstance allows the parent component to manage form state, trigger validations, and extract data for processing.
Visual Diagram
componentDiagram
component YahooFinanceForm {
+props: IOperatorForm
+render()
}
component Form {
+name
+autoComplete
+form (FormInstance)
+onValuesChange
+layout
}
component DynamicInputVariable {
+props: { node }
+render()
}
component Switch {
+toggle()
}
YahooFinanceForm --> Form
Form *-- DynamicInputVariable
Form *-- Switch: info
Form *-- Switch: history
Form *-- Switch: financials
Form *-- Switch: balance_sheet
Form *-- Switch: cash_flow_statement
Form *-- Switch: news
Summary
The index.tsx file provides a configurable form component to select which Yahoo Finance data categories to include for a given node in a workflow. It leverages Ant Design's form system and controls, a custom translation hook for localization, and integrates a dynamic input subcomponent. The component is controlled externally via props for seamless integration into complex applications where form state management and node configuration are centralized.