1
1
import './Voyager.css' ;
2
2
import './viewport.css' ;
3
3
4
+ import Button from '@mui/material/Button' ;
5
+ import Stack from '@mui/material/Stack' ;
4
6
import { ThemeProvider } from '@mui/material/styles' ;
5
7
import {
6
8
Children ,
@@ -17,6 +19,7 @@ import { extractTypeId, getSchema } from '../introspection';
17
19
import { voyagerIntrospectionQuery } from '../utils/introspection-query' ;
18
20
import DocExplorer from './doc-explorer/DocExplorer' ;
19
21
import GraphViewport from './GraphViewport' ;
22
+ import { IntrospectionModal } from './IntrospectionModal' ;
20
23
import { theme } from './MUITheme' ;
21
24
import Settings from './settings/Settings' ;
22
25
import PoweredBy from './utils/PoweredBy' ;
@@ -45,6 +48,8 @@ const defaultDisplayOptions = {
45
48
export interface VoyagerProps {
46
49
introspection : IntrospectionProvider | unknown ;
47
50
displayOptions ?: VoyagerDisplayOptions ;
51
+ introspectionPresets ?: { [ name : string ] : any } ;
52
+ allowToChangeSchema ?: boolean ;
48
53
hideDocs ?: boolean ;
49
54
hideSettings ?: boolean ;
50
55
hideVoyagerLogo ?: boolean ;
@@ -53,6 +58,7 @@ export interface VoyagerProps {
53
58
}
54
59
55
60
export default function Voyager ( props : VoyagerProps ) {
61
+ const [ introspectionModalOpen , setIntrospectionModalOpen ] = useState ( false ) ;
56
62
const [ introspectionData , setIntrospectionData ] = useState ( null ) ;
57
63
const [ displayOptions , setDisplayOptions ] = useState ( {
58
64
...defaultDisplayOptions ,
@@ -103,6 +109,7 @@ export default function Voyager(props: VoyagerProps) {
103
109
const [ selected , setSelected ] = useState ( { typeID : null , edgeID : null } ) ;
104
110
105
111
const {
112
+ allowToChangeSchema = false ,
106
113
hideDocs = false ,
107
114
hideSettings = false ,
108
115
// TODO: switch to false in the next major version
@@ -121,10 +128,22 @@ export default function Voyager(props: VoyagerProps) {
121
128
{ ! hideDocs && renderPanel ( ) }
122
129
{ ! hideSettings && renderSettings ( ) }
123
130
{ renderGraphViewport ( ) }
131
+ { allowToChangeSchema && renderIntrospectionModal ( ) }
124
132
</ div >
125
133
</ ThemeProvider >
126
134
) ;
127
135
136
+ function renderIntrospectionModal ( ) {
137
+ return (
138
+ < IntrospectionModal
139
+ open = { introspectionModalOpen }
140
+ presets = { props . introspectionPresets }
141
+ onClose = { ( ) => setIntrospectionModalOpen ( false ) }
142
+ onChange = { setIntrospectionData }
143
+ />
144
+ ) ;
145
+ }
146
+
128
147
function renderPanel ( ) {
129
148
const children = Children . toArray ( props . children ) ;
130
149
const panelHeader = children . find (
@@ -135,6 +154,7 @@ export default function Voyager(props: VoyagerProps) {
135
154
< div className = "doc-panel" >
136
155
< div className = "contents" >
137
156
{ ! hideVoyagerLogo && < VoyagerLogo /> }
157
+ { allowToChangeSchema && renderChangeSchemaButton ( ) }
138
158
{ panelHeader }
139
159
< DocExplorer
140
160
typeGraph = { typeGraph }
@@ -150,6 +170,22 @@ export default function Voyager(props: VoyagerProps) {
150
170
) ;
151
171
}
152
172
173
+ function renderChangeSchemaButton ( ) {
174
+ // TODO: generalize padding by applying it to the whole panel
175
+ return (
176
+ < Stack padding = { ( { panelSpacing } ) => `0 ${ panelSpacing } ` } >
177
+ < Button
178
+ color = "primary"
179
+ style = { { color : 'white' } }
180
+ variant = "contained"
181
+ onClick = { ( ) => setIntrospectionModalOpen ( true ) }
182
+ >
183
+ Change Schema
184
+ </ Button >
185
+ </ Stack >
186
+ ) ;
187
+ }
188
+
153
189
function renderSettings ( ) {
154
190
if ( schema == null ) return null ;
155
191
0 commit comments