@@ -2,79 +2,69 @@ import { GRAPHQL_QUERY_OBJECT } from "@/config/constants";
22import GraphqlQueryDetailsCard from "@/entities/graphql/ui/graphql-query-details-card" ;
33import GraphQLQueryDetailsPageSkeleton from "@/entities/graphql/ui/graphql-query-details-page-skeleton" ;
44import GraphqlQueryViewerCard from "@/entities/graphql/ui/graphql-query-viewer-card" ;
5- import { getObjectDetailsPaginated } from "@/entities/nodes/api/getObjectDetails " ;
6- import { getSchemaObjectColumns } from "@/entities/nodes/ object-items/getSchemaObjectColumns " ;
5+ import { useObjectDetails } from "@/entities/nodes/hooks/useObjectDetails " ;
6+ import { useGetObjectPermissions } from "@/entities/permission/domain/get- object-permissions.query " ;
77import { Permission } from "@/entities/permission/types" ;
8- import { getPermission } from "@/entities/permission/utils" ;
9- import { nodeSchemasAtom } from "@/entities/schema/stores/schema.atom" ;
10- import { NodeSchema } from "@/entities/schema/types" ;
8+ import { ModelSchema , NodeSchema } from "@/entities/schema/types" ;
119import { CoreGraphQlQuery } from "@/shared/api/graphql/generated/graphql" ;
12- import useQuery from "@/shared/api/graphql/useQuery " ;
10+ import ErrorScreen from "@/shared/components/errors/error-screen " ;
1311import NoDataFound from "@/shared/components/errors/no-data-found" ;
1412import UnauthorizedScreen from "@/shared/components/errors/unauthorized-screen" ;
13+ import { LoadingIndicator } from "@/shared/components/loading/loading-indicator" ;
1514import { useTitle } from "@/shared/hooks/useTitle" ;
16- import { gql } from "@apollo/client" ;
17- import { useAtomValue } from "jotai/index" ;
1815
19- export default function GraphqlQueryDetailsPage ( { graphqlQueryId } : { graphqlQueryId : string } ) {
20- useTitle ( "GraphQL Query details" ) ;
21-
22- const objectid = graphqlQueryId ;
23-
24- const nodes = useAtomValue ( nodeSchemasAtom ) ;
25- const graphqlQuerySchema = nodes . find ( ( s ) => s . kind === GRAPHQL_QUERY_OBJECT ) ;
26-
27- const columns = getSchemaObjectColumns ( { schema : graphqlQuerySchema } ) ;
28-
29- const query = gql (
30- getObjectDetailsPaginated ( {
31- objectid,
32- kind : GRAPHQL_QUERY_OBJECT ,
33- columns,
34- hasPermissions : true ,
35- } )
36- ) ;
37-
38- const { loading, data, refetch } = useQuery ( query , {
39- skip : ! graphqlQuerySchema ,
40- } ) ;
16+ export interface GraphqlQueryDetailsPageProps {
17+ graphqlQuerySchema : ModelSchema ;
18+ graphqlQueryId : string ;
19+ }
4120
42- if ( ! graphqlQuerySchema || loading ) return < GraphQLQueryDetailsPageSkeleton /> ;
21+ export default function GraphqlQueryDetailsPage ( {
22+ graphqlQuerySchema,
23+ graphqlQueryId,
24+ } : GraphqlQueryDetailsPageProps ) {
25+ useTitle ( "GraphQL Query details" ) ;
4326
44- const graphqlQueries = data && data . CoreGraphQLQuery . edges ;
45- if ( graphqlQueries . length === 0 ) return < NoDataFound /> ;
27+ const { isPending, error, data : permission } = useGetObjectPermissions ( GRAPHQL_QUERY_OBJECT ) ;
4628
47- const graphqlQuery : CoreGraphQlQuery = graphqlQueries [ 0 ] . node ;
29+ if ( isPending ) {
30+ return < LoadingIndicator className = "h-[calc(100vh-10rem)]" /> ;
31+ }
4832
49- const permission = getPermission ( data ?. [ GRAPHQL_QUERY_OBJECT ] ?. permissions ?. edges ) ;
33+ if ( error ) {
34+ return < ErrorScreen message = "Something went wrong when fetching permissions." /> ;
35+ }
5036
5137 if ( ! permission . view . isAllowed ) {
5238 return < UnauthorizedScreen message = { permission . view . message } /> ;
5339 }
5440
5541 return (
56- graphqlQuery && (
57- < GraphqlQueryDetailsContent
58- graphqlQuerySchema = { graphqlQuerySchema }
59- graphqlQuery = { graphqlQuery }
60- refetch = { refetch }
61- permission = { permission }
62- />
63- )
42+ < GraphqlQueryDetails
43+ graphqlQueryId = { graphqlQueryId }
44+ graphqlQuerySchema = { graphqlQuerySchema as NodeSchema }
45+ permission = { permission }
46+ />
6447 ) ;
6548}
6649
67- const GraphqlQueryDetailsContent = ( {
68- graphqlQuery ,
50+ const GraphqlQueryDetails = ( {
51+ graphqlQueryId ,
6952 graphqlQuerySchema,
70- refetch,
7153 permission,
7254} : {
73- graphqlQuery : CoreGraphQlQuery ;
55+ graphqlQueryId : string ;
7456 graphqlQuerySchema : NodeSchema ;
75- refetch : ( ) => Promise < unknown > ;
7657 permission : Permission ;
7758} ) => {
59+ const { loading, data, refetch } = useObjectDetails ( graphqlQuerySchema , graphqlQueryId ) ;
60+
61+ if ( loading ) return < GraphQLQueryDetailsPageSkeleton /> ;
62+
63+ const graphqlQueries = data && data . CoreGraphQLQuery . edges ;
64+ if ( graphqlQueries . length === 0 ) return < NoDataFound /> ;
65+
66+ const graphqlQuery : CoreGraphQlQuery = graphqlQueries [ 0 ] . node ;
67+
7868 return (
7969 < section className = "flex flex-wrap lg:flex-nowrap items-start gap-2 p-2" >
8070 < GraphqlQueryDetailsCard
@@ -84,7 +74,7 @@ const GraphqlQueryDetailsContent = ({
8474 permission = { permission }
8575 />
8676
87- < GraphqlQueryViewerCard query = { graphqlQuery . query . value ?? "" } permission = { permission } />
77+ < GraphqlQueryViewerCard query = { graphqlQuery . query . value ?? "" } />
8878 </ section >
8979 ) ;
9080} ;
0 commit comments