Skip to content

Commit

Permalink
Merge pull request #707 from jembi/CU-86c0qwg19_base-template-components
Browse files Browse the repository at this point in the history
creating an implementing base components
  • Loading branch information
drizzentic authored Nov 5, 2024
2 parents dcdd0eb + cb0dd32 commit 68226a5
Show file tree
Hide file tree
Showing 22 changed files with 508 additions and 598 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ npm install
To start up a development instance of the webapp run

```sh
npx lerna run start --concurrency=16
npm run dev
```

> The number passed into the --concurrency flag should be equal to the number of folders in the "./packages" directory
Expand Down
100 changes: 100 additions & 0 deletions packages/base-components/BaseDataGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import React from 'react'
import {Box, Paper} from '@mui/material'
import {
DataGrid,
GridToolbarDensitySelector,
GridToolbarFilterButton,
GridToolbarQuickFilter,
GridRowParams
} from '@mui/x-data-grid'
import ErrorIcon from '@mui/icons-material/Error'

interface BaseDataGridProps <T> {
rows: T[]
getRowId: (row: any) => any
onRowClick?: (params: GridRowParams) => void
columns: any[]
customToolbar?: React.JSXElementConstructor<any>
noRowsOverlay?: React.JSXElementConstructor<any>
}

const DefaultCustomToolbar = () => {
return (
<div style={{display: 'flex', justifyContent: 'space-between'}}>
<div>
<GridToolbarFilterButton />
<GridToolbarDensitySelector />
</div>
<GridToolbarQuickFilter variant="standard" />
</div>
)
}

const DefaultNoRowsOverlay = () => {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100%'
}}
>
<ErrorIcon fontSize="large" color="disabled" />
<Box sx={{m: 1}}>No Rows Found</Box>
</div>
)
}

export function BaseDataGrid<T>({
rows,
getRowId,
onRowClick,
columns,
customToolbar = DefaultCustomToolbar,
noRowsOverlay = DefaultNoRowsOverlay
}: BaseDataGridProps<T>) {
return (
<>
<Paper
elevation={2}
sx={{paddingX: '15px', borderRadius: '4px', paddingTop: '30px'}}
>
<DataGrid
getRowId={getRowId}
autoHeight
checkboxSelection
disableRowSelectionOnClick
sx={{
'.css-1iyq7zh-MuiDataGrid-columnHeaders': {
backgroundColor: '#f8f8f8',
borderRadius: '8px'
},
'&, [class^=MuiDataGrid]': {border: 'none'}
}}
rows={rows}
onRowClick={onRowClick}
slots={{
toolbar: customToolbar,
noRowsOverlay: noRowsOverlay
}}
columns={columns}
pageSizeOptions={[10, 25, 50]}
initialState={{
pagination: {
paginationModel: {page: 0, pageSize: 10}
}
}}
slotProps={{
toolbar: {
showQuickFilter: true,
printOptions: {disableToolbarButton: true},
csvOptions: {disableToolbarButton: true}
}
}}
/>
</Paper>
</>
)
}
81 changes: 81 additions & 0 deletions packages/base-components/BasePageTemplate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react'
import {
Box,
Grid,
Typography,
Button,
Card,
Divider,
alpha
} from '@mui/material'

interface BasePageTemplateProps {
children: React.ReactNode
title: string
subtitle: string | React.ReactNode
button?: React.ReactNode
}

export function BasePageTemplate({
children,
title,
subtitle,
button
}: BasePageTemplateProps) {
return (
<Box padding={1}>
<Grid container padding={2} spacing={2}>
<Grid item xs={12}>
<Typography
variant="h4"
gutterBottom
sx={{
width: '100%',
position: 'relative',
fontSize: '34px',
letterSpacing: '0.25px',
lineHeight: '123.5%',
fontFamily: 'Fira Sans',
color: alpha('#000', 0.87),
textAlign: 'left',
display: 'inline-block',
fontSmooth: 'never',
'-webkit-font-smoothing': 'antialiased',
'-moz-osx-font-smoothing': 'grayscale'
}}
>
{title}
</Typography>
<Grid
container
direction="row"
sx={{
justifyContent: 'space-between',
alignItems: 'center'
}}
>
<Grid item>
<Typography
variant="subtitle1"
gutterBottom
sx={{
color: alpha('#000', 0.6),
fontSmooth: 'never',
'-webkit-font-smoothing': 'antialiased',
'-moz-osx-font-smoothing': 'grayscale'
}}
>
{subtitle}
</Typography>
</Grid>
<Grid item>{button}</Grid>
</Grid>
<Divider sx={{marginTop: '10px', marginBottom: '20px'}} />
</Grid>
<Grid item xs={12}>
{children}
</Grid>
</Grid>
</Box>
)
}
4 changes: 4 additions & 0 deletions packages/base-components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {BasePageTemplate} from './BasePageTemplate'
import {BaseDataGrid} from './BaseDataGrid'

