@@ -19,6 +19,7 @@ import type { ParsedInputNode } from "@src/parse/parseNodeTypes";
1919import { DocumentationSection } from "@src/react-app/components/form/ProcedureForm/DescriptionSection" ;
2020import { Field } from "@src/react-app/components/form/Field" ;
2121import { ProcedureFormContextProvider } from "@src/react-app/components/form/ProcedureForm/ProcedureFormContext" ;
22+ import getSize from "string-byte-length" ;
2223
2324const TRPCErrorSchema = z . object ( {
2425 meta : z . object ( {
@@ -65,6 +66,9 @@ export function ProcedureForm({
6566 const [ queryInput , setQueryInput ] = useState < any > ( null ) ;
6667 const formRef = useRef < HTMLFormElement | null > ( null ) ;
6768 const context = trpc . useContext ( ) ;
69+ const [ dataSize , setDataSize ] = useState < number | undefined > ( ) ;
70+ const [ startTime , setStartTime ] = useState < number | undefined > ( ) ;
71+ const [ opDuration , setOpDuration ] = useState < number | undefined > ( ) ;
6872
6973 function getProcedure ( ) {
7074 var cur : typeof trpc | ( typeof trpc ) [ string ] = trpc ;
@@ -84,6 +88,11 @@ export function ProcedureForm({
8488 initialData : null ,
8589 retry : false ,
8690 refetchOnWindowFocus : false ,
91+ onSuccess : ( data : unknown ) => {
92+ if ( startTime ) setOpDuration ( Date . now ( ) - startTime ) ;
93+ setDataSize ( getSize ( JSON . stringify ( data ) ) ) ;
94+ setStartTime ( undefined ) ;
95+ } ,
8796 } ) ;
8897 } ) ( ) as UseQueryResult < any > ;
8998
@@ -100,6 +109,11 @@ export function ProcedureForm({
100109 //@ts -ignore
101110 return router . useMutation ( {
102111 retry : false ,
112+ onSuccess : ( data : unknown ) => {
113+ if ( startTime ) setOpDuration ( Date . now ( ) - startTime ) ;
114+ setDataSize ( getSize ( JSON . stringify ( data ) ) ) ;
115+ setStartTime ( undefined ) ;
116+ } ,
103117 } ) ;
104118 } ) ( ) as UseMutationResult < any > ;
105119
@@ -115,8 +129,8 @@ export function ProcedureForm({
115129 [ ROOT_VALS_PROPERTY_NAME ] : defaultFormValuesForNode ( procedure . node ) ,
116130 } ,
117131 } ) ;
118-
119132 function onSubmit ( data : { [ ROOT_VALS_PROPERTY_NAME ] : any } ) {
133+ setStartTime ( Date . now ( ) ) ;
120134 const newData = { json : data [ ROOT_VALS_PROPERTY_NAME ] } ;
121135 if ( procedure . procedureType === "query" ) {
122136 setQueryInput ( newData ) ;
@@ -207,15 +221,17 @@ export function ProcedureForm({
207221 </ div >
208222 </ form >
209223 < div className = "flex flex-col space-y-4" >
210- { data && < RequestResult result = { data } /> }
224+ { data && (
225+ < RequestResult result = { data } size = { dataSize } time = { opDuration } />
226+ ) }
211227 { ! data && data !== null && (
212228 < Response > Successful request but no data was returned</ Response >
213229 ) }
214230 { error &&
215231 ( isTrpcError ( error ) ? (
216232 < Error error = { error } />
217233 ) : (
218- < Response > { JSON . stringify ( error ) } </ Response >
234+ < Response > { error } </ Response >
219235 ) ) }
220236 </ div >
221237 </ CollapsableSection >
0 commit comments