forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bulk-import): allow user to select repositories from side panel
Signed-off-by: Yi Cai <yicai@redhat.com>
- Loading branch information
Showing
12 changed files
with
862 additions
and
84 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
plugins/bulk-import/src/components/AddRepositories/AddRepositoriesDrawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { Link } from '@backstage/core-components'; | ||
|
||
import { | ||
Button, | ||
Card, | ||
Container, | ||
Drawer, | ||
IconButton, | ||
makeStyles, | ||
Typography, | ||
} from '@material-ui/core'; | ||
import CloseIcon from '@material-ui/icons/Close'; | ||
import OpenInNewIcon from '@mui/icons-material/OpenInNew'; | ||
|
||
import { AddRepositoriesData, AddRepositoriesFormValues } from '../../types'; | ||
import { filterSelectedForActiveDrawer } from '../../utils/repository-utils'; | ||
import { AddRepositoriesTableToolbar } from './AddRepositoriesTableToolbar'; | ||
import { OrganizationRepositoriesTable } from './OrganizationRepositoriesTable'; | ||
|
||
type AddRepositoriesDrawerProps = { | ||
open: boolean; | ||
onClose: () => void; | ||
onSelect: (ids: number[]) => void; | ||
title: string; | ||
data: AddRepositoriesData; | ||
selectedRepositoriesFormData: AddRepositoriesFormValues; | ||
checkedRepos: number[]; | ||
}; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
createButton: { | ||
marginRight: theme.spacing(1), | ||
}, | ||
sidePanelfooter: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'right', | ||
marginTop: theme.spacing(2), | ||
position: 'fixed', | ||
bottom: '20px', | ||
}, | ||
})); | ||
|
||
export const AddRepositoriesDrawer = ({ | ||
open, | ||
onClose, | ||
onSelect, | ||
title, | ||
data, | ||
selectedRepositoriesFormData, | ||
checkedRepos, | ||
}: AddRepositoriesDrawerProps) => { | ||
const classes = useStyles(); | ||
const [searchString, setSearchString] = useState<string>(''); | ||
|
||
const [selectedReposID, setSelectedReposID] = | ||
useState<number[]>(checkedRepos); | ||
|
||
const handleCallback = (ids: number[]) => { | ||
setSelectedReposID(ids); | ||
}; | ||
|
||
const handleSelecRepoFromDrawer = (selected: number[]) => { | ||
onSelect(selected); | ||
onClose(); | ||
}; | ||
|
||
const selectedForActiveDrawer = React.useMemo( | ||
() => filterSelectedForActiveDrawer(data, selectedReposID), | ||
[data?.repositories, selectedReposID], | ||
); | ||
|
||
return ( | ||
<Drawer anchor="right" open={open}> | ||
<Container | ||
style={{ | ||
padding: '20px', | ||
height: '100%', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
}} | ||
> | ||
<div style={{ display: 'flex', justifyContent: 'space-between' }}> | ||
<div> | ||
<Typography variant="h5">{data?.name}</Typography> | ||
<Link to={data?.url}> | ||
{data?.url} | ||
<OpenInNewIcon | ||
style={{ verticalAlign: 'sub', paddingTop: '7px' }} | ||
/> | ||
</Link> | ||
</div> | ||
<div> | ||
<IconButton onClick={onClose} className="align-right"> | ||
<CloseIcon /> | ||
</IconButton> | ||
</div> | ||
</div> | ||
<Card style={{ marginTop: '20px', marginBottom: '60px' }}> | ||
<AddRepositoriesTableToolbar | ||
title={title} | ||
setSearchString={setSearchString} | ||
selectedReposFromDrawer={selectedReposID} | ||
selectedRepositoriesFormData={selectedRepositoriesFormData} | ||
activeOrganization={data} | ||
/> | ||
<OrganizationRepositoriesTable | ||
searchString={searchString} | ||
activeOrganization={data} | ||
selectedRepos={selectedReposID} | ||
updateSelectedRepos={handleCallback} | ||
/> | ||
</Card> | ||
<div className={classes.sidePanelfooter}> | ||
<span> | ||
<Button | ||
variant="contained" | ||
color="primary" | ||
onClick={() => handleSelecRepoFromDrawer(selectedReposID)} | ||
className={classes.createButton} | ||
disabled={selectedForActiveDrawer.length === 0} | ||
aria-labelledby="select-from-drawer" | ||
> | ||
Select | ||
</Button> | ||
</span> | ||
<span> | ||
<Button | ||
aria-labelledby="cancel-drawer-select" | ||
variant="outlined" | ||
onClick={onClose} | ||
> | ||
Cancel | ||
</Button> | ||
</span> | ||
</div> | ||
</Container> | ||
</Drawer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.