Skip to content

Commit

Permalink
fix: return graph null when datalist is null (#393)
Browse files Browse the repository at this point in the history
* RM#74244
  • Loading branch information
gca-axelor authored Feb 9, 2024
1 parent 3776226 commit 8660c68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/dashboards/view/DashboardScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ export const DashboardScreen = ({dashboardId}) => {
const I18n = useTranslator();

const [dashboard, setDashboard] = useState<any>({});
const [loading, setLoading] = useState<boolean>(false);

const refresh = useCallback(() => {
setLoading(true);
fetchDashboard({id: dashboardId})
.then(response => {
setDashboard({...(response?.data?.object ?? {}), id: dashboardId});
})
.catch(() => setDashboard({}));
.catch(() => setDashboard({}))
.finally(() => setLoading(false));
}, [dashboardId]);

useEffect(() => {
Expand Down Expand Up @@ -78,7 +81,7 @@ export const DashboardScreen = ({dashboardId}) => {
}));
}, [dashboard]);

if (dashboard?.id !== dashboardId) {
if (loading) {
return <ActivityIndicator size="large" />;
}

Expand Down
12 changes: 8 additions & 4 deletions packages/ui/src/components/templates/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,20 @@ const Dashboard = ({style, lineList}: DashboardProps) => {
return (
<ScrollView style={[styles.container, style]}>
{lineList?.map((line, indexLine) => {
const nbGraphInLine = Math.min(
line.graphList?.length,
MAX_GRAPH_PER_LINE,
const validGraphs = line.graphList.filter(
graph => graph.dataList?.[0]?.length > 0,
);
const nbGraphInLine = Math.min(validGraphs.length, MAX_GRAPH_PER_LINE);

const limitedGraphList = line.graphList?.slice(0, MAX_GRAPH_PER_LINE);

return (
<View style={styles.lineContainer} key={indexLine}>
{limitedGraphList?.map((graph, indexGraph) => {
return renderChart(graph, indexGraph, nbGraphInLine);
if (graph.dataList?.[0]?.length > 0) {
return renderChart(graph, indexGraph, nbGraphInLine);
}
return null;
})}
</View>
);
Expand Down

0 comments on commit 8660c68

Please sign in to comment.