Skip to content

Commit dc78361

Browse files
committed
Refactor chart handling: integrate ChartContent component, replace MultiTrackHorizontalBarChart logic with modular approach, and update multi-index aggregation query.
1 parent b225087 commit dc78361

File tree

5 files changed

+229
-176
lines changed

5 files changed

+229
-176
lines changed

packages/core/src/features/guppy/guppySlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ export const explorerApi = explorerTags.injectEndpoints({
617617
},
618618
}),
619619
getGetMultiIndexAggregation: builder.query<
620-
ObjectIdQueryResponse,
620+
Record<string, any>,
621621
MultiIndexFieldQueryRequest
622622
>({
623623
query: ({

packages/frontend/src/components/Content/Chart.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import { createChart } from '../charts/createChart';
3+
import { ChartProps } from '../charts';
4+
import {
5+
HistogramDataArray,
6+
useGetGetMultiIndexAggregationQuery,
7+
} from '@gen3/core';
8+
import { LoadingOverlay } from '@mantine/core';
9+
import { ErrorCard } from '../../index';
10+
11+
interface ChartContentProps {
12+
chartType?: string;
13+
parameters?: Record<string, any>;
14+
width?: string;
15+
}
16+
17+
const ChartContent = ({ chartType, parameters }: ChartContentProps) => {
18+
const chart: ChartProps = parameters?.chart;
19+
const dataFunctionParameters = parameters?.dataFetch;
20+
const { data, isFetching, isError } = useGetGetMultiIndexAggregationQuery(
21+
dataFunctionParameters,
22+
);
23+
24+
if (!chartType) {
25+
return <div>No chart type specified</div>;
26+
}
27+
28+
if (isError) {
29+
return <ErrorCard message="Error fetching chart data" />;
30+
}
31+
32+
const chartComponent = createChart(chartType, {
33+
data: data === undefined ? [] : (data as HistogramDataArray),
34+
total: 1,
35+
valueType: chart.valueType ?? 'count',
36+
label: chart.label,
37+
showLegendInChart: chart.showLegendInChart,
38+
});
39+
40+
return (
41+
<div className="flex justify-center pt-2 items-center m-2">
42+
<LoadingOverlay visible={isFetching} />
43+
{chartComponent}
44+
</div>
45+
);
46+
};
47+
48+
export default ChartContent;

packages/frontend/src/components/Content/LandingPageContent.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { MdFormatQuote, MdGroup, MdOutlineBarChart, MdOutlineSearch, } from 'rea
99
import { FaGraduationCap, FaRegQuestionCircle, FaVideo } from 'react-icons/fa';
1010
import Gen3Link from '../../features/Navigation/Gen3Link';
1111
import TextContent, { ContentType } from './TextContent';
12+
import ChartContent from './ChartContent';
1213
import { Gen3AppConfigData } from '../../lib/content/types';
14+
import { ChartProps } from '../charts';
1315

1416
export interface LandingPageContentProp {
1517
content: LandingPageProps;
@@ -27,6 +29,13 @@ export interface leftRightProps {
2729
readonly src: string;
2830
readonly alt: string;
2931
};
32+
readonly chart?: {
33+
readonly chartType: string;
34+
parameters: {
35+
readonly chart?: ChartProps;
36+
readonly dataFetch: Record<string, any>;
37+
};
38+
};
3039
}
3140
export interface LandingPageProps extends Gen3AppConfigData {
3241
readonly topTitle?: string;
@@ -122,6 +131,16 @@ const LandingPageContent = ({ content }: LandingPageContentProp) => {
122131
</div>
123132
);
124133
}
134+
if (obj.type === 'chart') {
135+
return (
136+
<div key="chart" className="h-full relative">
137+
<ChartContent
138+
chartType={obj.chart?.chartType}
139+
parameters={obj.chart?.parameters}
140+
/>
141+
</div>
142+
);
143+
}
125144
});
126145
return (
127146
<div key={index} className="flex mx-20">

0 commit comments

Comments
 (0)