Skip to content

Commit 2f85e20

Browse files
authored
fe: fix no data for locations (#114)
1 parent cbfa4e3 commit 2f85e20

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

app/src/containers/indicators/item.tsx

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { useSyncLocation } from "@/app/(frontend)/[locale]/(app)/store";
1111

1212
import { useToggleLayers } from "@/hooks/use-toggle-layers";
1313

14-
import { IndicatorChartData } from "@/containers/indicators/types";
15-
1614
import WidgetChart from "@/components/chart";
1715
import InfoButton from "@/components/ui/info-button";
1816
import { 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
};

app/src/containers/landscapes/[id]/chart/chart.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export const LandscapeChart = (props: {
2828
params: {
2929
query: {
3030
depth: 1,
31-
limit: 100,
32-
page: 1,
31+
pagination: false,
3332
sort: "-createdAt",
3433
locale,
3534
where: {

0 commit comments

Comments
 (0)