@@ -126,6 +126,7 @@ type NewOperationType = 'query' | 'mutation' | 'subscription';
126
126
type State = { |
127
127
operation : ?OperationDefinitionNode ,
128
128
newOperationType : NewOperationType ,
129
+ operationToScrollTo : ?string ,
129
130
| } ;
130
131
131
132
type Selections = $ReadOnlyArray < SelectionNode > ;
@@ -1445,6 +1446,7 @@ type RootViewProps = {|
1445
1446
) = > void ,
1446
1447
onOperationRename : ( query : string ) = > void ,
1447
1448
onRunOperation : ( name : ?string ) = > void ,
1449
+ onMount : ( rootViewElId : string ) = > void ,
1448
1450
getDefaultFieldNames : ( type : GraphQLObjectType ) = > Array < string > ,
1449
1451
getDefaultScalarArgValue : GetDefaultScalarArgValue ,
1450
1452
makeDefaultArg : ?MakeDefaultArg ,
@@ -1516,15 +1518,28 @@ class RootView extends React.PureComponent<RootViewProps, {}> {
1516
1518
}
1517
1519
} ;
1518
1520
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
+
1519
1533
render ( ) {
1520
1534
const {
1521
1535
operation ,
1522
- name ,
1523
1536
definition ,
1524
1537
schema ,
1525
1538
getDefaultFieldNames ,
1526
1539
styleConfig ,
1527
1540
} = this . props ;
1541
+ const rootViewElId = this . _rootViewElId ( ) ;
1542
+
1528
1543
const fields = this . props . fields || { } ;
1529
1544
const operationDef = definition ;
1530
1545
const selections = operationDef . selectionSet . selections ;
@@ -1534,7 +1549,7 @@ class RootView extends React.PureComponent<RootViewProps, {}> {
1534
1549
1535
1550
return (
1536
1551
< div
1537
- id = { ` ${ operation } - ${ name || 'unknown' } ` }
1552
+ id = { rootViewElId }
1538
1553
style = { {
1539
1554
// The actions bar has its own top border
1540
1555
borderBottom : this . props . isLast ? 'none' : '1px solid #d6d6d6' ,
@@ -1626,7 +1641,11 @@ class Explorer extends React.PureComponent<Props, State> {
1626
1641
getDefaultScalarArgValue : defaultGetDefaultScalarArgValue ,
1627
1642
} ;
1628
1643
1629
- state = { newOperationType : 'query' , operation : null } ;
1644
+ state = {
1645
+ newOperationType : 'query' ,
1646
+ operation : null ,
1647
+ operationToScrollTo : null ,
1648
+ } ;
1630
1649
1631
1650
_ref : ?any ;
1632
1651
_resetScroll = ( ) => {
@@ -1645,6 +1664,18 @@ class Explorer extends React.PureComponent<Props, State> {
1645
1664
this . setState ( { newOperationType : value } ) ;
1646
1665
} ;
1647
1666
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
+
1648
1679
render ( ) {
1649
1680
const { schema , query , makeDefaultArg } = this . props ;
1650
1681
@@ -1795,35 +1826,40 @@ class Explorer extends React.PureComponent<Props, State> {
1795
1826
definitions : newDefinitions ,
1796
1827
} ;
1797
1828
1829
+ this . setState ( { operationToScrollTo : `${ kind } -${ newOperationName } ` } ) ;
1830
+
1798
1831
this . props . onEdit ( print ( newOperationDef ) ) ;
1799
1832
} ;
1800
1833
1801
1834
const actionsOptions = [
1802
1835
! ! queryFields ? (
1803
1836
< option
1837
+ key = "query"
1804
1838
className = { 'toolbar-button' }
1805
1839
style = { styleConfig . styles . buttonStyle }
1806
1840
type = "link"
1807
1841
value = { ( 'query' : NewOperationType ) } >
1808
- New Query
1842
+ Query
1809
1843
</ option >
1810
1844
) : null ,
1811
1845
! ! mutationFields ? (
1812
1846
< option
1847
+ key = "mutation"
1813
1848
className = { 'toolbar-button' }
1814
1849
style = { styleConfig . styles . buttonStyle }
1815
1850
type = "link"
1816
1851
value = { ( 'mutation' : NewOperationType ) } >
1817
- New Mutation
1852
+ Mutation
1818
1853
</ option >
1819
1854
) : null ,
1820
1855
! ! subscriptionFields ? (
1821
1856
< option
1857
+ key = "subscription"
1822
1858
className = { 'toolbar-button' }
1823
1859
style = { styleConfig . styles . buttonStyle }
1824
1860
type = "link"
1825
1861
value = { ( 'subscription' : NewOperationType ) } >
1826
- New Subscription
1862
+ Subscription
1827
1863
</ option >
1828
1864
) : null ,
1829
1865
] . filter ( Boolean ) ;
@@ -1846,6 +1882,14 @@ class Explorer extends React.PureComponent<Props, State> {
1846
1882
borderTop : '1px solid rgb(214, 214, 214)' ,
1847
1883
} }
1848
1884
onSubmit = { event => event . preventDefault ( ) } >
1885
+ < span
1886
+ style = { {
1887
+ display : 'inline-block' ,
1888
+ flexGrow : '0' ,
1889
+ textAlign : 'right' ,
1890
+ } } >
1891
+ Add new{ ' ' }
1892
+ </ span >
1849
1893
< select
1850
1894
onChange = { event => this . _setAddOperationType ( event . target . value ) }
1851
1895
value = { this . state . newOperationType }
@@ -1950,6 +1994,7 @@ class Explorer extends React.PureComponent<Props, State> {
1950
1994
definition = { operation }
1951
1995
onOperationRename = { onOperationRename }
1952
1996
onTypeName = { fragmentTypeName }
1997
+ onMount = { this . _handleRootViewMount }
1953
1998
onEdit = { newDefinition => {
1954
1999
const newQuery = {
1955
2000
...parsedQuery ,
0 commit comments