@@ -40,21 +40,58 @@ export default class EndpointSelection extends React.Component<Props, State> {
4040 } ;
4141 }
4242
43+ // TODO consider moving this to an isMiskEndpoint boolean on the metadata from the server
44+ private isMiskEndpoint ( route : MiskRoute ) : boolean {
45+ const routes = [
46+ '/' ,
47+ '/_liveness' ,
48+ '/_readiness' ,
49+ '/_status' ,
50+ '/api/{id}/metadata' ,
51+ '/api/v1/database/query/metadata' ,
52+ '/api/service/metadata' ,
53+ '/{path:.*}' ,
54+ ] ;
55+ const routePrefixes = [
56+ '/_admin' ,
57+ '/v2/_admin' ,
58+ '/_tab' ,
59+ '/api/dashboard/' ,
60+ '/@misk' ,
61+ '/static' ,
62+ ] ;
63+ return (
64+ routes . includes ( route . path ) ||
65+ routePrefixes . some ( ( prefix ) => route . path . startsWith ( prefix ) )
66+ ) ;
67+ }
68+
4369 componentDidMount ( ) {
4470 this . metadataClient . fetchMetadata ( ) . then ( ( actions : MiskRoute [ ] ) => {
45- this . options = actions
46- . map ( ( actionGroup ) => ( {
47- label : `${ actionGroup . httpMethod } ${ actionGroup . path } (${ actionGroup . actionName } )` ,
48- termsString :
49- `${ actionGroup . httpMethod } ${ actionGroup . path } ${ actionGroup . actionName } ` . toLowerCase ( ) ,
50- value : actionGroup ,
51- } ) )
71+ const appEndpoints = actions
72+ . filter ( ( action ) => ! this . isMiskEndpoint ( action ) )
5273 . sort ( ( a , b ) => {
5374 // Sort by path first, then by HTTP method
54- const pathCompare = a . value . path . localeCompare ( b . value . path ) ;
75+ const pathCompare = a . path . localeCompare ( b . path ) ;
5576 if ( pathCompare !== 0 ) return pathCompare ;
56- return a . value . httpMethod . localeCompare ( b . value . httpMethod ) ;
77+ return a . httpMethod . localeCompare ( b . httpMethod ) ;
5778 } ) ;
79+ const miskEndpoints = actions
80+ . filter ( ( action ) => this . isMiskEndpoint ( action ) )
81+ . sort ( ( a , b ) => {
82+ // Sort by path first, then by HTTP method
83+ const pathCompare = a . path . localeCompare ( b . path ) ;
84+ if ( pathCompare !== 0 ) return pathCompare ;
85+ return a . httpMethod . localeCompare ( b . httpMethod ) ;
86+ } ) ;
87+
88+ // Combine app and Misk endpoints, ensuring Misk endpoints are always after app endpoints for less scrolling
89+ this . options = [ ...appEndpoints , ...miskEndpoints ] . map ( ( actionGroup ) => ( {
90+ label : `${ actionGroup . httpMethod } ${ actionGroup . path } (${ actionGroup . actionName } )` ,
91+ termsString :
92+ `${ actionGroup . httpMethod } ${ actionGroup . path } ${ actionGroup . actionName } ` . toLowerCase ( ) ,
93+ value : actionGroup ,
94+ } ) ) ;
5895
5996 this . setState ( { filteredOptions : this . options } ) ;
6097 this . focusSelect ( ) ;
0 commit comments