11import { tableDataRowExample } from "comps/comps/tableComp/column/tableColumnListComp" ;
22import { 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" ;
44import { TableFilter } from "comps/comps/tableComp/tableToolbarComp" ;
55import {
66 columnHide ,
@@ -40,7 +40,11 @@ import {
4040 deferAction ,
4141 executeQueryAction ,
4242 fromRecord ,
43+ FunctionNode ,
44+ Node ,
4345 onlyEvalAction ,
46+ RecordNode ,
47+ RecordNodeToValue ,
4448 routeByNameAction ,
4549 withFunction ,
4650 wrapChildAction ,
@@ -53,7 +57,7 @@ import { getSelectedRowKeys } from "./selectionControl";
5357import { compTablePropertyView } from "./tablePropertyView" ;
5458import { RowColorComp , RowHeightComp , TableChildrenView , TableInitComp } from "./tableTypes" ;
5559
56- import { useContext } from "react" ;
60+ import { useContext , useState } from "react" ;
5761import { EditorContext } from "comps/editorState" ;
5862
5963export class TableImplComp extends TableInitComp implements IContainer {
@@ -401,12 +405,11 @@ export class TableImplComp extends TableInitComp implements IContainer {
401405 ) [ 0 ] ;
402406 }
403407
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 ) => {
410413 // merge input.dataIndexes and input.withParams into one structure
411414 const dataIndexRenderDict = _ ( input . dataIndexes )
412415 . mapValues ( ( dataIndex , idx ) => input . renders [ idx ] )
@@ -416,26 +419,45 @@ export class TableImplComp extends TableInitComp implements IContainer {
416419 _ . forEach ( dataIndexRenderDict , ( render , dataIndex ) => {
417420 _ . forEach ( render [ MAP_KEY ] , ( value , key ) => {
418421 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 ) {
420424 if ( ! record [ key ] ) record [ key ] = { } ;
421425 record [ key ] [ dataIndex ] = changeValue ;
422426 }
423427 } ) ;
424428 } ) ;
425429 return record ;
426430 } ) ;
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 ) ;
427440 return lastValueIfEqual ( this , "changeSetNode" , [ resNode , nodes ] as const , ( a , b ) =>
428441 shallowEqual ( a [ 1 ] , b [ 1 ] )
429442 ) [ 0 ] ;
430443 }
431444
432- toUpdateRowsNode ( ) {
445+ insertSetNode ( ) {
433446 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" ) ,
437449 } ;
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 ) => {
439461 const res = _ ( input . changeSet )
440462 . map ( ( changeValues , oriIndex ) => {
441463 const idx = input . indexes [ oriIndex ] ;
@@ -446,11 +468,34 @@ export class TableImplComp extends TableInitComp implements IContainer {
446468 // console.info("toUpdateRowsNode. input: ", input, " res: ", res);
447469 return res ;
448470 } ) ;
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 ) ;
449481 return lastValueIfEqual ( this , "toUpdateRowsNode" , [ resNode , nodes ] as const , ( a , b ) =>
450482 shallowEqual ( a [ 1 ] , b [ 1 ] )
451483 ) [ 0 ] ;
452484 }
453485
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+
454499 columnAggrNode ( ) {
455500 const nodes = {
456501 oriDisplayData : this . oriDisplayDataNode ( ) ,
@@ -473,6 +518,7 @@ export class TableImplComp extends TableInitComp implements IContainer {
473518}
474519
475520let TableTmpComp = withViewFn ( TableImplComp , ( comp ) => {
521+ const [ emptyRows , setEmptyRows ] = useState ( [ ] ) ;
476522 return (
477523 < HidableView hidden = { comp . children . hidden . getView ( ) } >
478524 < TableCompView
@@ -687,6 +733,14 @@ export const TableComp = withExposingConfigs(TableTmpComp, [
687733 ( input ) => input . changeSet ,
688734 trans ( "table.changeSetDesc" )
689735 ) ,
736+ new CompDepsConfig (
737+ "insertSet" ,
738+ ( comp ) => ( {
739+ insertSet : comp . insertSetNode ( ) ,
740+ } ) ,
741+ ( input ) => input . insertSet ,
742+ trans ( "table.changeSetDesc" )
743+ ) ,
690744 new CompDepsConfig (
691745 "toUpdateRows" ,
692746 ( comp ) => ( {
@@ -697,6 +751,16 @@ export const TableComp = withExposingConfigs(TableTmpComp, [
697751 } ,
698752 trans ( "table.toUpdateRowsDesc" )
699753 ) ,
754+ new CompDepsConfig (
755+ "toInsertRows" ,
756+ ( comp ) => ( {
757+ toInsertRows : comp . toInsertRowsNode ( ) ,
758+ } ) ,
759+ ( input ) => {
760+ return input . toInsertRows ;
761+ } ,
762+ trans ( "table.toUpdateRowsDesc" )
763+ ) ,
700764 new DepsConfig (
701765 "pageNo" ,
702766 ( children ) => {
0 commit comments