1- import React , { useRef } from 'react' ;
2- import Link from 'next/link' ;
3- import { useParams } from 'next/navigation' ;
4- import assam_geojson from '@/geo_json/assam_geojson' ;
51import { renderGeoJSON } from '@/geo_json/render_geojson' ;
62import { graphql } from '@/gql' ;
73import { useQuery } from '@tanstack/react-query' ;
84import ReactECharts from 'echarts-for-react' ;
95import * as echarts from 'echarts/core' ;
6+ import Image from 'next/image' ;
7+ import Link from 'next/link' ;
8+ import { useParams } from 'next/navigation' ;
109import {
1110 Button ,
1211 Carousel ,
@@ -18,22 +17,36 @@ import {
1817 Spinner ,
1918 Text ,
2019} from 'opub-ui' ;
20+ import { useRef } from 'react' ;
2121
22- import { GraphQL } from '@/lib/api' ;
2322import { Icons } from '@/components/icons' ;
23+ import { GraphQL } from '@/lib/api' ;
2424
25- const charts = graphql ( `
26- query chartsData($datasetId: UUID!) {
27- chartsDetails(datasetId: $datasetId) {
28- aggregateType
29- chartType
30- description
31- id
32- name
33- showLegend
34- xAxisLabel
35- yAxisLabel
36- chart
25+ const DetailsQuery : any = graphql ( `
26+ query ChartDetailsQuery($datasetId: UUID!) {
27+ getChartData(datasetId: $datasetId) {
28+ __typename
29+ ... on TypeResourceChart {
30+ aggregateType
31+ chartType
32+ description
33+ id
34+ name
35+ showLegend
36+ xAxisLabel
37+ yAxisLabel
38+ chart
39+ }
40+ ... on TypeResourceChartImage {
41+ name
42+ id
43+ description
44+ image {
45+ name
46+ path
47+ url
48+ }
49+ }
3750 }
3851 }
3952` ) ;
@@ -42,24 +55,12 @@ const Details = () => {
4255 const params = useParams ( ) ;
4356 const chartRef = useRef < ReactECharts > ( null ) ;
4457
45- const {
46- data,
47- isLoading,
48- refetch,
49- } : { data : any ; isLoading : boolean ; refetch : any } = useQuery (
50- [ `chartdata_${ params . datasetIdentifier } ` ] ,
51- ( ) =>
52- GraphQL (
53- charts ,
54- {
55- // Entity Headers if present
56- } ,
57- {
58- datasetId : params . datasetIdentifier ,
59- }
60- )
58+ const { data, isLoading } : { data : any ; isLoading : any } = useQuery (
59+ [ `chartDetails_${ params . id } ` ] ,
60+ ( ) => GraphQL ( DetailsQuery , { } , { datasetId : params . datasetIdentifier } )
6161 ) ;
6262
63+
6364 const renderChart = ( item : any ) => {
6465 if ( item . chartType === 'ASSAM_DISTRICT' || item . chartType === 'ASSAM_RC' ) {
6566 // Register the map
@@ -78,7 +79,7 @@ const Details = () => {
7879 < div className = " mt-8 flex justify-center" >
7980 < Spinner />
8081 </ div >
81- ) : data ?. chartsDetails ?. length > 0 ? (
82+ ) : data ?. getChartData ?. length > 0 ? (
8283 < >
8384 < Text variant = "bodyLg" className = "mx-6 lg:mx-0" >
8485 Visualizations
@@ -87,11 +88,21 @@ const Details = () => {
8788 < Carousel className = "w-full" >
8889 < div className = " px-12" >
8990 < CarouselContent className = "flex-grow" >
90- { data ?. chartsDetails . map ( ( item : any , index : any ) => (
91+ { data ?. getChartData . map ( ( item : any , index : any ) => (
9192 < CarouselItem key = { index } className = "m-auto" >
9293 < div className = "w-full border-2 border-solid border-baseGraySlateSolid4 bg-surfaceDefault p-6 text-center shadow-basicLg max-sm:p-2" >
9394 < div className = "lg:p-10" >
94- { renderChart ( item ) } { ' ' }
95+ { item . __typename === 'TypeResourceChart' ? (
96+ renderChart ( item )
97+ ) : (
98+ < Image
99+ src = { `${ process . env . NEXT_PUBLIC_BACKEND_URL } /api/download/chart_image/${ item . id } ` }
100+ alt = { '' }
101+ width = { 300 }
102+ height = { 300 }
103+ unoptimized
104+ />
105+ ) }
95106 { /* Call the renderChart function */ }
96107 </ div >
97108 < div className = "flex items-center justify-between gap-2 max-sm:flex-wrap" >
0 commit comments