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

chore: action events UI #6358

Merged
merged 3 commits into from
Feb 27, 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
59 changes: 37 additions & 22 deletions frontend/src/component/common/SidePanelList/SidePanelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ const StyledSidePanelHalf = styled('div')({
});

const StyledSidePanelHalfLeft = styled(StyledSidePanelHalf, {
shouldForwardProp: (prop) => prop !== 'height',
})<{ height?: number }>(({ theme, height }) => ({
shouldForwardProp: (prop) => prop !== 'height' && prop !== 'maxWidth',
})<{ height?: number; maxWidth?: number }>(({ theme, height, maxWidth }) => ({
border: `1px solid ${theme.palette.divider}`,
borderTop: 0,
borderBottomLeftRadius: theme.shape.borderRadiusMedium,
overflow: 'auto',
...(height && { height }),
...(maxWidth && { maxWidth }),
}));

const StyledSidePanelHalfRight = styled(StyledSidePanelHalf)(({ theme }) => ({
Expand All @@ -43,12 +44,14 @@ export const StyledSidePanelListColumn = styled('div', {
shouldForwardProp: (prop) => prop !== 'maxWidth' && prop !== 'align',
})<{ maxWidth?: number; align?: ColumnAlignment }>(
({ theme, maxWidth, align = 'start' }) => ({
display: 'flex',
flex: 1,
padding: theme.spacing(2),
fontSize: theme.fontSizes.smallBody,
justifyContent: align,
...(maxWidth && { maxWidth }),
textAlign: align,
alignItems: 'center',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this and the display change above affect other UI components? I'm just worried this might cause unnoticed changes a few days prior a release

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SidePanelList is a new component introduced in #6317 so I wouldn't worry about it.

The only other place where we're using it, Incoming webhook events, also looks correct with this change.

}),
);

Expand All @@ -64,6 +67,7 @@ interface ISidePanelListProps<T> {
columns: SidePanelListColumn<T>[];
sidePanelHeader: string;
renderContent: (item: T) => ReactNode;
renderItem?: (item: T, children: ReactNode) => ReactNode;
height?: number;
listEnd?: ReactNode;
}
Expand All @@ -73,6 +77,7 @@ export const SidePanelList = <T extends { id: string | number }>({
columns,
sidePanelHeader,
renderContent,
renderItem = (_, children) => children,
height,
listEnd,
}: ISidePanelListProps<T>) => {
Expand All @@ -83,34 +88,44 @@ export const SidePanelList = <T extends { id: string | number }>({
}

const activeItem = selectedItem || items[0];
const leftPanelMaxWidth = columns.every(({ maxWidth }) => Boolean(maxWidth))
? columns.reduce((acc, { maxWidth }) => acc + (maxWidth || 0), 0)
: undefined;

return (
<StyledSidePanelListWrapper>
<SidePanelListHeader
columns={columns}
sidePanelHeader={sidePanelHeader}
leftPanelMaxWidth={leftPanelMaxWidth}
/>
<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>
))}
<StyledSidePanelHalfLeft
height={height}
maxWidth={leftPanelMaxWidth}
>
{items.map((item) =>
renderItem(
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ const StyledHeader = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.table.headerBackground,
}));

const StyledHeaderHalf = styled('div')({
const StyledHeaderHalf = styled('div', {
shouldForwardProp: (prop) => prop !== 'maxWidth',
})<{ maxWidth?: number }>(({ maxWidth }) => ({
display: 'flex',
flex: 1,
});
...(maxWidth && { maxWidth }),
}));

interface ISidePanelListHeaderProps<T> {
columns: SidePanelListColumn<T>[];
sidePanelHeader: string;
leftPanelMaxWidth?: number;
}

export const SidePanelListHeader = <T,>({
columns,
sidePanelHeader,
leftPanelMaxWidth,
}: ISidePanelListHeaderProps<T>) => (
<StyledHeader>
<StyledHeaderHalf>
<StyledHeaderHalf maxWidth={leftPanelMaxWidth}>
{columns.map(({ header, maxWidth, align }) => (
<StyledSidePanelListColumn
key={header}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ const StyledItem = styled(Button, {
},
}));

interface ISidePanelListItemProps<T> {
interface ISidePanelListItemProps {
selected: boolean;
onClick: () => void;
children: ReactNode;
}

export const SidePanelListItem = <T,>({
export const SidePanelListItem = ({
selected,
onClick,
children,
}: ISidePanelListItemProps<T>) => (
}: ISidePanelListItemProps) => (
<StyledItemRow>
<StyledItem selected={selected} onClick={onClick}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const IncomingWebhooksEventsModal = ({
columns={[
{
header: 'Date',
maxWidth: 180,
cell: (event) =>
formatDateYMDHMS(
event.createdAt,
Expand All @@ -129,6 +130,7 @@ export const IncomingWebhooksEventsModal = ({
},
{
header: 'Token',
maxWidth: 350,
cell: (event) => event.tokenName,
},
]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
TokenGeneration,
useIncomingWebhooksForm,
} from './IncomingWebhooksForm/useIncomingWebhooksForm';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';

const StyledHeader = styled('div')(({ theme }) => ({
display: 'flex',
Expand Down Expand Up @@ -158,7 +159,10 @@ export const IncomingWebhooksModal = ({
>
<StyledHeader>
<StyledTitle>{title}</StyledTitle>
<Link onClick={onOpenEvents}>View events</Link>
<ConditionallyRender
condition={editing}
show={<Link onClick={onOpenEvents}>View events</Link>}
/>
Comment on lines +162 to +165

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Large Method
IncomingWebhooksModal has 138 lines, threshold = 120

Why does this problem occur?

Large functions with many lines of code are generally harder to understand and lower the code health. Avoid adding more lines to this function. Read more.

To ignore this warning click here.

</StyledHeader>
<StyledForm onSubmit={onSubmit}>
<IncomingWebhooksForm
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Alert, styled } from '@mui/material';
import { IActionSetEvent } from 'interfaces/action';
import { ProjectActionsEventsDetailsAction } from './ProjectActionsEventsDetailsAction';
import { ProjectActionsEventsDetailsSource } from './ProjectActionsEventsDetailsSource/ProjectActionsEventsDetailsSource';

const StyledDetails = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(2),
padding: theme.spacing(2),
}));

export const ProjectActionsEventsDetails = ({
state,
actionSet: { actions },
observableEvent,
}: IActionSetEvent) => {
const stateText =
state === 'failed'
? `${
actions.filter(({ state }) => state !== 'success').length
} out of ${actions.length} actions were not successfully executed`
: 'All actions were successfully executed';

return (
<StyledDetails>
<Alert severity={state === 'failed' ? 'error' : 'success'}>
{stateText}
</Alert>
<ProjectActionsEventsDetailsSource
observableEvent={observableEvent}
/>
{actions.map((action, i) => (
<ProjectActionsEventsDetailsAction
key={action.id}
action={action}
>
Action {i + 1}
</ProjectActionsEventsDetailsAction>
))}
</StyledDetails>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { CheckCircleOutline, ErrorOutline } from '@mui/icons-material';
import { Alert, CircularProgress, Divider, styled } from '@mui/material';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { IActionEvent } from 'interfaces/action';
import { ReactNode } from 'react';

const StyledAction = styled('div', {
shouldForwardProp: (prop) => prop !== 'state',
})<{ state?: IActionEvent['state'] }>(({ theme, state }) => ({
padding: theme.spacing(2),
border: `1px solid ${theme.palette.divider}`,
borderRadius: theme.shape.borderRadiusMedium,
...(state === 'not started' && {
backgroundColor: theme.palette.background.elevation1,
}),
}));

const StyledHeader = styled('div')({
display: 'flex',
flexDirection: 'column',
});

const StyledHeaderRow = styled('div')({
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
width: '100%',
});

const StyledHeaderState = styled('div')(({ theme }) => ({
display: 'flex',
alignItems: 'center',
fontSize: theme.fontSizes.smallBody,
gap: theme.spacing(2),
}));

export const StyledSuccessIcon = styled(CheckCircleOutline)(({ theme }) => ({
color: theme.palette.success.main,
}));

export const StyledFailedIcon = styled(ErrorOutline)(({ theme }) => ({
color: theme.palette.error.main,
}));

const StyledAlert = styled(Alert)(({ theme }) => ({
marginTop: theme.spacing(2),
}));

const StyledDivider = styled(Divider)(({ theme }) => ({
margin: theme.spacing(2, 0),
}));

const StyledActionBody = styled('div')(({ theme }) => ({
fontSize: theme.fontSizes.smallBody,
}));

const StyledActionLabel = styled('p')(({ theme }) => ({
fontWeight: theme.fontWeight.bold,
marginBottom: theme.spacing(0.5),
}));

const StyledPropertyLabel = styled('span')(({ theme }) => ({
color: theme.palette.text.secondary,
}));

interface IProjectActionsEventsDetailsActionProps {
action: IActionEvent;
children: ReactNode;
}

export const ProjectActionsEventsDetailsAction = ({
action: { state, details, action, executionParams },
children,
}: IProjectActionsEventsDetailsActionProps) => {
const actionState =
state === 'success' ? (
<StyledSuccessIcon />
) : state === 'failed' ? (
<StyledFailedIcon />
) : state === 'started' ? (
<CircularProgress size={20} />
) : (
<span>Not started</span>
);

return (
<StyledAction state={state}>
<StyledHeader>
<StyledHeaderRow>
<div>{children}</div>
<StyledHeaderState>{actionState}</StyledHeaderState>
</StyledHeaderRow>
<ConditionallyRender
condition={Boolean(details)}
show={<StyledAlert severity='error'>{details}</StyledAlert>}
/>
</StyledHeader>
<StyledDivider />
<StyledActionBody>
<StyledActionLabel>{action}</StyledActionLabel>
{Object.entries(executionParams).map(([property, value]) => (
<div key={property}>
<StyledPropertyLabel>{property}:</StyledPropertyLabel>{' '}
{value}
</div>
))}
</StyledActionBody>
</StyledAction>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { IObservableEvent } from 'interfaces/action';
import { ProjectActionsEventsDetailsSourceIncomingWebhook } from './ProjectActionsEventsDetailsSourceIncomingWebhook';

interface IProjectActionsEventsDetailsSourceProps {
observableEvent: IObservableEvent;
}

export const ProjectActionsEventsDetailsSource = ({
observableEvent,
}: IProjectActionsEventsDetailsSourceProps) => {
const { source } = observableEvent;

if (source === 'incoming-webhook') {
return (
<ProjectActionsEventsDetailsSourceIncomingWebhook
observableEvent={observableEvent}
/>
);
}

return null;
};
Loading
Loading