-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Align configuration pages into one flow, create ConfigurationBo…
…dy component for creating configuration pages (#26) Jira: EPMDEDP-12447 Resolves: #26 Change-Id: Ibde75a337ab4d48e534ac4b9a8d2d22324ccdf77
- Loading branch information
1 parent
549fb5f
commit daa8bfb
Showing
9 changed files
with
484 additions
and
884 deletions.
There are no files selected for viewing
141 changes: 141 additions & 0 deletions
141
src/pages/edp-configuration/components/ConfigurationBody/index.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,141 @@ | ||
import { Icon } from '@iconify/react'; | ||
import { EmptyContent } from '@kinvolk/headlamp-plugin/lib/CommonComponents'; | ||
import { | ||
Accordion, | ||
AccordionDetails, | ||
AccordionSummary, | ||
Grid, | ||
Link, | ||
Tooltip, | ||
Typography, | ||
} from '@material-ui/core'; | ||
import React from 'react'; | ||
import { CreateItemAccordion } from '../../../../components/CreateItemAccordion'; | ||
import { PageWithSubMenu } from '../../../../components/PageWithSubMenu'; | ||
import { PageWrapper } from '../../../../components/PageWrapper'; | ||
import { Render } from '../../../../components/Render'; | ||
import { ICONS } from '../../../../icons/iconify-icons-mapping'; | ||
import { menu } from '../../menu'; | ||
import { ConfigurationBodyProps } from './types'; | ||
|
||
export const ConfigurationBody = ({ | ||
pageData, | ||
renderPlaceHolderData, | ||
items, | ||
emptyMessage, | ||
}: ConfigurationBodyProps) => { | ||
const { label, description, docUrl } = pageData; | ||
const [expandedPanel, setExpandedPanel] = React.useState<string>(null); | ||
|
||
const handleChange = (panel: string) => (event: React.SyntheticEvent, isExpanded: boolean) => { | ||
setExpandedPanel(isExpanded ? panel : null); | ||
}; | ||
|
||
const handleClosePlaceholder = () => { | ||
setExpandedPanel(null); | ||
}; | ||
|
||
const placeholderData = React.useMemo( | ||
() => renderPlaceHolderData({ handleClosePlaceholder }), | ||
[renderPlaceHolderData] | ||
); | ||
|
||
return ( | ||
<PageWithSubMenu list={menu}> | ||
<PageWrapper containerMaxWidth={'lg'}> | ||
<Grid container spacing={3}> | ||
<Grid item xs={12}> | ||
<Typography variant={'h5'} gutterBottom> | ||
{label} | ||
</Typography> | ||
<Typography variant={'body1'}> | ||
{description}{' '} | ||
<Link href={docUrl} target={'_blank'}> | ||
<Typography variant={'body2'} component={'span'}> | ||
Learn more. | ||
</Typography> | ||
</Link> | ||
</Typography> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<CreateItemAccordion | ||
isExpanded={expandedPanel === 'placeholder'} | ||
onChange={handleChange('placeholder')} | ||
disabled={placeholderData.disabled} | ||
title={placeholderData.title} | ||
> | ||
<Grid container spacing={2}> | ||
<Grid item xs={12}> | ||
{placeholderData.component} | ||
</Grid> | ||
</Grid> | ||
</CreateItemAccordion> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<Grid container spacing={2}> | ||
{items && items.length ? ( | ||
items.map(configurationItem => { | ||
const key = configurationItem?.id; | ||
const ownerReference = configurationItem?.ownerReference; | ||
|
||
return ( | ||
<Grid item xs={12} key={key}> | ||
<Accordion | ||
expanded={expandedPanel === key} | ||
onChange={handleChange(key)} | ||
> | ||
<AccordionSummary | ||
expandIcon={<Icon icon={ICONS.ARROW_DOWN} />} | ||
> | ||
<Grid | ||
container | ||
spacing={3} | ||
alignItems={'center'} | ||
> | ||
<Grid item> | ||
<Typography variant={'h6'}> | ||
{configurationItem.title} | ||
</Typography> | ||
</Grid> | ||
<Render condition={!!ownerReference}> | ||
<Grid item> | ||
<Tooltip | ||
title={`Managed by ${ownerReference}`} | ||
> | ||
<Icon | ||
icon={ICONS.CLOUD_LOCK} | ||
width={20} | ||
style={{ | ||
display: 'block', | ||
}} | ||
/> | ||
</Tooltip> | ||
</Grid> | ||
</Render> | ||
</Grid> | ||
</AccordionSummary> | ||
<AccordionDetails> | ||
<Grid container spacing={2}> | ||
<Grid item xs={12}> | ||
{configurationItem.component} | ||
</Grid> | ||
</Grid> | ||
</AccordionDetails> | ||
</Accordion> | ||
</Grid> | ||
); | ||
}) | ||
) : ( | ||
<Grid item xs={12}> | ||
<EmptyContent color={'textSecondary'}> | ||
{emptyMessage} | ||
</EmptyContent> | ||
</Grid> | ||
)} | ||
</Grid> | ||
</Grid> | ||
</Grid> | ||
</PageWrapper> | ||
</PageWithSubMenu> | ||
); | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/pages/edp-configuration/components/ConfigurationBody/types.ts
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,24 @@ | ||
import React from 'react'; | ||
|
||
export interface ConfigurationItem { | ||
title: string; | ||
component: React.ReactElement; | ||
id?: string; | ||
ownerReference?: string; | ||
disabled?: boolean; | ||
} | ||
|
||
export interface ConfigurationBodyProps { | ||
pageData: { | ||
label: string; | ||
description: string; | ||
docUrl?: string; | ||
}; | ||
renderPlaceHolderData: ({ | ||
handleClosePlaceholder, | ||
}: { | ||
handleClosePlaceholder: () => void; | ||
}) => ConfigurationItem; | ||
items: ConfigurationItem[]; | ||
emptyMessage: string; | ||
} |
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.