-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app overview): implemented add roles (#225)
- Loading branch information
1 parent
1bb4fff
commit 939e259
Showing
11 changed files
with
565 additions
and
11 deletions.
There are no files selected for viewing
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
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
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,150 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
import { PageBreadcrumb } from 'components/shared/frame/PageBreadcrumb/PageBreadcrumb' | ||
import { | ||
Typography, | ||
PageHeader, | ||
Button, | ||
LoadingButton, | ||
StaticTable, | ||
Checkbox, | ||
} from '@catena-x/portal-shared-components' | ||
import { useTranslation } from 'react-i18next' | ||
import { useLocation, useNavigate, useParams } from 'react-router-dom' | ||
import { Box } from '@mui/material' | ||
import { useEffect, useState } from 'react' | ||
import { TableType } from 'types/MainTypes' | ||
import { useFetchAppRolesQuery } from 'features/appManagement/apiSlice' | ||
import AddRolesOverlay from './AddRolesOverlay' | ||
import DeleteOutlinedIcon from '@mui/icons-material/DeleteOutlined' | ||
import { PAGES } from 'types/Constants' | ||
|
||
export default function AddRoles() { | ||
const { t } = useTranslation() | ||
const navigate = useNavigate() | ||
const appId = useParams().appId | ||
const [isLoading, setIsLoading] = useState(false) | ||
const { state } = useLocation() | ||
const items: any = state | ||
const app = items?.filter((item: any) => item.id === appId) | ||
const { data, refetch } = useFetchAppRolesQuery(appId ?? '') | ||
const [addRolesOverlayOpen, setAddRolesOverlayOpen] = useState<boolean>(false) | ||
const [appRoles, setAppRoles] = useState<any[]>([ | ||
[''], | ||
[`${(<Checkbox disabled={true} />)}`], | ||
]) | ||
|
||
useEffect(() => { | ||
refetch() | ||
}, [state]) | ||
|
||
const handleSaveClick = async () => { | ||
setIsLoading(true) | ||
} | ||
|
||
useEffect(() => { | ||
setAppRoles( | ||
data && data.length > 0 | ||
? data.map((role) => [role.role, `${(<Checkbox disabled={true} />)}`]) | ||
: [['', '']] | ||
) | ||
}, [data]) | ||
|
||
const tableData: TableType = { | ||
head: [ | ||
t('content.addRoles.establishedRoles'), | ||
`${(<DeleteOutlinedIcon />)}`, | ||
], | ||
body: appRoles, | ||
} | ||
|
||
return ( | ||
<main className="add-app-roles-main"> | ||
<PageHeader headerHeight={200} topPage={true} title={app?.[0]?.title}> | ||
<PageBreadcrumb backButtonVariant="contained" /> | ||
</PageHeader> | ||
<section> | ||
<Typography mb={3} variant="body2" align="center"> | ||
{app?.[0]?.title} | ||
</Typography> | ||
<Typography mb={3} variant="h2" align="center"> | ||
{t('content.addRoles.headerTitle')} | ||
</Typography> | ||
<Typography variant="body2" align="center"> | ||
{t('content.addRoles.description')} | ||
</Typography> | ||
</section> | ||
<AddRolesOverlay | ||
openDialog={addRolesOverlayOpen} | ||
handleOverlayClose={() => setAddRolesOverlayOpen(false)} | ||
appId={appId || ''} | ||
/> | ||
<div className="main-container"> | ||
<div className="main-row"> | ||
<Box sx={{ textAlign: 'center', mb: 8 }}> | ||
<Button | ||
size="small" | ||
sx={{ alignItems: 'center' }} | ||
onClick={() => setAddRolesOverlayOpen(true)} | ||
> | ||
{t('content.addRoles.uploadAdditionalRoles')} | ||
</Button> | ||
</Box> | ||
<StaticTable data={tableData} horizontal={false} /> | ||
</div> | ||
</div> | ||
|
||
<section> | ||
<hr style={{ border: 0, borderTop: '1px solid #DCDCDC' }} /> | ||
<Box sx={{ marginTop: '30px', position: 'relative' }}> | ||
<Button | ||
color="secondary" | ||
onClick={() => navigate(`/${PAGES.APPOVERVIEW}`)} | ||
size="small" | ||
> | ||
{t('global.actions.cancel')} | ||
</Button> | ||
|
||
<span style={{ position: 'absolute', right: '10px' }}> | ||
{isLoading ? ( | ||
<LoadingButton | ||
size="small" | ||
loadIndicator="Loading..." | ||
loading={isLoading} | ||
variant="contained" | ||
onButtonClick={() => {}} | ||
label={`${t('global.actions.confirm')}`} | ||
/> | ||
) : ( | ||
<Button | ||
disabled={true} | ||
size="small" | ||
variant="contained" | ||
onClick={handleSaveClick} | ||
> | ||
{t('global.actions.save')} | ||
</Button> | ||
)} | ||
</span> | ||
</Box> | ||
</section> | ||
</main> | ||
) | ||
} |
Oops, something went wrong.