1
1
import { default as Table , TableProps , ColumnType } from "antd/es/table" ;
2
- import { TableCellContext , TableRowContext } from "./tableContext" ;
2
+ import { TableRowContext } from "./tableContext" ;
3
3
import { TableToolbar } from "./tableToolbarComp" ;
4
4
import { RowColorViewType , RowHeightViewType , TableEventOptionValues } from "./tableTypes" ;
5
5
import {
@@ -50,8 +50,6 @@ import { SkeletonButtonProps } from "antd/es/skeleton/Button";
50
50
import { ThemeContext } from "@lowcoder-ee/comps/utils/themeContext" ;
51
51
import { useUpdateEffect } from "react-use" ;
52
52
53
- export const EMPTY_ROW_KEY = 'empty_row' ;
54
-
55
53
function genLinerGradient ( color : string ) {
56
54
return isValidColor ( color ) ? `linear-gradient(${ color } , ${ color } )` : color ;
57
55
}
@@ -378,15 +376,14 @@ interface TableTdProps {
378
376
$style : TableColumnStyleType & { rowHeight ?: string } ;
379
377
$defaultThemeDetail : ThemeDetail ;
380
378
$linkStyle ?: TableColumnLinkStyleType ;
381
- $isEditing : boolean ;
382
379
$tableSize ?: string ;
383
380
$autoHeight ?: boolean ;
384
381
$customAlign ?: 'left' | 'center' | 'right' ;
385
382
}
386
383
const TableTd = styled . td < TableTdProps > `
387
384
.ant-table-row-expand-icon,
388
385
.ant-table-row-indent {
389
- display: ${ ( props ) => ( props . $isEditing ? "none" : " initial" ) } ;
386
+ display: initial;
390
387
}
391
388
&.ant-table-row-expand-icon-cell {
392
389
background: ${ ( props ) => props . $background } ;
@@ -398,11 +395,8 @@ const TableTd = styled.td<TableTdProps>`
398
395
padding: 0 !important;
399
396
text-align: ${ ( props ) => props . $customAlign || 'left' } !important;
400
397
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 } ;
406
400
color: ${ ( props ) => props . $style . text } ;
407
401
font-weight: ${ ( props ) => props . $style . textWeight } ;
408
402
font-family: ${ ( props ) => props . $style . fontFamily } ;
@@ -601,7 +595,6 @@ const TableCellView = React.memo((props: {
601
595
...restProps
602
596
} = props ;
603
597
604
- const [ editing , setEditing ] = useState ( false ) ;
605
598
const rowContext = useContext ( TableRowContext ) ;
606
599
607
600
// Memoize style calculations
@@ -655,7 +648,6 @@ const TableCellView = React.memo((props: {
655
648
$style = { style ! }
656
649
$defaultThemeDetail = { defaultTheme }
657
650
$linkStyle = { linkStyle }
658
- $isEditing = { editing }
659
651
$tableSize = { tableSize }
660
652
$autoHeight = { autoHeight }
661
653
$customAlign = { customAlign }
@@ -668,11 +660,7 @@ const TableCellView = React.memo((props: {
668
660
) ;
669
661
}
670
662
671
- return (
672
- < TableCellContext . Provider value = { { isEditing : editing , setIsEditing : setEditing } } >
673
- { tdView }
674
- </ TableCellContext . Provider >
675
- ) ;
663
+ return tdView ;
676
664
} ) ;
677
665
678
666
const TableRowView = React . memo ( ( props : any ) => {
@@ -809,26 +797,13 @@ ResizeableTableComp.whyDidYouRender = true;
809
797
const ResizeableTable = React . memo ( ResizeableTableComp ) as typeof ResizeableTableComp ;
810
798
811
799
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
+
824
801
825
802
export const TableCompView = React . memo ( ( props : {
826
803
comp : InstanceType < typeof TableImplComp > ;
827
804
onRefresh : ( allQueryNames : Array < string > , setLoading : ( loading : boolean ) => void ) => void ;
828
805
onDownload : ( fileName : string ) => void ;
829
806
} ) => {
830
- const [ expandedRowKeys , setExpandedRowKeys ] = useState < string [ ] > ( [ ] ) ;
831
- const [ emptyRowsMap , setEmptyRowsMap ] = useState < Record < string , RecordType > > ( { } ) ;
832
807
const editorState = useContext ( EditorContext ) ;
833
808
const currentTheme = useContext ( ThemeContext ) ?. theme ;
834
809
const showDataLoadingIndicators = currentTheme ?. showDataLoadingIndicators ;
@@ -865,10 +840,8 @@ export const TableCompView = React.memo((props: {
865
840
const toolbar = useMemo ( ( ) => compChildren . toolbar . getView ( ) , [ compChildren . toolbar ] ) ;
866
841
const showSummary = useMemo ( ( ) => compChildren . showSummary . getView ( ) , [ compChildren . showSummary ] ) ;
867
842
const summaryRows = useMemo ( ( ) => compChildren . summaryRows . getView ( ) , [ compChildren . summaryRows ] ) ;
868
- const inlineAddNewRow = useMemo ( ( ) => compChildren . inlineAddNewRow . getView ( ) , [ compChildren . inlineAddNewRow ] ) ;
869
843
const pagination = useMemo ( ( ) => compChildren . pagination . getView ( ) , [ compChildren . pagination ] ) ;
870
844
const size = useMemo ( ( ) => compChildren . size . getView ( ) , [ compChildren . size ] ) ;
871
- const editModeClicks = useMemo ( ( ) => compChildren . editModeClicks . getView ( ) , [ compChildren . editModeClicks ] ) ;
872
845
const onEvent = useMemo ( ( ) => compChildren . onEvent . getView ( ) , [ compChildren . onEvent ] ) ;
873
846
const dynamicColumn = compChildren . dynamicColumn . getView ( ) ;
874
847
const dynamicColumnConfig = useMemo (
@@ -886,7 +859,6 @@ export const TableCompView = React.memo((props: {
886
859
dynamicColumn ,
887
860
dynamicColumnConfig ,
888
861
columnsAggrData ,
889
- editModeClicks ,
890
862
onEvent ,
891
863
) ,
892
864
[
@@ -897,7 +869,6 @@ export const TableCompView = React.memo((props: {
897
869
dynamicColumn ,
898
870
dynamicColumnConfig ,
899
871
columnsAggrData ,
900
- editModeClicks ,
901
872
]
902
873
) ;
903
874
@@ -906,69 +877,6 @@ export const TableCompView = React.memo((props: {
906
877
[ compChildren . data ]
907
878
) ;
908
879
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
-
972
880
973
881
const pageDataInfo = useMemo ( ( ) => {
974
882
// Data pagination
@@ -1001,10 +909,6 @@ export const TableCompView = React.memo((props: {
1001
909
1002
910
const handleChangeEvent = useCallback (
1003
911
( eventName : TableEventOptionValues ) => {
1004
- if ( eventName === "saveChanges" && ! compChildren . onEvent . isBind ( eventName ) ) {
1005
- ! viewMode && messageInstance . warning ( trans ( "table.saveChangesNotBind" ) ) ;
1006
- return ;
1007
- }
1008
912
compChildren . onEvent . getView ( ) ( eventName ) ;
1009
913
setTimeout ( ( ) => compChildren . columns . dispatchClearChangeSet ( ) ) ;
1010
914
} ,
@@ -1031,14 +935,6 @@ export const TableCompView = React.memo((props: {
1031
935
handleChangeEvent ( "download" ) ;
1032
936
onDownload ( `${ compName } -data` )
1033
937
} }
1034
- hasChange = { hasChange }
1035
- onSaveChanges = { ( ) => handleChangeEvent ( "saveChanges" ) }
1036
- onCancelChanges = { ( ) => {
1037
- handleChangeEvent ( "cancelChanges" ) ;
1038
- if ( inlineAddNewRow ) {
1039
- setEmptyRowsMap ( { } ) ;
1040
- }
1041
- } }
1042
938
onEvent = { onEvent }
1043
939
/>
1044
940
) ;
@@ -1118,7 +1014,7 @@ export const TableCompView = React.memo((props: {
1118
1014
columnsStyle = { columnsStyle }
1119
1015
viewModeResizable = { compChildren . viewModeResizable . getView ( ) }
1120
1016
visibleResizables = { compChildren . visibleResizables . getView ( ) }
1121
- dataSource = { pageDataInfo . data . concat ( Object . values ( emptyRowsMap ) ) }
1017
+ dataSource = { pageDataInfo . data }
1122
1018
size = { compChildren . size . getView ( ) }
1123
1019
rowAutoHeight = { rowAutoHeight }
1124
1020
tableLayout = "fixed"
0 commit comments