go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/web/rpcexplorer/src/views/methods_list.tsx (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import { Link as RouterLink, useParams } from 'react-router-dom'; 16 17 import Alert from '@mui/material/Alert'; 18 import Stack from '@mui/material/Stack'; 19 import List from '@mui/material/List'; 20 import ListItem from '@mui/material/ListItem'; 21 import ListItemButton from '@mui/material/ListItemButton'; 22 import ListItemIcon from '@mui/material/ListItemIcon'; 23 import ListItemText from '@mui/material/ListItemText'; 24 25 import { Doc } from '../components/doc'; 26 import { MethodIcon } from '../components/icons'; 27 import { useGlobals } from '../context/globals'; 28 29 30 const MethodsList = () => { 31 const { serviceName } = useParams(); 32 const { descriptors } = useGlobals(); 33 34 const svc = descriptors.service(serviceName ?? 'unknown'); 35 if (svc === undefined) { 36 return ( 37 <Alert severity='error'> 38 Service <b>{serviceName ?? 'unknown'}</b> is not 39 registered in the server. 40 </Alert> 41 ); 42 } 43 44 return ( 45 <Stack> 46 <Doc markdown={svc.doc} /> 47 <List dense> 48 {svc.methods.map((method) => { 49 return ( 50 <ListItem key={method.name} disablePadding divider> 51 <ListItemButton component={RouterLink} to={method.name}> 52 <ListItemIcon sx={{ minWidth: '40px' }}> 53 <MethodIcon /> 54 </ListItemIcon> 55 <ListItemText primary={method.name} secondary={method.help} /> 56 </ListItemButton> 57 </ListItem> 58 ); 59 })} 60 </List> 61 </Stack> 62 ); 63 }; 64 65 66 export default MethodsList;