-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: incoming webhook events UI (#6317)
https://linear.app/unleash/issue/2-1937/incoming-webhook-events-ui This PR implements the UI for incoming webhook events. We're also introducing a new `SidePanelList` component that we'll be able to reuse when we tackle action set events. This PR also promotes `ReactJSONEditor` to a common component and adapts it slightly for this use case. ![image](https://github.com/Unleash/unleash/assets/14320932/b1abc2e0-3971-4882-b6f6-0ae48d1523d5) ![image](https://github.com/Unleash/unleash/assets/14320932/ce5c31e4-650a-4df5-a966-2ce06fd6baa8) We're refreshing the events view every 5s, so if you're monitoring events for a specific incoming webhook you can see the latest ones coming in. We load 20 (configurable through the hook) events by default. Everytime you reach the end of the list you can load 20 more events until you reach the end of the event list. ![image](https://github.com/Unleash/unleash/assets/14320932/94f187a1-8b0f-4138-8dbc-d3ebc9914bfd)
- Loading branch information
Showing
12 changed files
with
603 additions
and
9 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
122 changes: 122 additions & 0 deletions
122
frontend/src/component/common/SidePanelList/SidePanelList.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,122 @@ | ||
import { styled } from '@mui/material'; | ||
import { ReactNode, useState } from 'react'; | ||
import { SidePanelListHeader } from './SidePanelListHeader'; | ||
import { SidePanelListItem } from './SidePanelListItem'; | ||
|
||
const StyledSidePanelListWrapper = styled('div')({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
width: '100%', | ||
}); | ||
|
||
const StyledSidePanelListBody = styled('div')({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
}); | ||
|
||
const StyledSidePanelHalf = styled('div')({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
flex: 1, | ||
}); | ||
|
||
const StyledSidePanelHalfLeft = styled(StyledSidePanelHalf, { | ||
shouldForwardProp: (prop) => prop !== 'height', | ||
})<{ height?: number }>(({ theme, height }) => ({ | ||
border: `1px solid ${theme.palette.divider}`, | ||
borderTop: 0, | ||
borderBottomLeftRadius: theme.shape.borderRadiusMedium, | ||
overflow: 'auto', | ||
...(height && { height }), | ||
})); | ||
|
||
const StyledSidePanelHalfRight = styled(StyledSidePanelHalf)(({ theme }) => ({ | ||
border: `1px solid ${theme.palette.divider}`, | ||
borderTop: 0, | ||
borderLeft: 0, | ||
borderBottomRightRadius: theme.shape.borderRadiusMedium, | ||
})); | ||
|
||
type ColumnAlignment = 'start' | 'end' | 'center'; | ||
|
||
export const StyledSidePanelListColumn = styled('div', { | ||
shouldForwardProp: (prop) => prop !== 'maxWidth' && prop !== 'align', | ||
})<{ maxWidth?: number; align?: ColumnAlignment }>( | ||
({ theme, maxWidth, align = 'start' }) => ({ | ||
flex: 1, | ||
padding: theme.spacing(2), | ||
fontSize: theme.fontSizes.smallBody, | ||
justifyContent: align, | ||
...(maxWidth && { maxWidth }), | ||
textAlign: align, | ||
}), | ||
); | ||
|
||
export type SidePanelListColumn<T> = { | ||
header: string; | ||
maxWidth?: number; | ||
align?: ColumnAlignment; | ||
cell: (item: T) => ReactNode; | ||
}; | ||
|
||
interface ISidePanelListProps<T> { | ||
items: T[]; | ||
columns: SidePanelListColumn<T>[]; | ||
sidePanelHeader: string; | ||
renderContent: (item: T) => ReactNode; | ||
height?: number; | ||
listEnd?: ReactNode; | ||
} | ||
|
||
export const SidePanelList = <T extends { id: string | number }>({ | ||
items, | ||
columns, | ||
sidePanelHeader, | ||
renderContent, | ||
height, | ||
listEnd, | ||
}: ISidePanelListProps<T>) => { | ||
const [selectedItem, setSelectedItem] = useState<T>(items[0]); | ||
|
||
if (items.length === 0) { | ||
return null; | ||
} | ||
|
||
const activeItem = selectedItem || items[0]; | ||
|
||
return ( | ||
<StyledSidePanelListWrapper> | ||
<SidePanelListHeader | ||
columns={columns} | ||
sidePanelHeader={sidePanelHeader} | ||
/> | ||
<StyledSidePanelListBody> | ||
<StyledSidePanelHalfLeft height={height}> | ||
{items.map((item) => ( | ||
<SidePanelListItem | ||
key={item.id} | ||
selected={activeItem.id === item.id} | ||
onClick={() => setSelectedItem(item)} | ||
> | ||
{columns.map( | ||
({ header, maxWidth, align, cell }) => ( | ||
<StyledSidePanelListColumn | ||
key={header} | ||
maxWidth={maxWidth} | ||
align={align} | ||
> | ||
{cell(item)} | ||
</StyledSidePanelListColumn> | ||
), | ||
)} | ||
</SidePanelListItem> | ||
))} | ||
{listEnd} | ||
</StyledSidePanelHalfLeft> | ||
<StyledSidePanelHalfRight> | ||
{renderContent(activeItem)} | ||
</StyledSidePanelHalfRight> | ||
</StyledSidePanelListBody> | ||
</StyledSidePanelListWrapper> | ||
); | ||
}; |
48 changes: 48 additions & 0 deletions
48
frontend/src/component/common/SidePanelList/SidePanelListHeader.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,48 @@ | ||
import { styled } from '@mui/material'; | ||
import { | ||
SidePanelListColumn, | ||
StyledSidePanelListColumn, | ||
} from './SidePanelList'; | ||
|
||
const StyledHeader = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
borderTopLeftRadius: theme.shape.borderRadiusMedium, | ||
borderTopRightRadius: theme.shape.borderRadiusMedium, | ||
backgroundColor: theme.palette.table.headerBackground, | ||
})); | ||
|
||
const StyledHeaderHalf = styled('div')({ | ||
display: 'flex', | ||
flex: 1, | ||
}); | ||
|
||
interface ISidePanelListHeaderProps<T> { | ||
columns: SidePanelListColumn<T>[]; | ||
sidePanelHeader: string; | ||
} | ||
|
||
export const SidePanelListHeader = <T,>({ | ||
columns, | ||
sidePanelHeader, | ||
}: ISidePanelListHeaderProps<T>) => ( | ||
<StyledHeader> | ||
<StyledHeaderHalf> | ||
{columns.map(({ header, maxWidth, align }) => ( | ||
<StyledSidePanelListColumn | ||
key={header} | ||
maxWidth={maxWidth} | ||
align={align} | ||
> | ||
{header} | ||
</StyledSidePanelListColumn> | ||
))} | ||
</StyledHeaderHalf> | ||
<StyledHeaderHalf> | ||
<StyledSidePanelListColumn> | ||
{sidePanelHeader} | ||
</StyledSidePanelListColumn> | ||
</StyledHeaderHalf> | ||
</StyledHeader> | ||
); |
58 changes: 58 additions & 0 deletions
58
frontend/src/component/common/SidePanelList/SidePanelListItem.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,58 @@ | ||
import { Button, styled } from '@mui/material'; | ||
import { ReactNode } from 'react'; | ||
|
||
const StyledItemRow = styled('div')(({ theme }) => ({ | ||
borderBottom: `1px solid ${theme.palette.divider}`, | ||
})); | ||
|
||
const StyledItem = styled(Button, { | ||
shouldForwardProp: (prop) => prop !== 'selected', | ||
})<{ selected: boolean }>(({ theme, selected }) => ({ | ||
'&.MuiButton-root': { | ||
width: '100%', | ||
backgroundColor: selected | ||
? theme.palette.secondary.light | ||
: 'transparent', | ||
borderRight: `${theme.spacing(0.5)} solid ${ | ||
selected ? theme.palette.background.alternative : 'transparent' | ||
}`, | ||
padding: 0, | ||
borderRadius: 0, | ||
justifyContent: 'start', | ||
transition: 'background-color 0.2s ease', | ||
color: theme.palette.text.primary, | ||
textAlign: 'left', | ||
fontWeight: selected ? theme.fontWeight.bold : theme.fontWeight.medium, | ||
fontSize: theme.fontSizes.smallBody, | ||
overflow: 'auto', | ||
}, | ||
'&:hover': { | ||
backgroundColor: selected | ||
? theme.palette.secondary.light | ||
: theme.palette.neutral.light, | ||
}, | ||
'&.Mui-disabled': { | ||
pointerEvents: 'auto', | ||
}, | ||
'&:focus-visible': { | ||
outline: `2px solid ${theme.palette.primary.main}`, | ||
}, | ||
})); | ||
|
||
interface ISidePanelListItemProps<T> { | ||
selected: boolean; | ||
onClick: () => void; | ||
children: ReactNode; | ||
} | ||
|
||
export const SidePanelListItem = <T,>({ | ||
selected, | ||
onClick, | ||
children, | ||
}: ISidePanelListItemProps<T>) => ( | ||
<StyledItemRow> | ||
<StyledItem selected={selected} onClick={onClick}> | ||
{children} | ||
</StyledItem> | ||
</StyledItemRow> | ||
); |
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.