@@ -4,11 +4,8 @@ import {
44 CheckDebugTrace ,
55 CheckDebugTrace_Permissionship ,
66 CheckDebugTrace_PermissionType ,
7- } from "../spicedb-common/protodefs/authzed/api/v1/debug" ;
8- import {
9- Struct ,
10- Value ,
11- } from "../spicedb-common/protodefs/google/protobuf/struct" ;
7+ } from "../spicedb-common/protodefs/authzed/api/v1/debug_pb" ;
8+ import type { JsonObject , JsonValue } from "@bufbuild/protobuf" ;
129import { createStyles , makeStyles , Theme } from "@material-ui/core/styles" ;
1310import CheckCircleIcon from "@material-ui/icons/CheckCircle" ;
1411import ChevronRightIcon from "@material-ui/icons/ChevronRight" ;
@@ -105,8 +102,8 @@ export function CheckDebugTraceView(props: {
105102 ) ;
106103 } ) ;
107104
108- if ( t . resolution . oneofKind === "subProblems" ) {
109- t . resolution . subProblems . traces . forEach ( appendExpanded ) ;
105+ if ( t . resolution . case === "subProblems" ) {
106+ t . resolution . value . traces . forEach ( appendExpanded ) ;
110107 }
111108 } ;
112109
@@ -145,18 +142,16 @@ function CheckDebugTraceItems(props: {
145142 const isNotMember = hasNotPermission ( props . trace ) ;
146143
147144 const children =
148- props . trace . resolution . oneofKind === "subProblems"
149- ? props . trace . resolution . subProblems . traces . map (
150- ( subTrace , index ) => {
151- return (
152- < CheckDebugTraceItems
153- key = { index }
154- trace = { subTrace }
155- localParseService = { props . localParseService }
156- />
157- ) ;
158- } ,
159- )
145+ props . trace . resolution . case === "subProblems"
146+ ? props . trace . resolution . value . traces . map ( ( subTrace , index ) => {
147+ return (
148+ < CheckDebugTraceItems
149+ key = { index }
150+ trace = { subTrace }
151+ localParseService = { props . localParseService }
152+ />
153+ ) ;
154+ } )
160155 : [ ] ;
161156
162157 if (
@@ -285,14 +280,18 @@ function CaveatTreeItem(props: {
285280 ) ;
286281}
287282
288- function ContextTreeView ( context : Struct | undefined ) {
283+ function ContextTreeView ( context : JsonObject | undefined ) {
289284 if ( context === undefined ) {
290285 return null ;
291286 }
292287
293- return Object . keys ( context . fields ) . map ( ( key ) => {
288+ if ( context === null ) {
289+ return null ;
290+ }
291+
292+ return Object . keys ( context ) . map ( ( key ) => {
294293 let label = < span > { key } </ span > ;
295- const [ value , isItemValue ] = ContextTreeValue ( context ?. fields [ key ] ) ;
294+ const [ value , isItemValue ] = ContextTreeValue ( context [ key ] ) ;
296295 if ( ! isItemValue ) {
297296 label = (
298297 < span >
@@ -309,31 +308,25 @@ function ContextTreeView(context: Struct | undefined) {
309308 } ) ;
310309}
311310
312- function ContextTreeValue ( value : Value ) {
313- switch ( value . kind . oneofKind ) {
314- case "nullValue" :
315- return [ < code > null</ code > , false ] ;
316-
317- case "numberValue" :
318- return [ < code > { value . kind . numberValue . toString ( ) } </ code > , false ] ;
319-
320- case "stringValue" :
321- return [ < code > { value . kind . stringValue } </ code > , false ] ;
322-
323- case "boolValue" :
324- return [ < code > { value . kind . boolValue . toString ( ) } </ code > , false ] ;
325-
326- case "structValue" :
327- return [ ContextTreeView ( value . kind . structValue ) , true ] ;
328-
329- case "listValue" :
330- return [
331- value . kind . listValue . values . map ( ( v ) => {
332- return < TreeItem nodeId = "" > { ContextTreeValue ( v ) } </ TreeItem > ;
333- } ) ,
334- true ,
335- ] ;
311+ function ContextTreeValue ( value : JsonValue ) {
312+ if ( value === null ) {
313+ return [ < code > null</ code > , false ] ;
336314 }
337-
338- return [ null , false ] ;
315+ if ( typeof value === "boolean" ) {
316+ return [ < code > { value . toString ( ) } </ code > , false ] ;
317+ }
318+ if ( Array . isArray ( value ) ) {
319+ return [
320+ value . map ( ( v ) => {
321+ return < TreeItem nodeId = "" > { ContextTreeValue ( v ) } </ TreeItem > ;
322+ } ) ,
323+ true ,
324+ ] ;
325+ }
326+ // NOTE: we've already handled null and array above, so this will match on objects.
327+ if ( typeof value === "object" ) {
328+ return [ ContextTreeView ( value ) , true ] ;
329+ }
330+ // If we've gotten this far, we have a number or a string and we can render it straight out.
331+ return [ < code > { value } </ code > , false ] ;
339332}
0 commit comments