Skip to content

Commit

Permalink
fix: improve indicators with title
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Dec 10, 2024
1 parent 8a6cf6b commit f1ccb99
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 36 deletions.
8 changes: 7 additions & 1 deletion src/hooks/useFormGraphData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const useFormGraphData = (actionId: number) => {
const formContext = useContext(FormContext) as FormContextType;
const { getContext, getPlainValues, activeId } = formContext || {};
const { globalValues, rootContext } = useConfigContext();
const context = useMemo(() => {
const context: any = useMemo(() => {
return { ...getContext?.(), ...rootContext };
}, [getContext, rootContext]);

Expand All @@ -28,6 +28,12 @@ export const useFormGraphData = (actionId: number) => {
...getPlainValues(),
},
});

if (!context.active_id) {
setActionData(result);
throw new Error("active_id_not_found");
}

const { views } = result as any;

const treeView = views.find((view: any[]) => {
Expand Down
54 changes: 26 additions & 28 deletions src/widgets/custom/Indicator.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useContext, useEffect } from "react";
import { Tooltip, theme, Statistic, Card } from "antd";
import { Tooltip, theme, Statistic, Card, Empty } from "antd";
import { Indicator as IndicatorOoui } from "@gisce/ooui";
import { WidgetProps } from "@/types";
import Field from "@/common/Field";
Expand All @@ -20,6 +20,7 @@ import {
import { GraphCard } from "../views/Graph";
import { useFormContext } from "@/context/FormContext";
import { useLocale } from "@gisce/react-formiga-components";
import styled from "styled-components";
const { useToken } = theme;

type IndicatorProps = WidgetProps & {
Expand Down Expand Up @@ -108,25 +109,18 @@ const GraphIndicatorInput = (props: IndicatorInputProps) => {
if (!ooui) {
return;
}
if (!activeId) {
return;
}
fetchData();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ooui, activeId]);

if (error) {
if (error && error.message !== "active_id_not_found") {
return <ErrorAlert error={error} />;
}

const { id, model, limit, domain, context, initialView } = actionData || {};

const GraphComponent = readForViewEnabled ? GraphServer : Graph;

if (!activeId) {
return <GrahCardPendingToCalculate id={id} />;
}

return (
<GraphCard
id={id}
Expand All @@ -137,27 +131,31 @@ const GraphIndicatorInput = (props: IndicatorInputProps) => {
>
{loading && <CenteredSpinner />}
{!loading && (
<GraphComponent
view_id={initialView.id}
model={model}
context={context}
domain={domain}
limit={limit}
fixedHeight={height}
/>
<>
{!activeId ? (
<StyledEmpty
image={Empty.PRESENTED_IMAGE_SIMPLE}
imageStyle={{ height: 15 }}
/>
) : (
<GraphComponent
view_id={initialView.id}
model={model}
context={context}
domain={domain}
limit={limit}
fixedHeight={height}
/>
)}
</>
)}
</GraphCard>
);
};

const GrahCardPendingToCalculate = ({ id }: { id: string }) => {
const { t } = useLocale();
return (
<GraphCard
id={id}
parms={{}}
title={t("pendingToCalculate")}
openAction={() => {}}
/>
);
};
const StyledEmpty = styled(Empty)`
&.ant-empty.ant-empty-normal {
margin: 0;
margin-top: 5px;
}
`;
20 changes: 13 additions & 7 deletions src/widgets/views/Dashboard/dashboardHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ export async function fetchAction({
fields: {},
});

const parsedDomain = dataForAction.domain
? await ConnectionProvider.getHandler().evalDomain({
domain: dataForAction.domain,
values: globalValues,
context: { ...rootContext, ...parsedContext },
})
: [];
const finalContext = { ...rootContext, ...parsedContext };

const {
res_model: model,
Expand All @@ -42,6 +36,18 @@ export async function fetchAction({
} = dataForAction;
const treeExpandable = view_type === "tree";

if (!finalContext.active_id) {
return { title };
}

const parsedDomain = dataForAction.domain
? await ConnectionProvider.getHandler().evalDomain({
domain: dataForAction.domain,
values: globalValues,
context: finalContext,
})
: [];

const finalViews = [];

for (const viewArray of views) {
Expand Down

0 comments on commit f1ccb99

Please sign in to comment.