1
- import { useContext , useEffect , useRef , useState } from "react" ;
1
+ import React , { useCallback , useContext , useEffect , useMemo , useRef , useState } from "react" ;
2
2
import { KanbanImplComp } from "./KabanComp" ;
3
3
import {
4
4
EditorContext ,
@@ -54,7 +54,7 @@ const getString = (assignee: string): string => {
54
54
return ( assignee . match ( / \b ( \w ) / g) as string [ ] ) . join ( "" ) . toUpperCase ( ) ;
55
55
} ;
56
56
57
- const columnTemplate = ( props : {
57
+ const ColumnTemplate = React . memo ( ( props : {
58
58
data : { [ key : string ] : string } ,
59
59
boardStyles : { [ key : string ] : string }
60
60
} ) => {
@@ -72,7 +72,7 @@ const columnTemplate = (props: {
72
72
</ div >
73
73
</ div >
74
74
) ;
75
- } ;
75
+ } ) ;
76
76
77
77
const cardRendered = ( props : {
78
78
args : CardRenderedEventArgs ,
@@ -88,7 +88,7 @@ const cardRendered = (props: {
88
88
addClass ( [ cardElement ] , val ) ;
89
89
} ;
90
90
91
- const cardTemplate = ( props : {
91
+ const CardTemplate = React . memo ( ( props : {
92
92
data : { [ key : string ] : string } ,
93
93
cardIndex : number ;
94
94
childrenProps : any ;
@@ -161,34 +161,37 @@ const cardTemplate = (props: {
161
161
</ div >
162
162
</ Wrapper >
163
163
) ;
164
- } ;
164
+ } ) ;
165
165
166
166
type Props = {
167
167
comp : InstanceType < typeof KanbanImplComp > ;
168
168
} ;
169
169
170
- export function KanbanCompView ( props : Props ) {
170
+ export const KanbanCompView = React . memo ( ( props : Props ) => {
171
171
const { comp } = props ;
172
- const childrenProps = childrenToProps ( comp . children ) ;
172
+ const childrenProps = useMemo ( ( ) =>
173
+ childrenToProps ( comp . children ) ,
174
+ [ childrenToProps , comp . children ] ,
175
+ ) ;
173
176
174
177
const [ dataMap , setDataMap ] = useState < Record < string , number > > ( { } ) ;
175
178
const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
176
179
177
- const updateDataMap = ( ) => {
180
+ const updateDataMap = useCallback ( ( ) => {
178
181
const mapData : Record < string , number > = { } ;
179
182
childrenProps . data ?. forEach ( ( item : any , index : number ) => {
180
183
mapData [ item . Id ] = index ;
181
184
} )
182
185
setDataMap ( mapData ) ;
183
- }
186
+ } , [ childrenProps . data , setDataMap ] ) ;
184
187
185
188
useEffect ( ( ) => {
186
189
updateDataMap ( ) ;
187
- } , [ ] ) ;
190
+ } , [ updateDataMap ] ) ;
188
191
189
192
useEffect ( ( ) => {
190
193
updateDataMap ( ) ;
191
- } , [ JSON . stringify ( childrenProps . data ) ] ) ;
194
+ } , [ JSON . stringify ( childrenProps . data ) , updateDataMap ] ) ;
192
195
193
196
console . log ( "🚀 ~ returnnewContainerCompBuilder ~ props:" , props )
194
197
@@ -293,6 +296,7 @@ export function KanbanCompView(props: Props) {
293
296
onOk = { handleOk }
294
297
onCancel = { handleCancel }
295
298
okText = "Update"
299
+ maskClosable = { false }
296
300
>
297
301
< Flex vertical gap = { 10 } >
298
302
< Typography . Title level = { 5 } > Title</ Typography . Title >
@@ -352,14 +356,16 @@ export function KanbanCompView(props: Props) {
352
356
headerField : 'Title' ,
353
357
template : ( data : Record < string , string > ) => {
354
358
const cardIndex = dataMap [ data . Id ] || 0 ;
355
- return cardTemplate ( {
356
- data,
357
- cardIndex,
358
- childrenProps,
359
- cardHeaderStyles : childrenProps . cardHeaderStyles ,
360
- cardContentStyles : childrenProps . cardContentStyles ,
361
- tagStyles : childrenProps . tagStyles ,
362
- } ) ;
359
+ return (
360
+ < CardTemplate
361
+ data = { data }
362
+ cardIndex = { cardIndex }
363
+ childrenProps = { childrenProps }
364
+ cardHeaderStyles = { childrenProps . cardHeaderStyles }
365
+ cardContentStyles = { childrenProps . cardContentStyles }
366
+ tagStyles = { childrenProps . tagStyles }
367
+ />
368
+ ) ;
363
369
} ,
364
370
selectionType : 'Multiple' ,
365
371
} }
@@ -377,37 +383,33 @@ export function KanbanCompView(props: Props) {
377
383
headerText = "To Do"
378
384
keyField = "Open"
379
385
allowToggle = { true }
380
- template = { ( data : Record < string , string > ) => columnTemplate ( {
381
- data,
382
- boardStyles : childrenProps . boardStyles ,
383
- } ) }
386
+ template = { ( data : Record < string , string > ) => (
387
+ < ColumnTemplate data = { data } boardStyles = { childrenProps . boardStyles } />
388
+ ) }
384
389
/>
385
390
< ColumnDirective
386
391
headerText = "In Progress"
387
392
keyField = "InProgress"
388
393
allowToggle = { true }
389
- template = { ( data : Record < string , string > ) => columnTemplate ( {
390
- data,
391
- boardStyles : childrenProps . boardStyles ,
392
- } ) }
394
+ template = { ( data : Record < string , string > ) => (
395
+ < ColumnTemplate data = { data } boardStyles = { childrenProps . boardStyles } />
396
+ ) }
393
397
/>
394
398
< ColumnDirective
395
399
headerText = "In Review"
396
400
keyField = "Review"
397
401
allowToggle = { true }
398
- template = { ( data : Record < string , string > ) => columnTemplate ( {
399
- data,
400
- boardStyles : childrenProps . boardStyles ,
401
- } ) }
402
+ template = { ( data : Record < string , string > ) => (
403
+ < ColumnTemplate data = { data } boardStyles = { childrenProps . boardStyles } />
404
+ ) }
402
405
/>
403
406
< ColumnDirective
404
407
headerText = "Done"
405
408
keyField = "Close"
406
409
allowToggle = { true }
407
- template = { ( data : Record < string , string > ) => columnTemplate ( {
408
- data,
409
- boardStyles : childrenProps . boardStyles ,
410
- } ) }
410
+ template = { ( data : Record < string , string > ) => (
411
+ < ColumnTemplate data = { data } boardStyles = { childrenProps . boardStyles } />
412
+ ) }
411
413
/>
412
414
</ ColumnsDirective >
413
415
</ KanbanComponent >
@@ -420,4 +422,4 @@ export function KanbanCompView(props: Props) {
420
422
</ div >
421
423
</ div >
422
424
) ;
423
- }
425
+ } )
0 commit comments