From e201659194c615a5005b9a97fbf85eaac1aa649f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Tue, 24 Dec 2024 08:32:47 +0100 Subject: [PATCH] fix: adjust search_fields and fields for graphs https://github.com/gisce/webclient/issues/1535 --- src/actionbar/GraphActionBar.tsx | 38 ++++------ src/types/index.ts | 2 + src/views/ActionView.tsx | 5 ++ src/views/actionViews/GraphActionView.tsx | 86 +++++++++++++---------- 4 files changed, 72 insertions(+), 59 deletions(-) diff --git a/src/actionbar/GraphActionBar.tsx b/src/actionbar/GraphActionBar.tsx index 88515e99a..54d347e58 100644 --- a/src/actionbar/GraphActionBar.tsx +++ b/src/actionbar/GraphActionBar.tsx @@ -11,13 +11,7 @@ import ButtonWithBadge from "./ButtonWithBadge"; import { ReloadOutlined, FilterOutlined } from "@ant-design/icons"; import { View } from "@/types"; -function GraphActionBar({ - refreshGraph, - mustShowSearchFilter, -}: { - refreshGraph: () => void; - mustShowSearchFilter: boolean; -}) { +function GraphActionBar({ refreshGraph }: { refreshGraph: () => void }) { const { t } = useLocale(); const { availableViews, @@ -33,22 +27,20 @@ function GraphActionBar({ return ( - {mustShowSearchFilter && ( - - } - tooltip={t("advanced_search")} - type={searchVisible ? "primary" : "default"} - onClick={() => { - setSearchVisible?.(!searchVisible); - }} - disabled={graphIsLoading} - badgeNumber={searchParams?.length} - /> - )} + + } + tooltip={t("advanced_search")} + type={searchVisible ? "primary" : "default"} + onClick={() => { + setSearchVisible?.(!searchVisible); + }} + disabled={graphIsLoading} + badgeNumber={searchParams?.length} + /> } tooltip={t("refresh")} diff --git a/src/types/index.ts b/src/types/index.ts index 5185fd461..1a6245be8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -67,6 +67,8 @@ export type GraphView = { view_id: number; name: string; title?: string; + fields: any; + search_fields?: SearchFields; }; export type View = TreeView | FormView | DashboardView | GraphView; diff --git a/src/views/ActionView.tsx b/src/views/ActionView.tsx index 04cc03858..701a2e620 100644 --- a/src/views/ActionView.tsx +++ b/src/views/ActionView.tsx @@ -454,6 +454,11 @@ function ActionView(props: Props, ref: any) { formView={ availableViews.find((v) => v.type === "form") as FormView } + graphView={ + availableViews.find( + (v) => v.view_id === view.view_id, + ) as GraphView + } /> ); } diff --git a/src/views/actionViews/GraphActionView.tsx b/src/views/actionViews/GraphActionView.tsx index c01df2219..533fe0bd4 100644 --- a/src/views/actionViews/GraphActionView.tsx +++ b/src/views/actionViews/GraphActionView.tsx @@ -6,7 +6,7 @@ import { ActionViewContext, ActionViewContextType, } from "@/context/ActionViewContext"; -import { FormView, TreeView } from "@/types"; +import { FormView, GraphView, TreeView } from "@/types"; import { mergeSearchFields } from "@/helpers/formHelper"; import { useSearch } from "@/hooks/useSearch"; import SearchFilter from "@/widgets/views/searchFilter/SearchFilter"; @@ -21,11 +21,20 @@ export type GraphActionViewProps = { domain: any; formView: FormView; treeView: TreeView; + graphView: GraphView; }; export const GraphActionView = (props: GraphActionViewProps) => { - const { viewData, visible, model, context, domain, formView, treeView } = - props; + const { + viewData, + visible, + model, + context, + domain, + formView, + treeView, + graphView, + } = props; const graphRef = useRef(); const actionViewContext = useContext( @@ -91,13 +100,19 @@ export const GraphActionView = (props: GraphActionViewProps) => { }); const searchFields = useMemo( - () => mergeSearchFields([formView?.search_fields, treeView?.search_fields]), - [formView?.search_fields, treeView?.search_fields], + () => + mergeSearchFields([ + formView?.search_fields, + treeView?.search_fields, + graphView?.search_fields, + ]), + [ + formView?.search_fields, + treeView?.search_fields, + graphView?.search_fields, + ], ); - const mustShowSearchFilter = - searchFields.primary.length > 0 || searchFields.secondary.length > 0; - if (!visible) { return null; } @@ -113,36 +128,35 @@ export const GraphActionView = (props: GraphActionViewProps) => { refreshGraph={() => { (graphRef.current as any).refresh(); }} - mustShowSearchFilter={mustShowSearchFilter} /> - {mustShowSearchFilter && ( - { - setApplyLimit(false); - setSearchParams?.(opts.params); - setSearchVisible?.(false); - }} - searchError={searchError} - searchVisible={searchVisible} - searchValues={searchValues} - showLimitOptions={false} - /> - )} + + { + setApplyLimit(false); + setSearchParams?.(opts.params); + setSearchVisible?.(false); + }} + searchError={searchError} + searchVisible={searchVisible} + searchValues={searchValues} + showLimitOptions={false} + /> {tableRefreshing ? ( ) : (