@@ -198,49 +198,48 @@ export default function AttributeCalculation() {
198198
199199 }
200200
201- function changeAttributeName ( name : string ) {
202- if ( name == currentAttribute . name ) return ;
201+ const changeAttributeName = useCallback ( ( name : string ) => {
202+ if ( name == currentAttributeRef . current . name ) return ;
203203 if ( name == '' ) return ;
204204 const duplicateNameExists = attributes . find ( ( attribute ) => attribute . name == name ) ;
205205 if ( duplicateNameExists ) {
206206 setDuplicateNameExists ( true ) ;
207- setAttributeName ( currentAttribute . name ) ;
207+ setAttributeName ( currentAttributeRef . current . name ) ;
208208 return ;
209209 }
210- const attributeNew = { ...currentAttribute } ;
210+ const attributeNew = { ...currentAttributeRef . current } ;
211211 attributeNew . name = name ;
212212 attributeNew . saveSourceCode = false ;
213- updateAttribute ( projectId , currentAttribute . id , ( res ) => {
213+ updateAttribute ( projectId , currentAttributeRef . current . id , ( res ) => {
214214 setCurrentAttribute ( postProcessCurrentAttribute ( attributeNew ) ) ;
215215 setEditorValue ( attributeNew . sourceCode . replace ( 'def ac(record)' , 'def ' + attributeNew . name + '(record)' ) ) ;
216216 dispatch ( updateAttributeById ( attributeNew ) ) ;
217217 setDuplicateNameExists ( false ) ;
218218 } , null , null , attributeNew . name ) ;
219- }
219+ } , [ ] ) ;
220220
221- function updateVisibility ( option : any ) {
222- const attributeNew = { ...currentAttribute } ;
221+ const updateVisibility = useCallback ( ( option : any ) => {
222+ const attributeNew = { ...currentAttributeRef . current } ;
223223 attributeNew . visibility = option . value ;
224224 attributeNew . visibilityIndex = ATTRIBUTES_VISIBILITY_STATES . findIndex ( ( state ) => state . name === option ) ;
225225 attributeNew . visibilityName = option . name ;
226226 attributeNew . saveSourceCode = false ;
227- updateAttribute ( projectId , currentAttribute . id , ( res ) => {
227+ updateAttribute ( projectId , currentAttributeRef . current . id , ( res ) => {
228228 setCurrentAttribute ( postProcessCurrentAttribute ( attributeNew ) ) ;
229229 dispatch ( updateAttributeById ( attributeNew ) ) ;
230230 } , null , null , null , null , attributeNew . visibility ) ;
231- }
231+ } , [ ] ) ;
232232
233- function updateDataType ( option : any ) {
234- const attributeNew = { ...currentAttribute } ;
233+ const updateDataType = useCallback ( ( option : any ) => {
234+ const attributeNew = { ...currentAttributeRef . current } ;
235235 attributeNew . dataType = option . value ;
236236 attributeNew . dataTypeName = option . name ;
237237 attributeNew . saveSourceCode = false ;
238- updateAttribute ( projectId , currentAttribute . id , ( res ) => {
238+ updateAttribute ( projectId , currentAttributeRef . current . id , ( res ) => {
239239 setCurrentAttribute ( postProcessCurrentAttribute ( attributeNew ) ) ;
240240 dispatch ( updateAttributeById ( attributeNew ) ) ;
241241 } , attributeNew . dataType ) ;
242- }
243-
242+ } , [ ] ) ;
244243
245244 function onScrollEvent ( event : any ) {
246245 if ( ! ( event . target instanceof HTMLElement ) ) return ;
@@ -251,7 +250,6 @@ export default function AttributeCalculation() {
251250 }
252251 }
253252
254-
255253 function checkProjectTokenization ( ) {
256254 getProjectTokenization ( projectId , ( res ) => {
257255 setTokenizationProgress ( res ?. progress ) ;
@@ -311,6 +309,16 @@ export default function AttributeCalculation() {
311309 const orgId = useSelector ( selectOrganizationId ) ;
312310 useWebsocket ( orgId , Application . REFINERY , CurrentPage . ATTRIBUTE_CALCULATION , handleWebsocketNotification , projectId ) ;
313311
312+ const goBack = useCallback ( ( e : React . MouseEvent ) => {
313+ e . preventDefault ( ) ;
314+ router . push ( `/projects/${ projectId } /settings` ) ;
315+ } , [ ] ) ;
316+
317+ const copyToClipboardFunc = useCallback (
318+ ( name : string ) => ( ) => copyToClipboard ( name ) ,
319+ [ ]
320+ ) ;
321+
314322 const disabledOptions = useMemo ( ( ) => {
315323 if ( ! currentAttribute || currentAttribute . dataType == DataTypeEnum . LLM_RESPONSE ) return undefined ;
316324 return DATA_TYPES . map ( ( e ) => e . value == DataTypeEnum . LLM_RESPONSE ) ;
@@ -321,10 +329,7 @@ export default function AttributeCalculation() {
321329 < div className = { `sticky z-50 h-12 ${ isHeaderNormal ? 'top-1' : '-top-5' } ` } >
322330 < div className = { `bg-white flex-grow ${ isHeaderNormal ? '' : 'shadow' } ` } >
323331 < div className = { `flex-row justify-start items-center inline-block ${ isHeaderNormal ? 'p-0' : 'flex py-2' } ` } style = { { transition : 'all .25s ease-in-out' } } >
324- < a href = { `/refinery/projects/${ projectId } /settings` } onClick = { ( e ) => {
325- e . preventDefault ( ) ;
326- router . push ( `/projects/${ projectId } /settings` ) ;
327- } } className = "text-green-800 text-sm font-medium" >
332+ < a href = { `/refinery/projects/${ projectId } /settings` } onClick = { goBack } className = "text-green-800 text-sm font-medium" >
328333 < MemoIconArrowLeft className = "h-5 w-5 inline-block text-green-800" />
329334 < span className = "leading-5" > Go back</ span >
330335 </ a >
@@ -386,7 +391,7 @@ export default function AttributeCalculation() {
386391 { usableAttributes . length == 0 && < div className = "text-sm font-normal text-gray-500" > No usable attributes.</ div > }
387392 { usableAttributes . map ( ( attribute : Attribute ) => (
388393 < Tooltip key = { attribute . id } content = { attribute . dataTypeName + ' - ' + TOOLTIPS_DICT . GENERAL . CLICK_TO_COPY } color = "invert" placement = "top" >
389- < span onClick = { ( ) => copyToClipboard ( attribute . name ) } >
394+ < span onClick = { copyToClipboardFunc ( attribute . name ) } >
390395 < div className = { `cursor-pointer border items-center px-2 py-0.5 rounded text-xs font-medium text-center mr-2 ${ 'bg-' + attribute . color + '-100' } ${ 'text-' + attribute . color + '-700' } ${ 'border-' + attribute . color + '-400' } ${ 'hover:bg-' + attribute . color + '-200' } ` } >
391396 { attribute . name }
392397 </ div >
@@ -400,7 +405,7 @@ export default function AttributeCalculation() {
400405 < div className = "flex flex-row items-center" >
401406 { lookupLists . map ( ( lookupList ) => (
402407 < Tooltip key = { lookupList . id } content = { TOOLTIPS_DICT . GENERAL . IMPORT_STATEMENT } color = "invert" placement = "top" >
403- < span onClick = { ( ) => copyToClipboard ( "from knowledge import " + lookupList . pythonVariable ) } >
408+ < span onClick = { copyToClipboardFunc ( "from knowledge import " + lookupList . pythonVariable ) } >
404409 < div className = "cursor-pointer border items-center px-2 py-0.5 rounded text-xs font-medium text-center mr-2" >
405410 { lookupList . pythonVariable } - { lookupList . termCount }
406411 </ div >
0 commit comments