Skip to content

Commit

Permalink
chore: project actions table
Browse files Browse the repository at this point in the history
  • Loading branch information
nunogois committed Jan 25, 2024
1 parent 9ac1c88 commit 6621d60
Show file tree
Hide file tree
Showing 10 changed files with 608 additions and 3 deletions.
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,44 @@
import { styled, Typography } 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 StyledItem = styled(Typography)(({ theme }) => ({
fontSize: theme.fontSizes.smallerBody,
}));

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={
<>
{actions.map(({ id, action, executionParams }) => (
<StyledItem key={id}>
{action}: {JSON.stringify(executionParams)}
</StyledItem>
))}
</>
}
>
{actions.length === 1 ? '1 action' : `${actions.length} tokens`}
</TooltipLink>
</TextCell>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 { sourceId } = action.match;
const actor = serviceAccounts.find(({ id }) => id === sourceId);

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

return <TextCell>{actor.name}</TextCell>;
};
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.keys(payload);

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

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

0 comments on commit 6621d60

Please sign in to comment.