Skip to content

Commit 27aa2ca

Browse files
authored
feat: update component designs (#3609)
* update sample queries design * update history design * fix badge style
1 parent 5e1cc14 commit 27aa2ca

File tree

4 files changed

+60
-95
lines changed

4 files changed

+60
-95
lines changed

src/app/views/sidebar/history/History.tsx

Lines changed: 37 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -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

286305
const 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/>}

src/app/views/sidebar/resource-explorer/ResourceLink.tsx

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tooltip, Button, Badge } from '@fluentui/react-components'
1+
import { Tooltip, Button, Badge, Link } from '@fluentui/react-components'
22
import { SubtractSquare20Regular, AddSquare20Regular, DocumentText20Regular } from '@fluentui/react-icons';
33
import { useEffect } from 'react';
44

@@ -138,24 +138,20 @@ const ResourceLinkActions = ({
138138
relationship='label'
139139
>
140140
{resourceLink.docLink ? (
141-
<Button
141+
<Link
142142
aria-label={translateMessage('Read documentation')}
143-
id='documentButton'
144-
aria-disabled={!resourceLink.docLink}
145-
className={iconButtonStyles.root}
146-
icon={<DocumentText20Regular />}
147-
appearance='transparent'
148-
onClick={() => openDocumentationLink()}
149-
/> ) :
150-
<Button
143+
appearance='subtle'
144+
className={iconButtonStyles.linkIcon}
145+
target='_blank' href={resourceLink.docLink}
146+
onClick={() => openDocumentationLink()}>
147+
<DocumentText20Regular /></Link>) :
148+
<Link
151149
disabled
152150
aria-label={translateMessage('Read documentation')}
153-
id='documentButton'
151+
appearance='subtle'
154152
aria-disabled
155-
appearance='transparent'
156-
className={iconButtonStyles.root}
157-
icon={<DocumentText20Regular />}
158-
/>}
153+
className={iconButtonStyles.linkIcon}>
154+
<DocumentText20Regular /></Link>}
159155
</Tooltip>
160156
)}
161157
{resourceLink.isInCollection ? (

src/app/views/sidebar/resource-explorer/resourceLinkStyles.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ export const useStyles = makeStyles({
3333
visibility: 'hidden',
3434
display: 'flex',
3535
alignItems: 'center'
36+
},
37+
linkIcon: {
38+
display: 'flex',
39+
'&:hover': {
40+
color: tokens.colorBrandForegroundLinkHover
41+
}
3642
}
3743
});
3844

src/app/views/sidebar/sample-queries/SampleQueriesV9.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ const useStyles = makeStyles({
6060
maxWidth: '100%'
6161
},
6262
iconBefore: {
63-
width: '74px',
64-
maxWidth: '74px',
6563
display: 'flex',
6664
flexDirection: 'row',
6765
alignItems: 'center',
6866
gap: '2px'
6967
},
7068
badge: {
71-
width: '58px',
72-
maxWidth: '58px'
69+
maxWidth: '50px'
7370
},
7471
disabled: {
7572
backgroundColor: tokens.colorSubtleBackgroundHover,
7673
'&:hover': {
7774
cursor: 'not-allowed'
7875
}
76+
},
77+
itemLayout: {
78+
paddingLeft: tokens.spacingHorizontalXXL
7979
}
8080
});
8181

@@ -246,6 +246,7 @@ const RenderSampleLeafs = (props: SampleLeaf) => {
246246
id={query.id}
247247
>
248248
<TreeItemLayout
249+
className={leafStyles.itemLayout}
249250
onClick={()=>handleOnClick(query)}
250251
iconBefore={<MethodIcon isSignedIn={isSignedIn} method={query.method} />}
251252
aside={<ResourceLink item={query}/>}
@@ -307,8 +308,7 @@ const MethodIcon = ({ method, isSignedIn }: { method: string, isSignedIn: boolea
307308
<div className={sampleQueriesStyles.iconBefore}>
308309
<Badge
309310
className={sampleQueriesStyles.badge}
310-
appearance="filled"
311-
size='small'
311+
size='medium'
312312
color={colors[method]}
313313
aria-label={'http method ' + method + ' for'}>
314314
{method}

0 commit comments

Comments
 (0)