@@ -89,6 +89,7 @@ const useStyles = makeStyles({
8989 } ,
9090 titleAside : {
9191 display : 'flex' ,
92+ alignItems : 'center' ,
9293 gap : '2px'
9394 }
9495} )
@@ -117,7 +118,7 @@ interface AsideGroupIconsProps {
117118 historyItems : IHistoryItem [ ]
118119}
119120
120- const AsideGroupIcons = ( props : AsideGroupIconsProps ) => {
121+ const GroupIcons = ( props : AsideGroupIconsProps ) => {
121122 const dispatch = useAppDispatch ( )
122123 const { groupName, historyItems} = props
123124 const [ open , setOpen ] = useState ( false ) ;
@@ -136,6 +137,7 @@ const AsideGroupIcons = (props: AsideGroupIconsProps)=>{
136137 }
137138
138139 return < div className = { styles . titleAside } >
140+ < Text weight = 'semibold' > { groupName } { ' ' } </ Text >
139141 < Tooltip withArrow relationship = "label" content = { `${ translateMessage ( 'Export' ) } ${ groupName } queries` } >
140142 < Button onClick = {
141143 ( e ) => handleDownloadHistoryGroup ( e , groupName , historyItems ) }
@@ -206,7 +208,6 @@ const HistoryItems = (props: HistoryProps)=>{
206208 body : query . result ,
207209 headers : query . responseHeaders
208210 } ) )
209- // TODO: change the message bar type to v9 types
210211 dispatch ( setQueryResponseStatus ( {
211212 duration,
212213 messageBarType : status < 300 ? 'success' : 'error' ,
@@ -236,11 +237,11 @@ const HistoryItems = (props: HistoryProps)=>{
236237 aria-setsize = { 2 }
237238 aria-posinset = { pos + 1 }
238239 aria-label = { ariaLabel } >
239- < TreeItemLayout aside = { < AsideGroupIcons groupName = { name } historyItems = { history } /> } >
240- < Text weight = 'semibold' > { name } { ' ' }
241- < Badge appearance = 'tint' color = 'informative' aria-label = { count + translateMessage ( 'History' ) } >
242- { count }
243- </ Badge > </ Text >
240+ < TreeItemLayout aside = {
241+ < Badge appearance = 'tint' color = 'informative' aria-label = { count + translateMessage ( 'History' ) } >
242+ { count }
243+ </ Badge > } >
244+ < GroupIcons groupName = { name } historyItems = { history } / >
244245 </ TreeItemLayout >
245246 </ FlatTreeItem >
246247 { openItems . has ( name ) &&
@@ -257,7 +258,7 @@ const HistoryItems = (props: HistoryProps)=>{
257258 >
258259 < TreeItemLayout
259260 onClick = { ( ) => handleViewQuery ( h ) }
260- iconBefore = { < HistoryStatusCodes status = { h . status } /> }
261+ iconBefore = { < HistoryStatusCodes status = { h . status } method = { h . method } /> }
261262 aside = { < HistoryItemActionMenu item = { h } /> } >
262263 < Tooltip content = { `${ h . method } - ${ h . url } ` } relationship = 'description' withArrow >
263264 < Text > { h . url . replace ( GRAPH_URL , '' ) } </ Text >
@@ -272,16 +273,34 @@ const HistoryItems = (props: HistoryProps)=>{
272273 )
273274}
274275
275- const HistoryStatusCodes = ( { status} :{ status : number } ) => {
276- const getBadgeColor = ( ) : BadgeColors => {
277- if ( status >= 100 && status < 199 ) { return 'informative' }
278- if ( status >= 200 && status < 299 ) { return 'success' }
279- if ( status >= 300 && status < 399 ) { return 'important' }
280- if ( status >= 400 && status < 599 ) { return 'danger' }
281- return 'success'
282- }
283- return < Badge color = { getBadgeColor ( ) } appearance = "ghost" > { status } </ Badge >
284- }
276+ const HistoryStatusCodes = ( { status, method } : { status : number , method ?: string } ) => {
277+ const getBadgeColor = ( ) : BadgeColors => {
278+ if ( status >= 100 && status < 199 ) { return 'informative' }
279+ if ( status >= 200 && status < 299 ) { return 'success' }
280+ if ( status >= 300 && status < 399 ) { return 'important' }
281+ if ( status >= 400 && status < 599 ) { return 'danger' }
282+ return 'success' ;
283+ } ;
284+
285+ const methodColors : Record < string , BadgeColors > = {
286+ GET : 'brand' ,
287+ POST : 'success' ,
288+ PATCH : 'severe' ,
289+ DELETE : 'danger' ,
290+ PUT : 'warning'
291+ } ;
292+
293+ return (
294+ < div style = { { display : 'flex' , gap : '4px' } } >
295+ { method && (
296+ < Badge color = { methodColors [ method ] || 'informative' } >
297+ { method }
298+ </ Badge >
299+ ) }
300+ < Badge color = { getBadgeColor ( ) } appearance = "ghost" > { status } </ Badge >
301+ </ div >
302+ ) ;
303+ } ;
285304
286305const trackHistoryItemEvent = ( eventName : string , componentName : string , query : IHistoryItem ) => {
287306 const sanitizedUrl = sanitizeQueryUrl ( query . url ) ;
@@ -303,59 +322,6 @@ const HistoryItemActionMenu = (props: HistoryItemActionMenuProps)=>{
303322 const dispatch = useAppDispatch ( )
304323 const { item} = props
305324
306- const handleViewQuery = ( query : IHistoryItem ) => {
307- const { sampleUrl, queryVersion } = parseSampleUrl ( query . url ) ;
308- const sampleQuery : IQuery = {
309- sampleUrl,
310- selectedVerb : query . method ,
311- sampleBody : query . body ,
312- sampleHeaders : query . headers ,
313- selectedVersion : queryVersion
314- } ;
315- const { duration, status, statusText } = query ;
316- dispatch ( setSampleQuery ( sampleQuery ) ) ;
317- dispatch ( setQueryResponse ( {
318- body : query . result ,
319- headers : query . responseHeaders
320- } ) )
321- // TODO: change the message bar type to v9 types
322- dispatch ( setQueryResponseStatus ( {
323- duration,
324- messageBarType : status < 300 ? 'success' : 'error' ,
325- ok : status < 300 ,
326- status,
327- statusText
328- } ) ) ;
329- trackHistoryItemEvent (
330- eventTypes . LISTITEM_CLICK_EVENT ,
331- componentNames . HISTORY_LIST_ITEM ,
332- query
333- ) ;
334- }
335-
336- const handleRunQuery = ( query : IHistoryItem ) => {
337- const { sampleUrl, queryVersion } = parseSampleUrl ( query . url ) ;
338- const sampleQuery : IQuery = {
339- sampleUrl,
340- selectedVerb : query . method ,
341- sampleBody : query . body ,
342- sampleHeaders : query . headers ,
343- selectedVersion : queryVersion
344- } ;
345-
346- if ( sampleQuery . selectedVerb === 'GET' ) {
347- sampleQuery . sampleBody = JSON . parse ( '{}' ) as string ;
348- }
349- dispatch ( setSampleQuery ( sampleQuery ) ) ;
350- dispatch ( runQuery ( sampleQuery ) ) ;
351-
352- trackHistoryItemEvent (
353- eventTypes . BUTTON_CLICK_EVENT ,
354- componentNames . RUN_HISTORY_ITEM_BUTTON ,
355- query
356- ) ;
357- }
358-
359325 const handleExportQuery = ( query : IHistoryItem ) => {
360326 const harPayload = createHarEntry ( query ) ;
361327 const generatedHarData = generateHar ( [ harPayload ] ) ;
@@ -386,9 +352,6 @@ const HistoryItemActionMenu = (props: HistoryItemActionMenuProps)=>{
386352 < MenuList >
387353 < MenuGroup >
388354 < MenuGroupHeader > { translateMessage ( 'actions' ) } </ MenuGroupHeader >
389- < MenuItem icon = { < EyeRegular /> } onClick = { ( ) => handleViewQuery ( item ) } > { translateMessage ( 'view' ) } </ MenuItem >
390- < MenuItem icon = { < ArrowRepeatAllRegular /> }
391- onClick = { ( ) => handleRunQuery ( item ) } > { translateMessage ( 'Run Query' ) } </ MenuItem >
392355 < MenuItem icon = { < ArrowDownloadRegular /> }
393356 onClick = { ( ) => handleExportQuery ( item ) } > { translateMessage ( 'Export' ) } </ MenuItem >
394357 < MenuItem icon = { < DeleteRegular /> }
0 commit comments