@@ -88,33 +88,31 @@ function FieldDataFormatter(props: FieldDataFormatterProps): JSX.Element {
8888
8989type FieldPrinterProps = {
9090 field : I_PISField ;
91+ fieldPath : string ;
9192} ;
9293
9394function FieldPrinter ( props : FieldPrinterProps ) : JSX . Element {
9495 const { setCurrentAppState } = useAppState ( ) ;
95- const { field } = props ;
96+ const { field, fieldPath } = props ;
9697
9798 const handleAddToFavourites = useCallback ( ( ) => {
9899 const storedFavourites = localStorage . getItem ( "favourites" ) ;
99100 const parsedFavourites : string [ ] = storedFavourites
100101 ? ( JSON . parse ( storedFavourites ) as string [ ] )
101102 : [ ] ;
102103
103- if (
104- ! parsedFavourites . some ( ( fav ) => fav === field . name ) &&
105- typeof field . name === "string"
106- ) {
107- if ( parsedFavourites . length === 8 && typeof field . name === "string" ) {
104+ if ( ! parsedFavourites . includes ( fieldPath ) ) {
105+ if ( parsedFavourites . length === 8 ) {
108106 parsedFavourites . shift ( ) ;
109107 }
110- parsedFavourites . push ( field . name ) ;
108+ parsedFavourites . push ( fieldPath ) ;
111109 setCurrentAppState ( ( prev ) => ( {
112110 ...prev ,
113111 favourites : parsedFavourites ,
114112 } ) ) ;
115113 localStorage . setItem ( "favourites" , JSON . stringify ( parsedFavourites ) ) ;
116114 }
117- } , [ field . name , setCurrentAppState ] ) ;
115+ } , [ fieldPath , setCurrentAppState ] ) ;
118116
119117 if (
120118 field . fstring !== undefined &&
@@ -151,6 +149,7 @@ function FieldPrinter(props: FieldPrinterProps): JSX.Element {
151149type FieldsPrinterProps = {
152150 fields : I_PISField [ ] ;
153151 depth ?: number ;
152+ basePath : string ; // NEW
154153} ;
155154
156155function FieldsPrinter ( props : FieldsPrinterProps ) : JSX . Element {
@@ -170,30 +169,39 @@ function FieldsPrinter(props: FieldsPrinterProps): JSX.Element {
170169 className = { `block overflow-x-hidden md:grid md:grid-cols-3 md:gap-x-2 lg:block lg:overflow-x-hidden ${ getMaxHeightClass ( ) } ` }
171170 >
172171 { fields . map ( ( field , index ) => (
173- < FieldPrinter field = { field } key = { index } />
172+ < FieldPrinter
173+ field = { field }
174+ fieldPath = { `${ basePath } .${ field . name } ` }
175+ key = { index }
176+ />
174177 ) ) }
175178 </ div >
176179 ) ;
177180}
181+
178182type PIStransformerProps = {
179183 root : I_PIS ;
180184 depth ?: number ;
185+ path ?: string [ ] ;
181186} ;
182187
183188function PISTransformer ( props : PIStransformerProps ) : JSX . Element {
184- const { depth = 0 , root } = props ;
189+ const { depth = 0 , path = [ ] , root } = props ;
190+
185191 const formatKey = ( key : string ) : string => {
186192 return key
187- . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1 $2" ) // Add space between lowercase and uppercase
188- . replace ( / ( [ A - Z ] + ) ( [ A - Z ] [ a - z ] ) / g, "$1 $2" ) // Add space between consecutive uppercase followed by lowercase
189- . replace ( / ( [ a - z A - Z ] ) ( \d ) / g, "$1 $2" ) ; // Add space between letters and numbers
193+ . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1 $2" )
194+ . replace ( / ( [ A - Z ] + ) ( [ A - Z ] [ a - z ] ) / g, "$1 $2" )
195+ . replace ( / ( [ a - z A - Z ] ) ( \d ) / g, "$1 $2" ) ;
190196 } ;
191197
192198 return (
193199 root && (
194200 < div className = "flex size-full flex-col gap-x-2 lg:h-[375px] lg:flex-wrap xl:h-[350px]" >
195201 { Object . keys ( root ) . map ( ( key , index ) => {
196202 const value = root [ key ] ;
203+ const newPath = [ ...path , key ] ; // Track path
204+
197205 return (
198206 < div className = { `flex flex-col` } id = { key } key = { index } >
199207 < div className = "flex w-full items-center justify-evenly border-b-2 border-helios" >
@@ -205,10 +213,19 @@ function PISTransformer(props: PIStransformerProps): JSX.Element {
205213 { formatKey ( key ) }
206214 </ p >
207215 </ div >
216+
208217 { Array . isArray ( value ) ? (
209- < FieldsPrinter depth = { depth + 1 } fields = { value } />
218+ < FieldsPrinter
219+ basePath = { newPath . join ( "." ) }
220+ depth = { depth + 1 }
221+ fields = { value }
222+ />
210223 ) : (
211- < PISTransformer depth = { depth + 1 } root = { value as I_PIS } />
224+ < PISTransformer
225+ depth = { depth + 1 }
226+ path = { newPath }
227+ root = { value as I_PIS }
228+ />
212229 ) }
213230 </ div >
214231 ) ;
0 commit comments