export {BasePageTemplate, BaseDataGrid}
24 changes: 6 additions & 18 deletions packages/channels-app/src/screens/add.channel.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Channel, Routes} from '../types'
import {BasicInfo} from './steps/BasicInfo'
import {RequestMatching} from './steps/RequestMatching'
import {ChannelRoutes} from './steps/routes/ChannelRoutes'
import {BasePageTemplate} from '../../../base-components'

const steps = ['Basic Info', 'Request Matching', 'Routes']

Expand Down Expand Up @@ -104,23 +105,10 @@ function AddChannelScreen() {
}

return (
<Box padding={3} sx={{backgroundColor: '#F1F1F1'}}>
<header style={{marginBottom: '24px'}}>
<Typography variant="h4" gutterBottom fontWeight={400}>
Add Channel
</Typography>
<Typography
variant="subtitle1"
fontSize={16}
gutterBottom
fontWeight={400}
>
Control client systems and their access roles. Add clients to enable
their request routing and group them by roles for streamlined channel
accesss managment.
</Typography>
</header>

<BasePageTemplate
title="Add Channel"
subtitle="Control client systems and their access roles. Add clients to enable their request routing and group them by roles for streamlined channel accesss managment."
>
<Grid
container
direction="column"
Expand Down Expand Up @@ -216,7 +204,7 @@ function AddChannelScreen() {
</Paper>
</Grid>
</Grid>
</Box>
</BasePageTemplate>
)
}

Expand Down
24 changes: 6 additions & 18 deletions packages/channels-app/src/screens/edit.channel.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {Channel, Routes} from '../types'
import {BasicInfo} from './steps/BasicInfo'
import {RequestMatching} from './steps/RequestMatching'
import {ChannelRoutes} from './steps/routes/ChannelRoutes'
import {BasePageTemplate} from '../../../base-components'

function EditChannelScreen() {
const navigate = useNavigate()
Expand Down Expand Up @@ -61,23 +62,10 @@ function EditChannelScreen() {
}

return (
<Box padding={1} sx={{backgroundColor: '#F1F1F1'}}>
<header style={{marginBottom: '24px'}}>
<Typography variant="h4" gutterBottom fontWeight={400}>
Edit Channel
</Typography>
<Typography
variant="subtitle1"
fontSize={16}
gutterBottom
fontWeight={400}
>
Control client systems and their access roles. Add clients to enable
their request routing and group them by roles for streamlined channel
accesss managment.
</Typography>
</header>

<BasePageTemplate
title="Edit Channel"
subtitle="Control client systems and their access roles. Add clients to enable their request routing and group them by roles for streamlined channel accesss managment."
>
<Grid
container
direction="column"
Expand Down Expand Up @@ -152,7 +140,7 @@ function EditChannelScreen() {
</Paper>
</Grid>
</Grid>
</Box>
</BasePageTemplate>
)
}

Expand Down
51 changes: 21 additions & 30 deletions packages/channels-app/src/screens/manage.channels.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {useBasicBackdrop} from '../contexts/backdrop.context'
import {useConfirmation} from '../contexts/confirmation.context'
import {getChannels, modifyChannel} from '../services/api'
import {Channel, ChannelStatus} from '../types'

import {BasePageTemplate} from '../../../base-components'
const useStyles = makeStyles(_theme => ({
actionsIcon: {
marginRight: '10px'
Expand Down Expand Up @@ -219,34 +219,25 @@ const ManageChannelsScreen: React.FC = () => {
}

return (
<Box padding={3} sx={{backgroundColor: '#F1F1F1'}}>
<Typography variant="h4" gutterBottom>
Manage Channels
</Typography>

<Grid container>
<Grid item xs={11}>
<Typography variant="subtitle1" gutterBottom>
Setup and control your channels.&nbsp;
<a href="">How do channels work?</a>
</Typography>
</Grid>
<Grid container justifyContent="flex-end">
<Grid item>
<Button
variant="contained"
color="primary"
startIcon={<AddIcon />}
href="/#!/channels/create-channel"
>
Add
</Button>
</Grid>
</Grid>
</Grid>

<Divider sx={{marginTop: '10px', marginBottom: '30px'}} />

<BasePageTemplate
title="Manage Channels"
subtitle={
<>
Setup and control your channels.
<a href="https://openhim.org/docs/configuration/channels">How do channels work?</a>
</>
}
button={
<Button
variant="contained"
color="primary"
startIcon={<AddIcon />}
href="/#!/channels/create-channel"
>
Add
</Button>
}
>
<Paper
elevation={4}
sx={{paddingX: '25px'}}
Expand Down Expand Up @@ -280,7 +271,7 @@ const ManageChannelsScreen: React.FC = () => {
}}
/>
</Paper>
</Box>
</BasePageTemplate>
)
}

Expand Down
Loading

0 comments on commit 68226a5

Please sign in to comment.