Skip to content

Commit b190664

Browse files
committed
fix: only set group chart keys if component is selected
1 parent b2ae700 commit b190664

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/components/editor/fastboard-components/group-chart/FastboardGroupChart.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ import { FastboardGroupChartProperties } from "@/types/editor/group-chart-types"
1818
import useData from "@/hooks/useData";
1919
import { ComponentId, ComponentType } from "@/types/editor";
2020
import { useEffect } from "react";
21-
import { useSetRecoilState } from "recoil";
21+
import { useRecoilValue, useSetRecoilState } from "recoil";
2222
import { propertiesDrawerState } from "@/atoms/editor";
2323
import { useTheme } from "next-themes";
2424
import { generatePalette } from "@/lib/colors";
25-
import { Card } from "@nextui-org/react";
2625

2726
const groupData = (data: any[], groupBy: string) => {
2827
return data.reduce((acc, item) => {
@@ -197,8 +196,6 @@ const FastboardGroupChart = ({
197196
properties,
198197
}: {
199198
id: ComponentId;
200-
layoutIndex?: number;
201-
container?: string;
202199
properties: FastboardGroupChartProperties;
203200
}) => {
204201
const { theme } = useTheme();
@@ -213,6 +210,9 @@ const FastboardGroupChart = ({
213210
layout,
214211
} = properties;
215212
const setProperties = useSetRecoilState(propertiesDrawerState);
213+
const propertiesDrawer = useRecoilValue(propertiesDrawerState);
214+
215+
const isSelected = propertiesDrawer.selectedComponentId === id;
216216

217217
const {
218218
data,
@@ -222,7 +222,7 @@ const FastboardGroupChart = ({
222222
} = useData(`${ComponentType.GroupChart}-${id}`, sourceQueryData);
223223

224224
useEffect(() => {
225-
if (keys) {
225+
if (keys && isSelected) {
226226
setProperties((prev) => {
227227
return {
228228
...prev,
@@ -233,7 +233,7 @@ const FastboardGroupChart = ({
233233
};
234234
});
235235
}
236-
}, [keys]);
236+
}, [keys, isSelected]);
237237

238238
const chartConfig = {
239239
[groupBy]: {

src/hooks/useData.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const useData = (componentId: string, queryData: QueryData | null) => {
1616
refetchOnWindowFocus: false,
1717
});
1818
const [keys, setKeys] = useState<string[]>([]);
19-
const [page, setPage] = useState(1);
2019

2120
const mapItem = (item: any) => {
2221
Object.keys(item).forEach((key) => {

0 commit comments

Comments
 (0)