From 1fa1b5fd8a8e45c46ac7859533b9a3bec506f2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Tue, 9 Jul 2024 13:05:34 +0200 Subject: [PATCH] fix: let form graphs refresh, remove shadow in graphcards in form widgets, pass activeId --- src/hooks/useFormGraphData.ts | 19 ++++++------- src/widgets/custom/Indicator.tsx | 39 ++++++++++++++++----------- src/widgets/views/Graph/GraphCard.tsx | 2 +- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/hooks/useFormGraphData.ts b/src/hooks/useFormGraphData.ts index 302eb0bd1..32ce16961 100644 --- a/src/hooks/useFormGraphData.ts +++ b/src/hooks/useFormGraphData.ts @@ -10,20 +10,12 @@ export const useFormGraphData = (actionId: number) => { const [actionData, setActionData] = useState(); const [treeShortcut, setTreeShortcut] = useState(); const formContext = useContext(FormContext) as FormContextType; - const { getContext, getValues } = formContext || {}; + const { getContext, getValues, activeId } = formContext || {}; const { globalValues, rootContext } = useConfigContext(); const context = useMemo(() => { return { ...getContext?.(), ...rootContext }; }, [getContext, rootContext]); - useEffect(() => { - if (!actionId) { - return; - } - fetchData(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [actionId]); - const fetchData = async () => { setError(undefined); setLoading(true); @@ -31,7 +23,12 @@ export const useFormGraphData = (actionId: number) => { const result = await fetchAction({ actionId, rootContext: context, - globalValues: { ...globalValues, ...getValues() }, + globalValues: { + ...globalValues, + ...getValues(), + active_id: activeId, + active_ids: [activeId], + }, }); const { views } = result as any; @@ -66,5 +63,5 @@ export const useFormGraphData = (actionId: number) => { setLoading(false); }; - return { actionData, treeShortcut, loading, error }; + return { actionData, treeShortcut, loading, error, fetchData }; }; diff --git a/src/widgets/custom/Indicator.tsx b/src/widgets/custom/Indicator.tsx index 3013ca556..9231fb629 100644 --- a/src/widgets/custom/Indicator.tsx +++ b/src/widgets/custom/Indicator.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from "react"; +import React, { useContext, useEffect } from "react"; import { Tooltip, theme, Statistic, Card } from "antd"; import { Indicator as IndicatorOoui } from "@gisce/ooui"; import { WidgetProps } from "@/types"; @@ -90,9 +90,9 @@ const GraphIndicatorInput = (props: IndicatorInputProps) => { const { ooui } = props; const { actionId } = ooui; - const { actionData, treeShortcut, loading, error } = useFormGraphData( - actionId!, - ); + const { actionData, treeShortcut, loading, error, fetchData } = + useFormGraphData(actionId!); + const readForViewEnabled = useFeatureIsEnabled( ErpFeatureKeys.FEATURE_READFORVIEW, ); @@ -101,15 +101,19 @@ const GraphIndicatorInput = (props: IndicatorInputProps) => { ) as TabManagerContextType; const { openShortcut } = tabManagerContext || {}; - if (loading) { - return ; - } + useEffect(() => { + if (!ooui) { + return; + } + fetchData(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [ooui]); if (error) { return ; } - const { id, model, limit, domain, context, initialView } = actionData; + const { id, model, limit, domain, context, initialView } = actionData || {}; const GraphComponent = readForViewEnabled ? GraphServer : Graph; @@ -117,17 +121,20 @@ const GraphIndicatorInput = (props: IndicatorInputProps) => { - + {loading && } + {!loading && ( + + )} ); }; diff --git a/src/widgets/views/Graph/GraphCard.tsx b/src/widgets/views/Graph/GraphCard.tsx index dd979d4fb..ab733e859 100644 --- a/src/widgets/views/Graph/GraphCard.tsx +++ b/src/widgets/views/Graph/GraphCard.tsx @@ -14,7 +14,7 @@ export const GraphCard = (props: GraphCardProps) => { return (