Skip to content

Commit

Permalink
feat(app overview): implemented add roles (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
lavanya-bmw authored Aug 25, 2023
1 parent 1bb4fff commit 939e259
Show file tree
Hide file tree
Showing 11 changed files with 565 additions and 11 deletions.
18 changes: 15 additions & 3 deletions src/assets/locales/de/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@
"sortOptions": {
"deactivate": "Deactivate",
"changeImage": "Change Image",
"changeDescription": "Change Description"
"changeDescription": "Change Description",
"addRoles": "Add Roles"
},
"addbtn": "Registrieren Sie Ihre App",
"confirmModal": {
Expand Down Expand Up @@ -423,7 +424,7 @@
"headerTitle": "Change Lead Image",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .",
"uploadNewImage": "Upload New Image",
"successMsg": "successfully changed app lead image",
"successMsg": "Successfully changed app lead image",
"errorMsg": "Unable to change the lead image"
},
"changeDescription": {
Expand All @@ -435,9 +436,20 @@
"shortDescription": "Short Description",
"shortDescriptionEN": "Short Description - EN *",
"shortDescriptionDE": "Short Description - DE *",
"successMsg": "successfully changed description",
"successMsg": "Successfully changed description",
"errorMsg": "Unable to change description"
},
"addRoles": {
"headerTitle": "Load Additional Roles",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .",
"uploadAdditionalRoles": "Upload Additional Roles",
"establishedRoles": "Established Roles",
"uploadAdditionalRolesDescription": "Note: only one file for upload allowed",
"newRolesToAdd": "New roles to be added",
"confirmButtonDescription": "With clicking the confirm button, the newly added application roles will get added in the top record as well as inside all active apps clients of your app customers.",
"successMsg": "Successfully added roles",
"errorMsg": "Unable to add roles"
},
"appreleaseprocess": {
"message": "App Release Process Message"
},
Expand Down
18 changes: 15 additions & 3 deletions src/assets/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@
"sortOptions": {
"deactivate": "Deactivate",
"changeImage": "Change Image",
"changeDescription": "Change Description"
"changeDescription": "Change Description",
"addRoles": "Add Roles"
},
"addbtn": "Register your App",
"confirmModal": {
Expand Down Expand Up @@ -422,7 +423,7 @@
"headerTitle": "Change Lead Image",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .",
"uploadNewImage": "Upload New Image",
"successMsg": "successfully changed app lead image",
"successMsg": "Successfully changed app lead image",
"errorMsg": "Unable to change the lead image"
},
"changeDescription": {
Expand All @@ -434,9 +435,20 @@
"shortDescription": "Short Description",
"shortDescriptionEN": "Short Description - EN *",
"shortDescriptionDE": "Short Description - DE *",
"successMsg": "successfully changed description",
"successMsg": "Successfully changed description",
"errorMsg": "Unable to change description"
},
"addRoles": {
"headerTitle": "Load Additional Roles",
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard .",
"uploadAdditionalRoles": "Upload Additional Roles",
"establishedRoles": "Established Roles",
"uploadAdditionalRolesDescription": "Note: only one file for upload allowed",
"newRolesToAdd": "New roles to be added",
"confirmButtonDescription": "With clicking the confirm button, the newly added application roles will get added in the top record as well as inside all active apps clients of your app customers.",
"successMsg": "Successfully added roles",
"errorMsg": "Unable to add roles"
},
"appreleaseprocess": {
"message": "App Release Process Message"
},
Expand Down
150 changes: 150 additions & 0 deletions src/components/pages/AppOverview/AddRoles.tsx
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>
)
}
Loading

0 comments on commit 939e259

Please sign in to comment.