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: project actions table #6039

Merged
merged 2 commits into from
Jan 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export const ProjectActions = () => {
}
>
<PermissionGuard permissions={ADMIN}>
<ProjectActionsTable />
<ProjectActionsTable
modalOpen={actionModalOpen}
setModalOpen={setActionModalOpen}
selectedAction={selectedAction}
setSelectedAction={setSelectedAction}
/>
</PermissionGuard>
</PageContent>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { styled } from '@mui/material';
import { TextCell } from 'component/common/Table/cells/TextCell/TextCell';
import { IActionSet } from 'interfaces/action';
import { LinkCell } from 'component/common/Table/cells/LinkCell/LinkCell';
import { TooltipLink } from 'component/common/TooltipLink/TooltipLink';

const StyledActionItems = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
gap: theme.spacing(1),
fontSize: theme.fontSizes.smallerBody,
}));

const StyledParameterList = styled('ul')(({ theme }) => ({
listStyle: 'none',
paddingLeft: theme.spacing(1),
margin: 0,
}));

interface IProjectActionsActionsCellProps {
action: IActionSet;
onCreateAction?: () => void;
}

export const ProjectActionsActionsCell = ({
action,
onCreateAction,
}: IProjectActionsActionsCellProps) => {
const { actions } = action;

if (actions.length === 0) {
if (!onCreateAction) return <TextCell>0 actions</TextCell>;
else return <LinkCell title='Create action' onClick={onCreateAction} />;
}

return (
<TextCell>
<TooltipLink
tooltip={
<StyledActionItems>
{actions.map(({ id, action, executionParams }) => (
<div key={id}>
<strong>{action}</strong>
<StyledParameterList>
{Object.entries(executionParams).map(
([param, value]) => (
<li key={param}>
{param}: {value}
</li>
),
)}
</StyledParameterList>
</div>
))}
</StyledActionItems>
}
>
{actions.length === 1
? '1 action'
: `${actions.length} actions`}
</TooltipLink>
</TextCell>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { LinkCell } from 'component/common/Table/cells/LinkCell/LinkCell';
import { TextCell } from 'component/common/Table/cells/TextCell/TextCell';
import { IActionSet } from 'interfaces/action';
import { IServiceAccount } from 'interfaces/service-account';

interface IProjectActionsActorCellProps {
action: IActionSet;
serviceAccounts: IServiceAccount[];
}

export const ProjectActionsActorCell = ({
action,
serviceAccounts,
}: IProjectActionsActorCellProps) => {
const { actorId } = action;
const actor = serviceAccounts.find(({ id }) => id === actorId);

if (!actor) {
return <TextCell>No service account</TextCell>;
}

return <LinkCell to='/admin/service-accounts'>{actor.name}</LinkCell>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { IActionSet } from 'interfaces/action';

interface IProjectActionsDeleteDialogProps {
action?: IActionSet;
open: boolean;
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
onConfirm: (action: IActionSet) => void;
}

export const ProjectActionsDeleteDialog = ({
action,
open,
setOpen,
onConfirm,
}: IProjectActionsDeleteDialogProps) => (
<Dialogue
title='Delete action?'
open={open}
primaryButtonText='Delete action'
secondaryButtonText='Cancel'
onClick={() => onConfirm(action!)}
onClose={() => {
setOpen(false);
}}
>
<p>
You are about to delete action: <strong>{action?.name}</strong>
</p>
</Dialogue>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { styled, Typography } from '@mui/material';
import { TextCell } from 'component/common/Table/cells/TextCell/TextCell';
import { IActionSet } from 'interfaces/action';
import { TooltipLink } from 'component/common/TooltipLink/TooltipLink';

const StyledItem = styled(Typography)(({ theme }) => ({
fontSize: theme.fontSizes.smallerBody,
}));

interface IProjectActionsFiltersCellProps {
action: IActionSet;
}

export const ProjectActionsFiltersCell = ({
action,
}: IProjectActionsFiltersCellProps) => {
const { payload } = action.match;
const filters = Object.entries(payload);

if (filters.length === 0) {
return <TextCell>0 filters</TextCell>;
}

return (
<TextCell>
<TooltipLink
tooltip={
<>
{filters.map(([parameter, value]) => (
<StyledItem key={parameter}>
{parameter}: {value}
</StyledItem>
))}
</>
}
>
{filters.length === 1
? '1 filter'
: `${filters.length} filters`}
</TooltipLink>
</TextCell>
);
};
Loading
Loading