1
1
import { tableDataRowExample } from "comps/comps/tableComp/column/tableColumnListComp" ;
2
2
import { getPageSize } from "comps/comps/tableComp/paginationControl" ;
3
- import { TableCompView } from "comps/comps/tableComp/tableCompView" ;
3
+ import { EMPTY_ROW_KEY , TableCompView } from "comps/comps/tableComp/tableCompView" ;
4
4
import { TableFilter } from "comps/comps/tableComp/tableToolbarComp" ;
5
5
import {
6
6
columnHide ,
@@ -40,7 +40,11 @@ import {
40
40
deferAction ,
41
41
executeQueryAction ,
42
42
fromRecord ,
43
+ FunctionNode ,
44
+ Node ,
43
45
onlyEvalAction ,
46
+ RecordNode ,
47
+ RecordNodeToValue ,
44
48
routeByNameAction ,
45
49
withFunction ,
46
50
wrapChildAction ,
@@ -53,7 +57,7 @@ import { getSelectedRowKeys } from "./selectionControl";
53
57
import { compTablePropertyView } from "./tablePropertyView" ;
54
58
import { RowColorComp , RowHeightComp , TableChildrenView , TableInitComp } from "./tableTypes" ;
55
59
56
- import { useContext } from "react" ;
60
+ import { useContext , useState } from "react" ;
57
61
import { EditorContext } from "comps/editorState" ;
58
62
59
63
export class TableImplComp extends TableInitComp implements IContainer {
@@ -401,12 +405,11 @@ export class TableImplComp extends TableInitComp implements IContainer {
401
405
) [ 0 ] ;
402
406
}
403
407
404
- changeSetNode ( ) {
405
- const nodes = {
406
- dataIndexes : this . children . columns . getColumnsNode ( "dataIndex" ) ,
407
- renders : this . children . columns . getColumnsNode ( "render" ) ,
408
- } ;
409
- const resNode = withFunction ( fromRecord ( nodes ) , ( input ) => {
408
+ private getUpsertSetResNode (
409
+ nodes : Record < string , RecordNode < Record < string , Node < any > > > > ,
410
+ filterNewRows ?: boolean ,
411
+ ) {
412
+ return withFunction ( fromRecord ( nodes ) , ( input ) => {
410
413
// merge input.dataIndexes and input.withParams into one structure
411
414
const dataIndexRenderDict = _ ( input . dataIndexes )
412
415
. mapValues ( ( dataIndex , idx ) => input . renders [ idx ] )
@@ -416,26 +419,45 @@ export class TableImplComp extends TableInitComp implements IContainer {
416
419
_ . forEach ( dataIndexRenderDict , ( render , dataIndex ) => {
417
420
_ . forEach ( render [ MAP_KEY ] , ( value , key ) => {
418
421
const changeValue = ( value . comp as any ) . comp . changeValue ;
419
- if ( ! _ . isNil ( changeValue ) ) {
422
+ const includeRecord = ( filterNewRows && key . startsWith ( EMPTY_ROW_KEY ) ) || ( ! filterNewRows && ! key . startsWith ( EMPTY_ROW_KEY ) ) ;
423
+ if ( ! _ . isNil ( changeValue ) && includeRecord ) {
420
424
if ( ! record [ key ] ) record [ key ] = { } ;
421
425
record [ key ] [ dataIndex ] = changeValue ;
422
426
}
423
427
} ) ;
424
428
} ) ;
425
429
return record ;
426
430
} ) ;
431
+ }
432
+
433
+ changeSetNode ( ) {
434
+ const nodes = {
435
+ dataIndexes : this . children . columns . getColumnsNode ( "dataIndex" ) ,
436
+ renders : this . children . columns . getColumnsNode ( "render" ) ,
437
+ } ;
438
+
439
+ const resNode = this . getUpsertSetResNode ( nodes ) ;
427
440
return lastValueIfEqual ( this , "changeSetNode" , [ resNode , nodes ] as const , ( a , b ) =>
428
441
shallowEqual ( a [ 1 ] , b [ 1 ] )
429
442
) [ 0 ] ;
430
443
}
431
444
432
- toUpdateRowsNode ( ) {
445
+ insertSetNode ( ) {
433
446
const nodes = {
434
- oriDisplayData : this . oriDisplayDataNode ( ) ,
435
- indexes : this . displayDataIndexesNode ( ) ,
436
- changeSet : this . changeSetNode ( ) ,
447
+ dataIndexes : this . children . columns . getColumnsNode ( "dataIndex" ) ,
448
+ renders : this . children . columns . getColumnsNode ( "render" ) ,
437
449
} ;
438
- const resNode = withFunction ( fromRecord ( nodes ) , ( input ) => {
450
+
451
+ const resNode = this . getUpsertSetResNode ( nodes , true ) ;
452
+ return lastValueIfEqual ( this , "insertSetNode" , [ resNode , nodes ] as const , ( a , b ) =>
453
+ shallowEqual ( a [ 1 ] , b [ 1 ] )
454
+ ) [ 0 ] ;
455
+ }
456
+
457
+ private getToUpsertRowsResNodes (
458
+ nodes : Record < string , FunctionNode < any , any > >
459
+ ) {
460
+ return withFunction ( fromRecord ( nodes ) , ( input ) => {
439
461
const res = _ ( input . changeSet )
440
462
. map ( ( changeValues , oriIndex ) => {
441
463
const idx = input . indexes [ oriIndex ] ;
@@ -446,11 +468,34 @@ export class TableImplComp extends TableInitComp implements IContainer {
446
468
// console.info("toUpdateRowsNode. input: ", input, " res: ", res);
447
469
return res ;
448
470
} ) ;
471
+ }
472
+
473
+ toUpdateRowsNode ( ) {
474
+ const nodes = {
475
+ oriDisplayData : this . oriDisplayDataNode ( ) ,
476
+ indexes : this . displayDataIndexesNode ( ) ,
477
+ changeSet : this . changeSetNode ( ) ,
478
+ } ;
479
+
480
+ const resNode = this . getToUpsertRowsResNodes ( nodes ) ;
449
481
return lastValueIfEqual ( this , "toUpdateRowsNode" , [ resNode , nodes ] as const , ( a , b ) =>
450
482
shallowEqual ( a [ 1 ] , b [ 1 ] )
451
483
) [ 0 ] ;
452
484
}
453
485
486
+ toInsertRowsNode ( ) {
487
+ const nodes = {
488
+ oriDisplayData : this . oriDisplayDataNode ( ) ,
489
+ indexes : this . displayDataIndexesNode ( ) ,
490
+ changeSet : this . insertSetNode ( ) ,
491
+ } ;
492
+
493
+ const resNode = this . getToUpsertRowsResNodes ( nodes ) ;
494
+ return lastValueIfEqual ( this , "toInsertRowsNode" , [ resNode , nodes ] as const , ( a , b ) =>
495
+ shallowEqual ( a [ 1 ] , b [ 1 ] )
496
+ ) [ 0 ] ;
497
+ }
498
+
454
499
columnAggrNode ( ) {
455
500
const nodes = {
456
501
oriDisplayData : this . oriDisplayDataNode ( ) ,
@@ -473,6 +518,7 @@ export class TableImplComp extends TableInitComp implements IContainer {
473
518
}
474
519
475
520
let TableTmpComp = withViewFn ( TableImplComp , ( comp ) => {
521
+ const [ emptyRows , setEmptyRows ] = useState ( [ ] ) ;
476
522
return (
477
523
< HidableView hidden = { comp . children . hidden . getView ( ) } >
478
524
< TableCompView
@@ -687,6 +733,14 @@ export const TableComp = withExposingConfigs(TableTmpComp, [
687
733
( input ) => input . changeSet ,
688
734
trans ( "table.changeSetDesc" )
689
735
) ,
736
+ new CompDepsConfig (
737
+ "insertSet" ,
738
+ ( comp ) => ( {
739
+ insertSet : comp . insertSetNode ( ) ,
740
+ } ) ,
741
+ ( input ) => input . insertSet ,
742
+ trans ( "table.changeSetDesc" )
743
+ ) ,
690
744
new CompDepsConfig (
691
745
"toUpdateRows" ,
692
746
( comp ) => ( {
@@ -697,6 +751,16 @@ export const TableComp = withExposingConfigs(TableTmpComp, [
697
751
} ,
698
752
trans ( "table.toUpdateRowsDesc" )
699
753
) ,
754
+ new CompDepsConfig (
755
+ "toInsertRows" ,
756
+ ( comp ) => ( {
757
+ toInsertRows : comp . toInsertRowsNode ( ) ,
758
+ } ) ,
759
+ ( input ) => {
760
+ return input . toInsertRows ;
761
+ } ,
762
+ trans ( "table.toUpdateRowsDesc" )
763
+ ) ,
700
764
new DepsConfig (
701
765
"pageNo" ,
702
766
( children ) => {
0 commit comments