@@ -2,7 +2,7 @@ import Statuses from "@/src/components/shared/statuses/Statuses";
22import { selectAllLookupLists , setAllLookupLists } from "@/src/reduxStore/states/pages/lookup-lists" ;
33import { selectAttributes , selectVisibleAttributeAC , setAllAttributes , setLabelingTasksAll , updateAttributeById } from "@/src/reduxStore/states/pages/settings" ;
44import { selectProjectId } from "@/src/reduxStore/states/project"
5- import { Attribute , AttributeState , AttributeWithOnClick , LLMConfig } from "@/src/types/components/projects/projectId/settings/data-schema" ;
5+ import { Attribute , AttributeState , AttributeVisibility , AttributeWithOnClick , LLMConfig } from "@/src/types/components/projects/projectId/settings/data-schema" ;
66import { DataTypeEnum } from "@/src/types/shared/general" ;
77import { LLM_PROVIDER_OPTIONS , postProcessCurrentAttribute } from "@/src/util/components/projects/projectId/settings/attribute-calculation-helper" ;
88import { ATTRIBUTES_VISIBILITY_STATES , DATA_TYPES , getTooltipVisibilityState } from "@/src/util/components/projects/projectId/settings/data-schema-helper" ;
@@ -40,6 +40,7 @@ import { simpleDictCompare } from "@/submodules/javascript-functions/validations
4040import { LLM_CODE_TEMPLATE_EXAMPLES , LLM_CODE_TEMPLATE_OPTIONS } from "./LLM/llmTemplates" ;
4141import KernButton from "@/submodules/react-components/components/kern-button/KernButton" ;
4242import { MemoIconAlertTriangleFilled , MemoIconArrowLeft , MemoIconCircleCheckFilled } from "@/submodules/react-components/components/kern-icons/icons" ;
43+ import { LookupListWithOnClick } from "@/src/types/components/projects/projectId/lookup-lists" ;
4344
4445const EDITOR_OPTIONS = { theme : 'vs-light' , language : 'python' , readOnly : false } ;
4546
@@ -197,10 +198,11 @@ export default function AttributeCalculation() {
197198
198199 }
199200
201+ const attributesRef = useRefFor ( attributes ) ;
200202 const changeAttributeName = useCallback ( ( name : string ) => {
201203 if ( name == currentAttributeRef . current . name ) return ;
202204 if ( name == '' ) return ;
203- const duplicateNameExists = attributes . find ( ( attribute ) => attribute . name == name ) ;
205+ const duplicateNameExists = attributesRef . current . find ( ( attribute ) => attribute . name == name ) ;
204206 if ( duplicateNameExists ) {
205207 setDuplicateNameExists ( true ) ;
206208 setAttributeName ( currentAttributeRef . current . name ) ;
@@ -217,10 +219,10 @@ export default function AttributeCalculation() {
217219 } , null , null , attributeNew . name ) ;
218220 } , [ ] ) ;
219221
220- const updateVisibility = useCallback ( ( option : any ) => {
222+ const updateVisibility = useCallback ( ( option : { name : string , value : string } ) => {
221223 const attributeNew = { ...currentAttributeRef . current } ;
222- attributeNew . visibility = option . value ;
223- attributeNew . visibilityIndex = ATTRIBUTES_VISIBILITY_STATES . findIndex ( ( state ) => state . name === option ) ;
224+ attributeNew . visibility = option . value as AttributeVisibility ;
225+ attributeNew . visibilityIndex = ATTRIBUTES_VISIBILITY_STATES . findIndex ( ( state ) => state . name === option . name ) ;
224226 attributeNew . visibilityName = option . name ;
225227 attributeNew . saveSourceCode = false ;
226228 updateAttribute ( projectId , currentAttributeRef . current . id , ( res ) => {
@@ -229,7 +231,7 @@ export default function AttributeCalculation() {
229231 } , null , null , null , null , attributeNew . visibility ) ;
230232 } , [ ] ) ;
231233
232- const updateDataType = useCallback ( ( option : any ) => {
234+ const updateDataType = useCallback ( ( option : { name : string , value : string } ) => {
233235 const attributeNew = { ...currentAttributeRef . current } ;
234236 attributeNew . dataType = option . value ;
235237 attributeNew . dataTypeName = option . name ;
@@ -322,6 +324,10 @@ export default function AttributeCalculation() {
322324 { ...attribute , onClick : copyToClipboardFunc ( attribute . name ) }
323325 ) ) , [ usableAttributes ] ) ;
324326
327+ const lookupListsFinal = useMemo ( ( ) => lookupLists . map ( ( lookupList ) => (
328+ { ...lookupList , onClick : copyToClipboardFunc ( "from knowledge import " + lookupList . pythonVariable ) }
329+ ) ) , [ lookupLists ] ) ;
330+
325331 const disabledOptions = useMemo ( ( ) => {
326332 if ( ! currentAttribute || currentAttribute . dataType == DataTypeEnum . LLM_RESPONSE ) return undefined ;
327333 return DATA_TYPES . map ( ( e ) => e . value == DataTypeEnum . LLM_RESPONSE ) ;
@@ -404,11 +410,11 @@ export default function AttributeCalculation() {
404410 </ div >
405411
406412 < div className = "text-sm leading-5 font-medium text-gray-700 inline-block" >
407- { lookupLists . length == 0 ? 'No lookup lists in project' : 'Lookup lists' } </ div >
413+ { lookupListsFinal . length == 0 ? 'No lookup lists in project' : 'Lookup lists' } </ div >
408414 < div className = "flex flex-row items-center" >
409- { lookupLists . map ( ( lookupList ) => (
415+ { lookupListsFinal . map ( ( lookupList : LookupListWithOnClick ) => (
410416 < Tooltip key = { lookupList . id } content = { TOOLTIPS_DICT . GENERAL . IMPORT_STATEMENT } color = "invert" placement = "top" >
411- < span onClick = { copyToClipboardFunc ( "from knowledge import " + lookupList . pythonVariable ) } >
417+ < span onClick = { lookupList . onClick } >
412418 < div className = "cursor-pointer border items-center px-2 py-0.5 rounded text-xs font-medium text-center mr-2" >
413419 { lookupList . pythonVariable } - { lookupList . termCount }
414420 </ div >
0 commit comments