@@ -9,12 +9,14 @@ import {
99 withMethodExposing ,
1010 CompAction ,
1111 CompDepsConfig ,
12+ CompActionTypes ,
1213} from 'lowcoder-sdk' ;
1314import { trans } from "./i18n/comps" ;
1415import { KanbanInitComp } from './kanbanTypes' ;
1516import { KanbanPropertyView } from './kanbanPropertyView' ;
1617import { KanbanCompView } from './kanbanCompView' ;
1718import * as datasource from './datasource.json' ;
19+ import isEqual from 'lodash.isequal' ;
1820
1921type IContainer = typeof IContainer ;
2022type NameGenerator = typeof NameGenerator ;
@@ -50,20 +52,39 @@ export class KanbanImplComp extends KanbanInitComp implements IContainer {
5052
5153 override reduce ( action : CompAction ) : this {
5254 let comp = super . reduce ( action ) ;
53- const params = comp . children . cardView . children . cardView . getCachedParams ( '0' ) ;
54- if ( ! Boolean ( params ) ) {
55+
56+ let dataChanged = false ;
57+ if ( action . type === CompActionTypes . UPDATE_NODES_V2 ) {
58+ dataChanged =
59+ comp . children . data !== this . children . data &&
60+ isEqual ( this . children . data . getView ( ) , comp . children . data . getView ( ) ) ;
61+ }
62+
63+ const thisSelection = this . children . activeCardIndex . getView ( ) ?? "0" ;
64+ const newSelection = comp . children . activeCardIndex . getView ( ) ?? "0" ;
65+ const selectionChanged = thisSelection !== newSelection ;
66+ let params = comp . children . cardView . children . cardView . getCachedParams ( newSelection ) ;
67+ if ( selectionChanged || ! Boolean ( params ) || dataChanged ) {
68+ params = ! Boolean ( params ) || dataChanged
69+ ? {
70+ currentRow : comp . children . data . getView ( ) [ newSelection ] ,
71+ currentIndex : newSelection ,
72+ currentOriginalIndex : newSelection ,
73+ } : undefined ;
5574 comp = comp . setChild (
5675 "cardView" ,
5776 comp . children . cardView . reduce (
58- comp . children . cardView . setSelectionAction ( '0' , params )
77+ comp . children . cardView . setSelectionAction ( newSelection , params )
5978 )
6079 ) ;
6180 }
6281 return comp ;
6382 }
6483}
6584
66- const KanbanRenderComp = withViewFn ( KanbanImplComp , ( comp : KanbanImplComp ) => < KanbanCompView comp = { comp } /> ) ;
85+ const KanbanRenderComp = withViewFn ( KanbanImplComp , ( comp : KanbanImplComp ) => {
86+ return < KanbanCompView comp = { comp } />
87+ } ) ;
6788let KanbanPropertyComp = withPropertyViewFn ( KanbanRenderComp , ( comp : KanbanImplComp ) => {
6889 return < KanbanPropertyView comp = { comp } /> ;
6990} ) ;
0 commit comments