Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | 66x | import React, { ReactElement, useCallback, useEffect, useReducer, useState } from 'react'; import { fetchDomainMeta, fetchCanCreate, fetchFormExtInfo } from '@utils/FetchUtils'; import { FormProps, RecordProps, TableMetaProps } from '@props/RecordProps'; import { PageHeader } from '../../form'; import { LargeSpin } from '../../components'; import './App.less'; import FullTextSearchPanel from './FullTextSearchPanel'; import { dataReducer, initData } from "@utils/hooks"; export interface WithSearchListProps { domainName: string; formId: number; zIndex: number; setOwnerIds?: (ownerIds: Array<number>) => void; initShowCreateModal?: boolean; initDomainId?: number; hideHeaderTitle?: boolean; ownerClass?: string; ownerIds?: Array<number>; ownerClassColumnName?: string; } const FullTextSearchListComponent = (props: WithSearchListProps): ReactElement => { const { domainName, formId, zIndex, initDomainId, initShowCreateModal, hideHeaderTitle, ownerClass, ownerIds, ownerClassColumnName, setOwnerIds } = props; const [canCreate, setCanCreate] = useState<boolean>(false); const [columns, setColumns] = useState<Array<TableMetaProps>>([] as TableMetaProps[]); const [loading, setLoading] = useState<boolean>(true); const [contentDisplayColumns, setContentDisplayColumns] = useState<Array<TableMetaProps>>([]); const [fullTextSearchColumns, setFullTextSearchColumns] = useState<Array<TableMetaProps>>([]); const [additionalSearchColumns, setAdditionalSearchColumns] = useState<Array<TableMetaProps>>([]); const [panelDisplayColumns, setPanelDisplayColumns] = useState<Array<TableMetaProps>>([]); const [sortColumns, setSortColumns] = useState<Array<TableMetaProps>>([]); const [willRefreshData, setWillRefreshData] = useState<boolean>(false); const [formExtInfo, setFormExtInfo] = useState<FormProps>(); const [dataState, dataDispatch] = useReducer(dataReducer, initData); useEffect(() => { setLoading(true); fetchCanCreate(domainName).then(json => { setCanCreate(json.create); }).catch(e => console.error(`Failed to get canCreate of ${domainName}: ${e}`)); fetchFormExtInfo(formId).then((formProps: FormProps) => { setFormExtInfo(formProps); }); fetchDomainMeta(domainName, formId).then((meta: Array<TableMetaProps>) => { setColumns(meta); setContentDisplayColumns(meta.filter(c => c.groupName?.startsWith('contentDisplayGroup'))); setFullTextSearchColumns(meta.filter(c => c.groupName?.startsWith('fullTextSearchConditionGroup'))); setAdditionalSearchColumns(meta.filter(c => c.groupName?.startsWith('additionalSearchConditionGroup'))); setSortColumns(meta.filter(c => c.groupName?.startsWith('sortingConditionGroup'))); setPanelDisplayColumns(meta.filter(c => c.groupName?.startsWith('panelDisplayGroup'))); return meta; }) .finally(() => setLoading(false)) .catch(e => console.error(`Failed to get form ${formId} for domain ${domainName}: ${e}`)); }, [domainName, formId]); const refreshDataCallback = useCallback((): void => { setWillRefreshData(true); }, []); return loading ? (<LargeSpin />) : ( <div className='with-search-container'> {hideHeaderTitle !== true && <PageHeader initDomainId={initDomainId} initShowCreateModal={initShowCreateModal} listForm={formExtInfo ?? {} as FormProps} tableMode={"table-list"} domainName={domainName} data={dataState.data ?? []} selectedData={dataState.selectedData ?? []} columns={columns} enumValues={{}} objectValues={{}} setData={(data: Array<RecordProps>) => dataDispatch({ type: 'set', payload: { data } })} fetchDataCallback={() => refreshDataCallback()} initialCanCreate={canCreate} zIndex={zIndex + 1} ownerClass={ownerClass} ownerId={ownerIds?.[0]} columnNameInOwnerClass={ownerClassColumnName} dataState={dataState} dataDispatch={dataDispatch} createFormName={formExtInfo?.extInfo?.createFormName} /> } <FullTextSearchPanel formExtInfo={formExtInfo} zIndex={zIndex} refreshData={willRefreshData} domainName={domainName} columns={columns} fetchDataCallback={(data: Array<RecordProps>) => { dataDispatch({ type: 'set', payload: { data } }); setWillRefreshData(false); }} additionalSearchColumns={additionalSearchColumns} fullTextSearchColumns={fullTextSearchColumns} sortColumns={sortColumns} panelDisplayColumns={panelDisplayColumns} ownerClass={ownerClass} ownerIds={ownerIds} ownerClassColumnName={ownerClassColumnName} contentDisplayColumns={contentDisplayColumns} changeCallback={(record: RecordProps, selected: boolean): void => { const sd = (dataState.selectedData ?? []); if (selected) { dataDispatch({ type: 'set', payload: { selectedData: [...sd, record] } }); } else { const index = sd.indexOf(record); const newSelectedData = sd.slice(); newSelectedData.splice(index, 1); dataDispatch({ type: 'set', payload: { selectedData: newSelectedData } }); } }} setOwnerIds={setOwnerIds} /> </div> ); }; export default FullTextSearchListComponent; |