Skip to content

Commit

Permalink
chore: action events UI development
Browse files Browse the repository at this point in the history
  • Loading branch information
nunogois committed Feb 27, 2024
1 parent 08c8051 commit c891e01
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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',
Expand All @@ -26,9 +27,9 @@ export const ProjectActionsEventsDetails = ({
<Alert severity={state === 'failed' ? 'error' : 'success'}>
{stateText}
</Alert>
{/* <ProjectActionsEventsDetailsSource
<ProjectActionsEventsDetailsSource
observableEvent={observableEvent}
/> */}
/>
{actions.map((action, i) => (
<ProjectActionsEventsDetailsAction
key={action.id}
Expand Down
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;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { ExpandMore } from '@mui/icons-material';
import {
Accordion,
AccordionDetails,
AccordionSummary,
IconButton,
styled,
} from '@mui/material';
import { useIncomingWebhooks } from 'hooks/api/getters/useIncomingWebhooks/useIncomingWebhooks';
import { IObservableEvent } from 'interfaces/action';
import { Suspense, lazy, useMemo } from 'react';
import { Link } from 'react-router-dom';

const LazyReactJSONEditor = lazy(
() => import('component/common/ReactJSONEditor/ReactJSONEditor'),
);

const StyledAccordion = styled(Accordion)(({ theme }) => ({
boxShadow: 'none',
border: `1px solid ${theme.palette.divider}`,
borderRadius: theme.shape.borderRadiusMedium,
'&:before': {
display: 'none',
},
}));

const StyledLink = styled(Link)(({ theme }) => ({
marginLeft: theme.spacing(1),
}));

interface IProjectActionsEventsDetailsSourceIncomingWebhookProps {
observableEvent: IObservableEvent;
}

export const ProjectActionsEventsDetailsSourceIncomingWebhook = ({
observableEvent,
}: IProjectActionsEventsDetailsSourceIncomingWebhookProps) => {
const { incomingWebhooks } = useIncomingWebhooks();

const incomingWebhookName = useMemo(() => {
const incomingWebhook = incomingWebhooks.find(
(incomingWebhook) =>
incomingWebhook.id === observableEvent.sourceId,
);

return incomingWebhook?.name;
}, [incomingWebhooks, observableEvent.sourceId]);

return (
<StyledAccordion>
<AccordionSummary
expandIcon={
<IconButton>
<ExpandMore titleAccess='Toggle' />
</IconButton>
}
>
Incoming webhook:
<StyledLink to='/integrations/incoming-webhooks'>
{incomingWebhookName}
</StyledLink>
</AccordionSummary>
<AccordionDetails>
<Suspense fallback={null}>
<LazyReactJSONEditor
content={{ json: observableEvent.payload }}
readOnly
statusBar={false}
editorStyle='sidePanel'
/>
</Suspense>
</AccordionDetails>
</StyledAccordion>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ export const ProjectActionsEventsModal = ({
]}
sidePanelHeader='Details'
renderContent={ProjectActionsEventsDetails}
renderItem={({ state }, children) => {
renderItem={({ id, state }, children) => {
if (state === 'failed') {
return (
<StyledFailedItemWrapper>
<StyledFailedItemWrapper key={id}>
{children}
</StyledFailedItemWrapper>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/interfaces/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface IAction {

export type ObservableEventSource = 'incoming-webhook';

interface IObservableEvent {
export interface IObservableEvent {
id: number;
source: ObservableEventSource;
sourceId: number;
Expand Down

0 comments on commit c891e01

Please sign in to comment.