@@ -126,6 +126,7 @@ type NewOperationType = 'query' | 'mutation' | 'subscription';
126126type State = { |
127127 operation : ?OperationDefinitionNode ,
128128 newOperationType : NewOperationType ,
129+ operationToScrollTo : ?string ,
129130| } ;
130131
131132type Selections = $ReadOnlyArray < SelectionNode > ;
@@ -1445,6 +1446,7 @@ type RootViewProps = {|
14451446 ) = > void ,
14461447 onOperationRename : ( query : string ) = > void ,
14471448 onRunOperation : ( name : ?string ) = > void ,
1449+ onMount : ( rootViewElId : string ) = > void ,
14481450 getDefaultFieldNames : ( type : GraphQLObjectType ) = > Array < string > ,
14491451 getDefaultScalarArgValue : GetDefaultScalarArgValue ,
14501452 makeDefaultArg : ?MakeDefaultArg ,
@@ -1516,15 +1518,28 @@ class RootView extends React.PureComponent<RootViewProps, {}> {
15161518 }
15171519 } ;
15181520
1521+ _rootViewElId = ( ) => {
1522+ const { operation, name} = this . props ;
1523+ const rootViewElId = `${ operation } -${ name || 'unknown' } ` ;
1524+ return rootViewElId ;
1525+ } ;
1526+
1527+ componentDidMount ( ) {
1528+ const rootViewElId = this . _rootViewElId ( ) ;
1529+
1530+ this . props . onMount ( rootViewElId ) ;
1531+ }
1532+
15191533 render ( ) {
15201534 const {
15211535 operation ,
1522- name ,
15231536 definition ,
15241537 schema ,
15251538 getDefaultFieldNames ,
15261539 styleConfig ,
15271540 } = this . props ;
1541+ const rootViewElId = this . _rootViewElId ( ) ;
1542+
15281543 const fields = this . props . fields || { } ;
15291544 const operationDef = definition ;
15301545 const selections = operationDef . selectionSet . selections ;
@@ -1534,7 +1549,7 @@ class RootView extends React.PureComponent<RootViewProps, {}> {
15341549
15351550 return (
15361551 < div
1537- id = { ` ${ operation } - ${ name || 'unknown' } ` }
1552+ id = { rootViewElId }
15381553 style = { {
15391554 // The actions bar has its own top border
15401555 borderBottom : this . props . isLast ? 'none' : '1px solid #d6d6d6' ,
@@ -1626,7 +1641,11 @@ class Explorer extends React.PureComponent<Props, State> {
16261641 getDefaultScalarArgValue : defaultGetDefaultScalarArgValue ,
16271642 } ;
16281643
1629- state = { newOperationType : 'query' , operation : null } ;
1644+ state = {
1645+ newOperationType : 'query' ,
1646+ operation : null ,
1647+ operationToScrollTo : null ,
1648+ } ;
16301649
16311650 _ref : ?any ;
16321651 _resetScroll = ( ) => {
@@ -1645,6 +1664,18 @@ class Explorer extends React.PureComponent<Props, State> {
16451664 this . setState ( { newOperationType : value } ) ;
16461665 } ;
16471666
1667+ _handleRootViewMount = ( rootViewElId : string ) = > {
1668+ if (
1669+ ! ! this . state . operationToScrollTo &&
1670+ this . state . operationToScrollTo === rootViewElId
1671+ ) {
1672+ var selector = `.graphiql-explorer-root #${ rootViewElId } ` ;
1673+
1674+ var el = document . querySelector ( selector ) ;
1675+ el && el . scrollIntoView ( ) ;
1676+ }
1677+ } ;
1678+
16481679 render ( ) {
16491680 const { schema , query , makeDefaultArg } = this . props ;
16501681
@@ -1795,35 +1826,40 @@ class Explorer extends React.PureComponent<Props, State> {
17951826 definitions : newDefinitions ,
17961827 } ;
17971828
1829+ this . setState ( { operationToScrollTo : `${ kind } -${ newOperationName } ` } ) ;
1830+
17981831 this . props . onEdit ( print ( newOperationDef ) ) ;
17991832 } ;
18001833
18011834 const actionsOptions = [
18021835 ! ! queryFields ? (
18031836 < option
1837+ key = "query"
18041838 className = { 'toolbar-button' }
18051839 style = { styleConfig . styles . buttonStyle }
18061840 type = "link"
18071841 value = { ( 'query' : NewOperationType ) } >
1808- New Query
1842+ Query
18091843 </ option >
18101844 ) : null ,
18111845 ! ! mutationFields ? (
18121846 < option
1847+ key = "mutation"
18131848 className = { 'toolbar-button' }
18141849 style = { styleConfig . styles . buttonStyle }
18151850 type = "link"
18161851 value = { ( 'mutation' : NewOperationType ) } >
1817- New Mutation
1852+ Mutation
18181853 </ option >
18191854 ) : null ,
18201855 ! ! subscriptionFields ? (
18211856 < option
1857+ key = "subscription"
18221858 className = { 'toolbar-button' }
18231859 style = { styleConfig . styles . buttonStyle }
18241860 type = "link"
18251861 value = { ( 'subscription' : NewOperationType ) } >
1826- New Subscription
1862+ Subscription
18271863 </ option >
18281864 ) : null ,
18291865 ] . filter ( Boolean ) ;
@@ -1846,6 +1882,14 @@ class Explorer extends React.PureComponent<Props, State> {
18461882 borderTop : '1px solid rgb(214, 214, 214)' ,
18471883 } }
18481884 onSubmit = { event => event . preventDefault ( ) } >
1885+ < span
1886+ style = { {
1887+ display : 'inline-block' ,
1888+ flexGrow : '0' ,
1889+ textAlign : 'right' ,
1890+ } } >
1891+ Add new{ ' ' }
1892+ </ span >
18491893 < select
18501894 onChange = { event => this . _setAddOperationType ( event . target . value ) }
18511895 value = { this . state . newOperationType }
@@ -1950,6 +1994,7 @@ class Explorer extends React.PureComponent<Props, State> {
19501994 definition = { operation }
19511995 onOperationRename = { onOperationRename }
19521996 onTypeName = { fragmentTypeName }
1997+ onMount = { this . _handleRootViewMount }
19531998 onEdit = { newDefinition => {
19541999 const newQuery = {
19552000 ...parsedQuery ,
0 commit comments