1
1
import { useContext } from 'react' ;
2
2
import { TypeContext } from '@/components/ApiDocs/ApiModalProvider' ;
3
3
import { View } from '@aws-amplify/ui-react' ;
4
+ import references from '@/directory/apiReferences.json' ;
4
5
5
6
export interface LinkDataType {
6
7
name : string ;
7
8
kind : number ;
8
9
type : string | LinkDataType ;
9
- target : number ;
10
+ target : number | LinkDataType ;
10
11
value : string ;
11
12
typeArguments : LinkDataType [ ] ;
12
13
elementType : LinkDataType ;
@@ -21,7 +22,6 @@ export const TypeLink = ({ linkData, breadCrumbs }: TypeLinkInterface) => {
21
22
const { setModalData, modalOpen, addBreadCrumb, setBC } =
22
23
useContext ( TypeContext ) ;
23
24
const name = linkData . name ;
24
- const className = `type-link kind-${ linkData . kind } ` ;
25
25
26
26
const onClickHandler = ( ) => {
27
27
setModalData ( linkData ) ;
@@ -39,6 +39,11 @@ export const TypeLink = ({ linkData, breadCrumbs }: TypeLinkInterface) => {
39
39
return < View as = "span" > { linkData . name } </ View > ;
40
40
} else if ( linkData . type === 'literal' ) {
41
41
return < View as = "span" > { linkData . value } </ View > ;
42
+ } else if (
43
+ linkData . type === 'typeOperator' &&
44
+ typeof linkData . target !== 'number'
45
+ ) {
46
+ return < View as = "span" > { linkData . target . name } </ View > ;
42
47
} else if ( linkData . type === 'array' ) {
43
48
return [
44
49
< TypeLink
@@ -49,6 +54,21 @@ export const TypeLink = ({ linkData, breadCrumbs }: TypeLinkInterface) => {
49
54
'[]'
50
55
] ;
51
56
} else {
57
+ let type = 'unknown' ;
58
+ if ( ! linkData . type ) {
59
+ type = 'interface' ;
60
+ } else if ( typeof linkData . type === 'string' ) {
61
+ type = linkData . type ;
62
+ } else if ( linkData ?. type ?. type && typeof linkData . type . type === 'string' ) {
63
+ type = linkData . type . type ;
64
+ }
65
+ if ( type === 'reference' && typeof linkData . target === 'number' ) {
66
+ const referencedObject = references [ linkData . target ] ;
67
+ type = referencedObject . type ?. type
68
+ ? referencedObject . type . type
69
+ : 'interface' ;
70
+ }
71
+ const className = `type-link type-${ type } ` ;
52
72
return (
53
73
< button className = { className } onClick = { onClickHandler } >
54
74
{ name }
0 commit comments