@@ -11,8 +11,6 @@ import { useSyncLocation } from "@/app/(frontend)/[locale]/(app)/store";
1111
1212import { useToggleLayers } from "@/hooks/use-toggle-layers" ;
1313
14- import { IndicatorChartData } from "@/containers/indicators/types" ;
15-
1614import WidgetChart from "@/components/chart" ;
1715import InfoButton from "@/components/ui/info-button" ;
1816import { Lexical } from "@/components/ui/lexical" ;
@@ -38,41 +36,36 @@ export const IndicatorsItem: FC<IndicatorsItemProps> = ({ indicator }) => {
3836 params : {
3937 query : {
4038 depth : 1 ,
41- limit : 100 ,
42- page : 1 ,
39+ pagination : false ,
4340 sort : "-createdAt" ,
4441 locale,
4542 where : {
4643 "indicator.id" : {
4744 equals : indicator . id ,
4845 } ,
46+ "location.id" : {
47+ equals : location ,
48+ } ,
4949 } ,
5050 } ,
5151 } ,
5252 } ,
5353 {
5454 select : ( data ) => {
55- const result : { location : string ; chartData : IndicatorChartData [ ] } [ ] = data . docs . map (
56- ( doc ) => ( {
57- location : typeof doc . location === "object" ? doc . location . id : doc . location ,
58- chartData : ( doc . data as IndicatorChartData [ ] ) . map ( ( d ) => ( {
55+ return data . docs
56+ . map ( ( doc ) =>
57+ doc . data . map ( ( d ) => ( {
5958 ...d ,
6059 key : d . label ,
6160 label : doc ?. labels ?. [ d . label ] ?? d . label ,
6261 } ) ) ,
63- } ) ,
64- ) ;
65-
66- return result ;
62+ )
63+ . flat ( ) ;
6764 } ,
6865 } ,
6966 ) ,
7067 ) ;
71- const chartData = data ?. find ( ( doc ) => doc . location === location ) ?. chartData || [ ] ;
72- const lexicalVariables = chartData . reduce (
73- ( acc , curr ) => ( { [ curr . key ] : curr . value , ...acc } ) ,
74- { } ,
75- ) ;
68+ const lexicalVariables = data ?. reduce ( ( acc , curr ) => ( { [ curr . key ] : curr . value , ...acc } ) , { } ) ;
7669
7770 return (
7871 < div
@@ -100,13 +93,13 @@ export const IndicatorsItem: FC<IndicatorsItemProps> = ({ indicator }) => {
10093 </ div >
10194 </ div >
10295
103- { indicator . widget && Object . keys ( lexicalVariables ) . length > 0 && (
96+ { indicator . widget && lexicalVariables && Object . keys ( lexicalVariables ) . length > 0 && (
10497 < div className = "prose prose-invert prose-sm prose-p:leading-5" >
10598 < Lexical data = { indicator . widget } variables = { lexicalVariables } />
10699 </ div >
107100 ) }
108101 </ header >
109- { chartData . length > 0 && < WidgetChart indicator = { indicator . id } data = { chartData } /> }
102+ { ! ! data ? .length && < WidgetChart indicator = { indicator . id } data = { data } /> }
110103 </ div >
111104 ) ;
112105} ;
0 commit comments