import { DataSetPage } from '@/services/data/console/dataset' ; import { useEffect , useState } from 'react' ; import { GridWrapper } from './body' ; import { useGridEventBus } from './grid-event-bus' ; import { GridEventTypes } from './grid-event-bus-types' ; import { GridHeader } from './header' ; import { ColumnDefs , DataPage , DataSetState } from './types' ; import { DataSetGridContainer } from './widgets' ; /**
 * structure and data of grid are passed to this component through event  GridEventTypes . DATA_LOADED .<br>
 * if pagination feature is on, handle  props . onPageChange to provide data, also via event  GridEventTypes . DATA_LOADED .<br>
 * for  props . simulating , through toggle and upload button is in grid itself,
 * switch value will be sent by  GridEventTypes . SIMULATOR_SWITCHED , handle it and repaint grid, otherwise ui will not be changed.<br>
 * for  GridEventTypes . SIMULATE_DATA_UPLOADED fired by upload button, handle it and notify grid via event  GridEventTypes . DATA_LOADED .
 *
 *  param props . hasColumns param props . simulateEnabled param props . simulating param props . pageable enable pagination, default true(feature on). will be ignored when  props . simulateEnabled is on.
 *  param props . onPageChange param props . downloadAll param props . languagesSupport export const Grid = ( props ) => { const { hasColumns , simulateEnabled , simulating = false , pageable , onPageChange , downloadAll , languagesSupport = true } = props ; const { on , off } = useGridEventBus ( ) ; const [ data , setData ] = useState < DataSetState > ( { itemCount : 0 , pageNumber : 1 , pageSize : 1 , pageCount : 1 , data : [ ] , loaded : false , columnDefs : { fixed : [ ] , data : [ ] } } ) ; useEffect ( ( ) => { if ( ! hasColumns ) { return ; } const onDataLoaded = ( page , columnDefs ) => { setData ( { ... page , loaded : true , columnDefs } ) ; } ; on ( GridEventTypes . DATA_LOADED , onDataLoaded ) ; return ( ) => { off ( GridEventTypes . DATA_LOADED , onDataLoaded ) ; } ; } , [ on , off , hasColumns ] ) ; if ( ! hasColumns || ! data . loaded ) { return null ; } return < DataSetGridContainer > < GridHeader data = { data } canSimulate = { simulateEnabled } simulating = { simulating } pageable = { pageable } onPageChange = { onPageChange } downloadAll = { downloadAll } languagesSupport = { languagesSupport } / > < GridWrapper data = { data } languagesSupport = { languagesSupport } / > < /DataSetGridContainer>; } ;