Skip to content

Commit a91bbc4

Browse files
authored
feat: migrate components in collections (#3530)
* use common component * update components * update style * fix far items * add drawer to parent component * fix style * fix styling * fix conflicts * localize strings * use tokens * increase default drawer size * remove multiple imports * fix message bars * update url styles
1 parent 1d7ec4b commit a91bbc4

File tree

11 files changed

+476
-323
lines changed

11 files changed

+476
-323
lines changed

src/app/views/common/popups/PanelWrapper.tsx renamed to src/app/views/common/popups/DrawerWrapper.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as React from 'react';
21
import { Suspense } from 'react';
32
import {
43
Drawer,
@@ -7,17 +6,28 @@ import {
76
DrawerHeader,
87
DrawerHeaderTitle,
98
Button,
10-
Spinner
9+
Spinner,
10+
makeStyles
1111
} from '@fluentui/react-components';
1212
import { ArrowLeft24Regular, Dismiss24Regular } from '@fluentui/react-icons';
1313

1414
import { translateMessage } from '../../../utils/translate-messages';
1515
import { WrapperProps } from './popups.types';
1616

17+
const useDrawerStyles = makeStyles({
18+
root: {
19+
width: '1100px'
20+
},
21+
button: {
22+
marginInlineEnd: '20px'
23+
}
24+
});
25+
1726

1827
export function DrawerWrapper(props: WrapperProps) {
1928
const { isOpen, dismissPopup, Component, popupsProps, closePopup } = props;
2029
const { title, renderFooter, width } = popupsProps.settings;
30+
const drawerStyles = useDrawerStyles();
2131

2232
const getDrawerSize = () => {
2333
switch (width) {
@@ -52,16 +62,9 @@ export function DrawerWrapper(props: WrapperProps) {
5262
position='end'
5363
type='overlay'
5464
size={getDrawerSize()}
65+
className={drawerStyles.root}
5566
>
5667
<DrawerHeader>
57-
{showBackButton && (
58-
<Button
59-
icon={<ArrowLeft24Regular />}
60-
appearance='subtle'
61-
onClick={() => dismissPopup()}
62-
aria-label={translateMessage('Back')}
63-
/>
64-
)}
6568
<DrawerHeaderTitle action={
6669
<Button
6770
icon={<Dismiss24Regular />}
@@ -71,6 +74,15 @@ export function DrawerWrapper(props: WrapperProps) {
7174
/>
7275

7376
}>
77+
{showBackButton && (
78+
<Button
79+
icon={<ArrowLeft24Regular />}
80+
appearance='subtle'
81+
onClick={() => dismissPopup()}
82+
aria-label={translateMessage('Back')}
83+
className={drawerStyles.button}
84+
/>
85+
)}
7486
{title || ''}
7587
</DrawerHeaderTitle>
7688
</DrawerHeader>

src/app/views/common/popups/PopupsWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import ErrorBoundary from '../error-boundary/ErrorBoundary';
66
import { DialogWrapper } from './DialogWrapper';
77
import { ModalWrapper } from './ModalWrapper';
8-
import { DrawerWrapper } from './PanelWrapper';
8+
import { DrawerWrapper } from './DrawerWrapper';
99

1010
const PopupWrapper = () => {
1111

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ const UnstyledResourceExplorer = (props: any) => {
118118
previewCollection({
119119
settings: {
120120
title: translateMessage('My API collection'),
121-
width: 'xl'
121+
width: 'lg'
122122
}
123123
})
124124
}

src/app/views/sidebar/resource-explorer/collection/APICollection.tsx

Lines changed: 82 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import {
2-
CommandBar,
3-
DefaultButton,
2+
Label,
3+
Toolbar,
4+
ToolbarButton,
5+
ToolbarGroup,
46
Dialog,
5-
DialogFooter, DialogType, ICommandBarItemProps,
6-
Label, MessageBarType, PrimaryButton
7-
} from '@fluentui/react';
8-
7+
DialogActions,
8+
DialogBody,
9+
DialogContent,
10+
DialogSurface,
11+
DialogTitle,
12+
Button
13+
} from '@fluentui/react-components';
14+
import { Delete20Regular, Key20Regular, ArrowUpload20Regular, List20Regular } from '@fluentui/react-icons';
915
import { useAppDispatch, useAppSelector } from '../../../../../store';
1016
import { componentNames, eventTypes, telemetry } from '../../../../../telemetry';
1117
import { PopupsComponent } from '../../../../services/context/popups-context';
@@ -19,6 +25,7 @@ import { useEffect, useState } from 'react';
1925
import { ResourcePath } from '../../../../../types/resources';
2026
import { setQueryResponseStatus } from '../../../../services/slices/query-status.slice';
2127
import { isGeneratedCollectionInCollection } from './upload-collection.util';
28+
import CommonCollectionsPanel from './CommonCollectionsPanel';
2229

2330
export interface APICollection {
2431
version: string;
@@ -64,7 +71,6 @@ const APICollection: React.FC<PopupsComponent<APICollection>> = (props) => {
6471
trackDownload(filename, componentNames.DOWNLOAD_POSTMAN_COLLECTION_BUTTON);
6572
}
6673

67-
6874
const handleFileSelect = (event: any) => {
6975
const file = event.target.files[0];
7076
if (file) {
@@ -155,7 +161,7 @@ const APICollection: React.FC<PopupsComponent<APICollection>> = (props) => {
155161
showPopup({
156162
settings: {
157163
title: translateMessage('Edit Collection'),
158-
width: 'xl'
164+
width: 'lg'
159165
}
160166
});
161167
};
@@ -164,57 +170,82 @@ const APICollection: React.FC<PopupsComponent<APICollection>> = (props) => {
164170
showEditScopePanel({
165171
settings: {
166172
title: translateMessage('Edit Scope'),
167-
width: 'xl'
173+
width: 'lg'
168174
}
169175
});
170176
};
171177

172-
const options: ICommandBarItemProps[] = [
178+
const options = [
173179
{
174180
key: 'remove',
175181
text: translateMessage('Edit collection'),
176-
iconProps: { iconName: 'Delete' },
182+
icon: <Delete20Regular />,
177183
disabled: items.length === 0,
178184
onClick: openEditCollectionPanel
179185
},
180186
{
181187
key: 'set-scope',
182188
text: translateMessage('Edit scope'),
183-
iconProps: { iconName: 'Permissions' },
189+
icon: <Key20Regular />,
184190
disabled: items.length === 0,
185191
onClick: openEditScopePanel
186192
},
187193
{
188194
key: 'upload',
189195
text: translateMessage('Upload a new list'),
190-
iconProps: { iconName: 'Upload' },
196+
icon: <ArrowUpload20Regular />,
191197
onClick: () => document.getElementById('file-input')?.click()
192198
}
193199
];
194200

195-
const farItems: ICommandBarItemProps[] = [
201+
const farItems = [
196202
{
197203
key: 'preview-permissions',
198204
text: translateMessage('Preview permissions'),
199-
iconProps: { iconName: 'ListMirrored' },
205+
icon: <List20Regular />,
200206
disabled: items.length === 0,
201207
onClick: () => viewPermissions({
202208
settings: {
203209
title: translateMessage('Preview Permissions'),
204-
width: 'xl'
210+
width: 'lg'
205211
}
206212
})}
207213
];
208214

209215
return (
210-
<>
211-
<CommandBar
212-
items={options}
213-
ariaLabel='Selection actions'
214-
primaryGroupAriaLabel='Selection actions'
215-
farItemsGroupAriaLabel='More selection actions'
216-
farItems={farItems}
217-
/>
216+
<CommonCollectionsPanel
217+
primaryButtonText='Download postman collection'
218+
primaryButtonAction={generateCollection}
219+
primaryButtonDisabled={items.length === 0}
220+
closePopup={props.dismissPopup}
221+
>
222+
<Toolbar aria-label='Selection actions' style={{ justifyContent: 'space-between' }}>
223+
<ToolbarGroup>
224+
{options.map(option => (
225+
<ToolbarButton
226+
key={option.key}
227+
icon={option.icon}
228+
disabled={option.disabled}
229+
onClick={option.onClick}
230+
style={{ marginInlineEnd: '30px' }}
231+
>
232+
{option.text}
233+
</ToolbarButton>
234+
))}
235+
</ToolbarGroup>
236+
<ToolbarGroup>
237+
{farItems.map(item => (
238+
<ToolbarButton
239+
key={item.key}
240+
icon={item.icon}
241+
disabled={item.disabled}
242+
onClick={item.onClick}
243+
>
244+
{item.text}
245+
</ToolbarButton>
246+
))}
247+
</ToolbarGroup>
248+
</Toolbar>
218249

219250
<input
220251
key={fileInputKey}
@@ -224,57 +255,45 @@ const APICollection: React.FC<PopupsComponent<APICollection>> = (props) => {
224255
onChange={handleFileSelect}
225256
/>
226257

227-
{!isDialogHidden && (
228-
<Dialog
229-
hidden={isDialogHidden}
230-
onDismiss={() => setIsDialogHidden(true)}
231-
dialogContentProps={{
232-
type: DialogType.normal,
233-
title: translateMessage('Upload collection'),
234-
closeButtonAriaLabel: 'Close',
235-
subText: translateMessage('You have an existing collection. Would you like to merge or replace it?')
236-
}}
237-
>
238-
<DialogFooter>
239-
<PrimaryButton onClick={mergeWithExistingCollection} text={translateMessage('Merge with existing')} />
240-
<DefaultButton onClick={overwriteCollection} text={translateMessage('Replace existing')} />
241-
</DialogFooter>
242-
</Dialog>
243-
)}
244-
245258
{items && items.length > 0 ?
246-
(<div style={{ height: '80vh' }}>
259+
(<div>
247260
<Paths
248261
resources={items}
249262
columns={columns}
250263
/>
251264
</div>
252265
) :
253266
(
254-
<Label
255-
style={{ display: 'flex', width: '100%',
256-
height: '80vh',
257-
justifyContent: 'center',
258-
alignItems: 'center' }}>
267+
<Label style={{
268+
height: '80vh',
269+
display: 'flex',
270+
width: '100%',
271+
justifyContent: 'center',
272+
alignItems: 'center'
273+
}}>
259274
{translateMessage('Add queries in the API Explorer and History tab')}
260275
</Label>
261276
)}
262-
<DialogFooter
263-
styles={{
264-
actionsRight: { bottom: 0, justifyContent: 'start' }
265-
}}>
266-
<PrimaryButton onClick={generateCollection} disabled={items.length === 0}>
267-
{translateMessage('Download postman collection')}
268-
</PrimaryButton>
269277

270-
<DefaultButton
271-
onClick={
272-
() => props.closePopup()
273-
}>
274-
{translateMessage('Close')}
275-
</DefaultButton>
276-
</DialogFooter>
277-
</>
278+
<Dialog open={!isDialogHidden} onOpenChange={toggleIsDialogHidden}>
279+
<DialogSurface>
280+
<DialogBody>
281+
<DialogTitle>{translateMessage('Upload collection')}</DialogTitle>
282+
<DialogContent>
283+
{translateMessage('You have an existing collection. Would you like to merge or replace it?')}
284+
</DialogContent>
285+
<DialogActions>
286+
<Button appearance="primary" onClick={mergeWithExistingCollection}>
287+
{translateMessage('Merge with existing')}
288+
</Button>
289+
<Button onClick={overwriteCollection}>
290+
{translateMessage('Replace existing')}
291+
</Button>
292+
</DialogActions>
293+
</DialogBody>
294+
</DialogSurface>
295+
</Dialog>
296+
</CommonCollectionsPanel>
278297
)
279298
}
280299

src/app/views/sidebar/resource-explorer/collection/Collection.styles.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)