Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui/list: padding and console fixes #3850

Merged
merged 5 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions web/src/app/lists/FlatList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export interface FlatListNotice extends Notice {
handleOnClick?: (event: MouseEvent) => void
'data-cy'?: string
}
export interface FlatListItemOptions extends ListItemProps {
title?: string
export interface FlatListItemOptions extends Omit<ListItemProps, 'title'> {
title?: React.ReactNode
primaryText?: React.ReactNode
highlight?: boolean
subText?: JSX.Element | string
Expand All @@ -119,7 +119,7 @@ export interface FlatListItemOptions extends ListItemProps {
}

export interface SectionTitle {
title: string
title: React.ReactNode
icon?: React.ReactNode | null
subText?: JSX.Element | string
}
Expand Down Expand Up @@ -172,7 +172,7 @@ export default function FlatList({
const classes = useStyles()

// collapsable sections state
const [openSections, setOpenSections] = useState<string[]>(
const [openSections, setOpenSections] = useState<React.ReactNode[]>(
sections && sections.length ? [sections[0].title] : [],
)

Expand All @@ -182,7 +182,9 @@ export default function FlatList({
if (
openSections.length &&
sectionArr?.length &&
!sectionArr?.find((section: string) => section === openSections[0])
!sectionArr?.find(
(section: React.ReactNode) => section === openSections[0],
)
) {
setOpenSections([sectionArr[0]])
}
Expand Down Expand Up @@ -367,7 +369,7 @@ export default function FlatList({
}

function renderCollapsableItems(): JSX.Element[] | undefined {
const toggleSection = (section: string): void => {
const toggleSection = (section: React.ReactNode): void => {
if (openSections?.includes(section)) {
setOpenSections(
openSections.filter((openSection) => openSection !== section),
Expand Down
3 changes: 2 additions & 1 deletion web/src/app/lists/FlatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function FlatListItem(props: FlatListItemProps): JSX.Element {
let linkProps = {}
if (url) {
linkProps = {
// MUI renders differently based on if secondaryAction is present
// if you render a link with a secondary action, MUI will render the <a> tag without an <li> around it
component: secondaryAction ? AppLink : AppLinkListItem,
to: url,
button: true,
Expand Down Expand Up @@ -102,6 +102,7 @@ export default function FlatListItem(props: FlatListItemProps): JSX.Element {
[classes.listItemDisabled]: disabled,
}),
tabIndex: 0,
component: typeof subText === 'string' ? 'p' : 'div',
}}
/>
{secondaryAction && (
Expand Down
35 changes: 18 additions & 17 deletions web/src/app/services/IntegrationKeyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import IntegrationKeyDeleteDialog from './IntegrationKeyDeleteDialog'
import CopyText from '../util/CopyText'
import AppLink from '../util/AppLink'
import { useIsWidthDown } from '../util/useWidth'
import { Add, ArrowDownward } from '@mui/icons-material'
import { Add } from '@mui/icons-material'
import makeStyles from '@mui/styles/makeStyles'
import Spinner from '../loading/components/Spinner'
import { GenericError } from '../error-pages'
Expand All @@ -24,9 +24,9 @@ import {
AccordionDetails,
AccordionSummary,
Chip,
Divider,
Typography,
} from '@mui/material'
import { ChevronDown } from 'mdi-material-ui'

const query = gql`
query ($serviceID: ID!) {
Expand Down Expand Up @@ -147,11 +147,12 @@ export default function IntegrationKeyList(props: {
.map(
(key: IntegrationKey): FlatListListItem => ({
title: key.name,
subText: <Chip label={key.externalSystemName} />,
subText: <Chip label={key.externalSystemName} sx={{ mt: 1 }} />,
secondaryAction: (
<IconButton
onClick={(): void => setDeleteDialog(key.id)}
size='large'
sx={{ right: '-16px' }}
>
<Trash />
</IconButton>
Expand Down Expand Up @@ -188,20 +189,20 @@ export default function IntegrationKeyList(props: {
}
/>
{!!extItems.length && (
<React.Fragment>
<Divider />
<Accordion disableGutters elevation={0}>
<AccordionSummary expandIcon={<ArrowDownward />}>
<Typography>Externally Managed Keys</Typography>
</AccordionSummary>
<AccordionDetails>
<FlatList
headerNote='These keys are managed by other applications.'
items={extItems}
/>
</AccordionDetails>
</Accordion>
</React.Fragment>
<Accordion disableGutters elevation={0}>
<AccordionSummary
expandIcon={<ChevronDown />}
sx={{ ml: '6px', mr: '12px' }}
>
<Typography>Externally Managed Keys</Typography>
</AccordionSummary>
<AccordionDetails>
<FlatList
headerNote='These keys are managed by other applications.'
items={extItems}
/>
</AccordionDetails>
</Accordion>
)}
</CardContent>
</Card>
Expand Down
6 changes: 4 additions & 2 deletions web/src/app/util/AppLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ const AppLink: ForwardRefRenderFunction<HTMLAnchorElement, AppLinkProps> =

export default forwardRef(AppLink)

// forwardRef required to shut console up
export const AppLinkListItem = forwardRef<HTMLAnchorElement, AppLinkProps>(
(props, ref) => (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(props, _) => (
<li>
<AppLink ref={ref} {...props} />
<AppLink {...props} />
</li>
),
)
Expand Down
Loading