@@ -65,6 +65,28 @@ const AddResourceChartImage: any = graphql(`
6565 }
6666` ) ;
6767
68+ const AddResourceImage : any = graphql ( `
69+ mutation GenerateResourceChart($resource: UUID!) {
70+ addResourceChart(resource: $resource) {
71+ __typename
72+ ... on TypeResourceChart {
73+ id
74+ name
75+ }
76+ }
77+ }
78+ ` ) ;
79+
80+ const datasetResourceList : any = graphql ( `
81+ query all_resources($datasetId: UUID!) {
82+ datasetResources(datasetId: $datasetId) {
83+ id
84+ type
85+ name
86+ }
87+ }
88+ ` ) ;
89+
6890const ChartsList : React . FC < ChartsListProps > = ( {
6991 setType,
7092 type,
@@ -173,10 +195,49 @@ const ChartsList: React.FC<ChartsListProps> = ({
173195 }
174196 ) ;
175197
198+ // AddResourceImage
199+
200+ const resourceList : { data : any } = useQuery ( [ `charts_${ params . id } ` ] , ( ) =>
201+ GraphQL (
202+ datasetResourceList ,
203+ {
204+ [ params . entityType ] : params . entitySlug ,
205+ } ,
206+ { datasetId : params . id }
207+ )
208+ ) ;
209+
210+ const resourceChartImage : {
211+ mutate : any ;
212+ isLoading : any ;
213+ } = useMutation (
214+ ( data : { resource : UUID } ) =>
215+ GraphQL (
216+ AddResourceImage ,
217+ {
218+ [ params . entityType ] : params . entitySlug ,
219+ } ,
220+ data
221+ ) ,
222+ {
223+ onSuccess : ( res : any ) => {
224+ toast ( 'Resource Chart Created Successfully' ) ;
225+ refetch ( ) ;
226+ setType ( 'visualize' ) ;
227+ setChartId ( res . addResourceChart . id ) ;
228+
229+ // setImageId(res.id);
230+ } ,
231+ onError : ( err : any ) => {
232+ toast ( `Received ${ err } while deleting chart ` ) ;
233+ } ,
234+ }
235+ ) ;
236+
176237 const handleChart = ( row : any ) => {
177- if ( row . original . __typename === 'TypeResourceChart' ) {
178- setChartId ( row . original . id ) ;
238+ if ( row . original . typename === 'TypeResourceChart' ) {
179239 setType ( 'visualize' ) ;
240+ setChartId ( row . original . id ) ;
180241 } else {
181242 setType ( 'img' ) ;
182243 setImageId ( row . original . id ) ;
@@ -266,7 +327,13 @@ const ChartsList: React.FC<ChartsListProps> = ({
266327 onChange = { ( e ) => handleSearchChange ( e ) }
267328 />
268329 < div className = "flex gap-3" >
269- < Button onClick = { ( e ) => setType ( 'visualize' ) } >
330+ < Button
331+ onClick = { ( e ) =>
332+ resourceChartImage . mutate ( {
333+ resource : resourceList . data . datasetResources [ 0 ] . id ,
334+ } )
335+ }
336+ >
270337 Visualize Data
271338 </ Button >
272339 < Button
0 commit comments