11import { default as Table , TableProps , ColumnType } from "antd/es/table" ;
2- import { TableCellContext , TableRowContext } from "./tableContext" ;
2+ import { TableRowContext } from "./tableContext" ;
33import { TableToolbar } from "./tableToolbarComp" ;
44import { RowColorViewType , RowHeightViewType , TableEventOptionValues } from "./tableTypes" ;
55import {
@@ -50,8 +50,6 @@ import { SkeletonButtonProps } from "antd/es/skeleton/Button";
5050import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext" ;
5151import { useUpdateEffect } from "react-use" ;
5252
53- export const EMPTY_ROW_KEY = 'empty_row' ;
54-
5553function genLinerGradient ( color : string ) {
5654 return isValidColor ( color ) ? `linear-gradient(${ color } , ${ color } )` : color ;
5755}
@@ -378,15 +376,14 @@ interface TableTdProps {
378376 $style : TableColumnStyleType & { rowHeight ?: string } ;
379377 $defaultThemeDetail : ThemeDetail ;
380378 $linkStyle ?: TableColumnLinkStyleType ;
381- $isEditing : boolean ;
382379 $tableSize ?: string ;
383380 $autoHeight ?: boolean ;
384381 $customAlign ?: 'left' | 'center' | 'right' ;
385382}
386383const TableTd = styled . td < TableTdProps > `
387384 .ant-table-row-expand-icon,
388385 .ant-table-row-indent {
389- display: ${ ( props ) => ( props . $isEditing ? "none" : " initial" ) } ;
386+ display: initial;
390387 }
391388 &.ant-table-row-expand-icon-cell {
392389 background: ${ ( props ) => props . $background } ;
@@ -398,11 +395,8 @@ const TableTd = styled.td<TableTdProps>`
398395 padding: 0 !important;
399396 text-align: ${ ( props ) => props . $customAlign || 'left' } !important;
400397
401- > div:not(.editing-border, .editing-wrapper),
402- .editing-wrapper .ant-input,
403- .editing-wrapper .ant-input-number,
404- .editing-wrapper .ant-picker {
405- margin: ${ ( props ) => props . $isEditing ? '0px' : props . $style . margin } ;
398+ > div {
399+ margin: ${ ( props ) => props . $style . margin } ;
406400 color: ${ ( props ) => props . $style . text } ;
407401 font-weight: ${ ( props ) => props . $style . textWeight } ;
408402 font-family: ${ ( props ) => props . $style . fontFamily } ;
@@ -601,7 +595,6 @@ const TableCellView = React.memo((props: {
601595 ...restProps
602596 } = props ;
603597
604- const [ editing , setEditing ] = useState ( false ) ;
605598 const rowContext = useContext ( TableRowContext ) ;
606599
607600 // Memoize style calculations
@@ -655,7 +648,6 @@ const TableCellView = React.memo((props: {
655648 $style = { style ! }
656649 $defaultThemeDetail = { defaultTheme }
657650 $linkStyle = { linkStyle }
658- $isEditing = { editing }
659651 $tableSize = { tableSize }
660652 $autoHeight = { autoHeight }
661653 $customAlign = { customAlign }
@@ -668,11 +660,7 @@ const TableCellView = React.memo((props: {
668660 ) ;
669661 }
670662
671- return (
672- < TableCellContext . Provider value = { { isEditing : editing , setIsEditing : setEditing } } >
673- { tdView }
674- </ TableCellContext . Provider >
675- ) ;
663+ return tdView ;
676664} ) ;
677665
678666const TableRowView = React . memo ( ( props : any ) => {
@@ -809,26 +797,13 @@ ResizeableTableComp.whyDidYouRender = true;
809797const ResizeableTable = React . memo ( ResizeableTableComp ) as typeof ResizeableTableComp ;
810798
811799
812- const createNewEmptyRow = (
813- rowIndex : number ,
814- columnsAggrData : ColumnsAggrData ,
815- ) => {
816- const emptyRowData : RecordType = {
817- [ OB_ROW_ORI_INDEX ] : `${ EMPTY_ROW_KEY } _${ rowIndex } ` ,
818- } ;
819- Object . keys ( columnsAggrData ) . forEach ( columnKey => {
820- emptyRowData [ columnKey ] = '' ;
821- } ) ;
822- return emptyRowData ;
823- }
800+
824801
825802export const TableCompView = React . memo ( ( props : {
826803 comp : InstanceType < typeof TableImplComp > ;
827804 onRefresh : ( allQueryNames : Array < string > , setLoading : ( loading : boolean ) => void ) => void ;
828805 onDownload : ( fileName : string ) => void ;
829806} ) => {
830- const [ expandedRowKeys , setExpandedRowKeys ] = useState < string [ ] > ( [ ] ) ;
831- const [ emptyRowsMap , setEmptyRowsMap ] = useState < Record < string , RecordType > > ( { } ) ;
832807 const editorState = useContext ( EditorContext ) ;
833808 const currentTheme = useContext ( ThemeContext ) ?. theme ;
834809 const showDataLoadingIndicators = currentTheme ?. showDataLoadingIndicators ;
@@ -865,10 +840,8 @@ export const TableCompView = React.memo((props: {
865840 const toolbar = useMemo ( ( ) => compChildren . toolbar . getView ( ) , [ compChildren . toolbar ] ) ;
866841 const showSummary = useMemo ( ( ) => compChildren . showSummary . getView ( ) , [ compChildren . showSummary ] ) ;
867842 const summaryRows = useMemo ( ( ) => compChildren . summaryRows . getView ( ) , [ compChildren . summaryRows ] ) ;
868- const inlineAddNewRow = useMemo ( ( ) => compChildren . inlineAddNewRow . getView ( ) , [ compChildren . inlineAddNewRow ] ) ;
869843 const pagination = useMemo ( ( ) => compChildren . pagination . getView ( ) , [ compChildren . pagination ] ) ;
870844 const size = useMemo ( ( ) => compChildren . size . getView ( ) , [ compChildren . size ] ) ;
871- const editModeClicks = useMemo ( ( ) => compChildren . editModeClicks . getView ( ) , [ compChildren . editModeClicks ] ) ;
872845 const onEvent = useMemo ( ( ) => compChildren . onEvent . getView ( ) , [ compChildren . onEvent ] ) ;
873846 const dynamicColumn = compChildren . dynamicColumn . getView ( ) ;
874847 const dynamicColumnConfig = useMemo (
@@ -886,7 +859,6 @@ export const TableCompView = React.memo((props: {
886859 dynamicColumn ,
887860 dynamicColumnConfig ,
888861 columnsAggrData ,
889- editModeClicks ,
890862 onEvent ,
891863 ) ,
892864 [
@@ -897,7 +869,6 @@ export const TableCompView = React.memo((props: {
897869 dynamicColumn ,
898870 dynamicColumnConfig ,
899871 columnsAggrData ,
900- editModeClicks ,
901872 ]
902873 ) ;
903874
@@ -906,69 +877,6 @@ export const TableCompView = React.memo((props: {
906877 [ compChildren . data ]
907878 ) ;
908879
909- const updateEmptyRows = useCallback ( ( ) => {
910- if ( ! inlineAddNewRow ) {
911- setEmptyRowsMap ( { } )
912- setTimeout ( ( ) => compChildren . columns . dispatchClearInsertSet ( ) ) ;
913- return ;
914- }
915-
916- let emptyRows : Record < string , RecordType > = { ...emptyRowsMap } ;
917- const existingRowsKeys = Object . keys ( emptyRows ) ;
918- const existingRowsCount = existingRowsKeys . length ;
919- const updatedRowsKeys = Object . keys ( insertSet ) . filter (
920- key => key . startsWith ( EMPTY_ROW_KEY )
921- ) ;
922- const updatedRowsCount = updatedRowsKeys . length ;
923- const removedRowsKeys = existingRowsKeys . filter (
924- x => ! updatedRowsKeys . includes ( x )
925- ) ;
926-
927- if ( removedRowsKeys . length === existingRowsCount ) {
928- const newRowIndex = 0 ;
929- const newRowKey = `${ EMPTY_ROW_KEY } _${ newRowIndex } ` ;
930- setEmptyRowsMap ( {
931- [ newRowKey ] : createNewEmptyRow ( newRowIndex , columnsAggrData )
932- } ) ;
933- const ele = document . querySelector < HTMLElement > ( `[data-row-key=${ newRowKey } ]` ) ;
934- if ( ele ) {
935- ele . style . display = '' ;
936- }
937- return ;
938- }
939-
940- removedRowsKeys . forEach ( rowKey => {
941- if (
942- rowKey === existingRowsKeys [ existingRowsCount - 1 ]
943- || rowKey === existingRowsKeys [ existingRowsCount - 2 ]
944- ) {
945- delete emptyRows [ rowKey ] ;
946- } else {
947- const ele = document . querySelector < HTMLElement > ( `[data-row-key=${ rowKey } ]` ) ;
948- if ( ele ) {
949- ele . style . display = 'none' ;
950- }
951- }
952- } )
953- const lastRowKey = updatedRowsCount ? updatedRowsKeys [ updatedRowsCount - 1 ] : '' ;
954- const lastRowIndex = lastRowKey ? parseInt ( lastRowKey . replace ( `${ EMPTY_ROW_KEY } _` , '' ) ) : - 1 ;
955-
956- const newRowIndex = lastRowIndex + 1 ;
957- const newRowKey = `${ EMPTY_ROW_KEY } _${ newRowIndex } ` ;
958- emptyRows [ newRowKey ] = createNewEmptyRow ( newRowIndex , columnsAggrData ) ;
959- setEmptyRowsMap ( emptyRows ) ;
960- } , [
961- inlineAddNewRow ,
962- JSON . stringify ( insertSet ) ,
963- setEmptyRowsMap ,
964- createNewEmptyRow ,
965- ] ) ;
966-
967- useEffect ( ( ) => {
968- updateEmptyRows ( ) ;
969- } , [ updateEmptyRows ] ) ;
970-
971-
972880
973881 const pageDataInfo = useMemo ( ( ) => {
974882 // Data pagination
@@ -1001,10 +909,6 @@ export const TableCompView = React.memo((props: {
1001909
1002910 const handleChangeEvent = useCallback (
1003911 ( eventName : TableEventOptionValues ) => {
1004- if ( eventName === "saveChanges" && ! compChildren . onEvent . isBind ( eventName ) ) {
1005- ! viewMode && messageInstance . warning ( trans ( "table.saveChangesNotBind" ) ) ;
1006- return ;
1007- }
1008912 compChildren . onEvent . getView ( ) ( eventName ) ;
1009913 setTimeout ( ( ) => compChildren . columns . dispatchClearChangeSet ( ) ) ;
1010914 } ,
@@ -1031,14 +935,6 @@ export const TableCompView = React.memo((props: {
1031935 handleChangeEvent ( "download" ) ;
1032936 onDownload ( `${ compName } -data` )
1033937 } }
1034- hasChange = { hasChange }
1035- onSaveChanges = { ( ) => handleChangeEvent ( "saveChanges" ) }
1036- onCancelChanges = { ( ) => {
1037- handleChangeEvent ( "cancelChanges" ) ;
1038- if ( inlineAddNewRow ) {
1039- setEmptyRowsMap ( { } ) ;
1040- }
1041- } }
1042938 onEvent = { onEvent }
1043939 />
1044940 ) ;
@@ -1118,7 +1014,7 @@ export const TableCompView = React.memo((props: {
11181014 columnsStyle = { columnsStyle }
11191015 viewModeResizable = { compChildren . viewModeResizable . getView ( ) }
11201016 visibleResizables = { compChildren . visibleResizables . getView ( ) }
1121- dataSource = { pageDataInfo . data . concat ( Object . values ( emptyRowsMap ) ) }
1017+ dataSource = { pageDataInfo . data }
11221018 size = { compChildren . size . getView ( ) }
11231019 rowAutoHeight = { rowAutoHeight }
11241020 tableLayout = "fixed"
0 commit comments