Skip to content

Commit 24ea24e

Browse files
MC-1656: adding edit & remove section item actions (#1231)
* MC-1656: adding edit & remove section item actions
1 parent 96b9948 commit 24ea24e

File tree

8 files changed

+362
-41
lines changed

8 files changed

+362
-41
lines changed

src/_shared/components/CardActionButtonRow/CardActionButtonRow.test.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@ describe('The CardActionButtonRow component', () => {
1010
const onReschedule = jest.fn();
1111
const onUnschedule = jest.fn();
1212
const onReject = jest.fn();
13+
const onRemove = jest.fn();
1314

1415
//TODO update when reject button flow ready
15-
it('should render all four card action buttons and call their callbacks', () => {
16+
it('should render all five card action buttons and call their callbacks', () => {
1617
render(
1718
<CardActionButtonRow
1819
onEdit={onEdit}
1920
onUnschedule={onUnschedule}
2021
onReschedule={onReschedule}
2122
onMoveToBottom={onMoveToBottom}
2223
onReject={onReject}
24+
onRemove={onRemove}
2325
/>,
2426
);
2527

@@ -58,6 +60,14 @@ describe('The CardActionButtonRow component', () => {
5860
expect(rejectButton).toBeInTheDocument();
5961
userEvent.click(rejectButton);
6062
expect(onReject).toHaveBeenCalled();
63+
64+
//assert for remove button and onRemove callback
65+
const removeButton = screen.getByRole('button', {
66+
name: 'remove',
67+
});
68+
expect(removeButton).toBeInTheDocument();
69+
userEvent.click(rejectButton);
70+
expect(onReject).toHaveBeenCalled();
6171
});
6272
it('should only render card actions that are passed', () => {
6373
render(<CardActionButtonRow onEdit={onEdit} onReject={onReject} />);
@@ -87,5 +97,9 @@ describe('The CardActionButtonRow component', () => {
8797
expect(rejectButton).toBeInTheDocument();
8898
userEvent.click(rejectButton);
8999
expect(onReject).toHaveBeenCalled();
100+
101+
// assert removeButton button is NOT present
102+
const removeButton = screen.queryByLabelText('remove');
103+
expect(removeButton).not.toBeInTheDocument();
90104
});
91105
});

src/_shared/components/CardActionButtonRow/CardActionButtonRow.tsx

+37-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import EditOutlinedIcon from '@mui/icons-material/EditOutlined';
66
import EventBusyOutlinedIcon from '@mui/icons-material/EventBusyOutlined';
77
import KeyboardDoubleArrowDownOutlinedIcon from '@mui/icons-material/KeyboardDoubleArrowDownOutlined';
88
import DeleteOutlinedIcon from '@mui/icons-material/DeleteOutlined';
9+
import ClearIcon from '@mui/icons-material/Clear';
910
import { curationPalette } from '../../../theme';
1011

1112
interface CardActionButtonRowProps {
@@ -32,14 +33,25 @@ interface CardActionButtonRowProps {
3233
/**
3334
* Callback for the "Reject" (trash) button
3435
*/
35-
onReject: VoidFunction;
36+
onReject?: VoidFunction;
37+
38+
/**
39+
* Callback for the "Remove" (X) button
40+
*/
41+
onRemove?: VoidFunction;
3642
}
3743

3844
export const CardActionButtonRow: React.FC<CardActionButtonRowProps> = (
3945
props,
4046
): JSX.Element => {
41-
const { onEdit, onUnschedule, onReschedule, onMoveToBottom, onReject } =
42-
props;
47+
const {
48+
onEdit,
49+
onUnschedule,
50+
onReschedule,
51+
onMoveToBottom,
52+
onReject,
53+
onRemove,
54+
} = props;
4355

4456
return (
4557
<Stack
@@ -50,15 +62,17 @@ export const CardActionButtonRow: React.FC<CardActionButtonRowProps> = (
5062
ml="0.5rem"
5163
>
5264
<Stack direction="row" justifyContent="flex-start">
53-
<Tooltip title="Reject" placement="bottom">
54-
<IconButton
55-
aria-label="reject"
56-
onClick={onReject}
57-
sx={{ color: curationPalette.jetBlack }}
58-
>
59-
<DeleteOutlinedIcon />
60-
</IconButton>
61-
</Tooltip>
65+
{onReject && (
66+
<Tooltip title="Reject" placement="bottom">
67+
<IconButton
68+
aria-label="reject"
69+
onClick={onReject}
70+
sx={{ color: curationPalette.jetBlack }}
71+
>
72+
<DeleteOutlinedIcon />
73+
</IconButton>
74+
</Tooltip>
75+
)}
6276

6377
{onMoveToBottom && (
6478
<Tooltip title="Move to bottom" placement="bottom">
@@ -107,6 +121,17 @@ export const CardActionButtonRow: React.FC<CardActionButtonRowProps> = (
107121
</IconButton>
108122
</Tooltip>
109123
)}
124+
{onRemove && (
125+
<Tooltip title="Remove" placement="bottom">
126+
<IconButton
127+
aria-label="remove"
128+
onClick={onRemove}
129+
sx={{ color: curationPalette.jetBlack }}
130+
>
131+
<ClearIcon />
132+
</IconButton>
133+
</Tooltip>
134+
)}
110135
</Stack>
111136
</Stack>
112137
);

src/api/generatedTypes.ts

+107-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ export enum ActionScreen {
5353
Prospecting = 'PROSPECTING',
5454
/** This action took place from the schedule screen in the admin tool */
5555
Schedule = 'SCHEDULE',
56+
/** This action took place from the sections screen in the admin tool */
57+
Sections = 'SECTIONS',
5658
}
5759

5860
/** The source of en entity */
@@ -1234,7 +1236,10 @@ export type Mutation = {
12341236
moderateShareableList?: Maybe<ShareableListComplete>;
12351237
/** Refresh an Item's article content. */
12361238
refreshItemArticle: Item;
1237-
/** Rejects an Approved Item: deletes it from the corpus and creates a Rejected Item instead. */
1239+
/**
1240+
* Rejects an Approved Item: deletes it from the corpus and creates a Rejected Item instead.
1241+
* Also deletes all associated SectionItems.
1242+
*/
12381243
rejectApprovedCorpusItem: ApprovedCorpusItem;
12391244
/**
12401245
* Marks a prospect as 'curated' in the database, preventing it from being displayed for prospecting.
@@ -3512,6 +3517,56 @@ export type RemoveProspectMutation = {
35123517
} | null;
35133518
};
35143519

3520+
export type RemoveSectionItemMutationVariables = Exact<{
3521+
externalId: Scalars['String'];
3522+
}>;
3523+
3524+
export type RemoveSectionItemMutation = {
3525+
__typename?: 'Mutation';
3526+
removeSectionItem: {
3527+
__typename?: 'SectionItem';
3528+
createdAt: number;
3529+
updatedAt: number;
3530+
externalId: string;
3531+
rank?: number | null;
3532+
approvedItem: {
3533+
__typename?: 'ApprovedCorpusItem';
3534+
externalId: string;
3535+
prospectId?: string | null;
3536+
title: string;
3537+
language: CorpusLanguage;
3538+
publisher: string;
3539+
datePublished?: any | null;
3540+
url: any;
3541+
hasTrustedDomain: boolean;
3542+
imageUrl: any;
3543+
excerpt: string;
3544+
status: CuratedStatus;
3545+
source: CorpusItemSource;
3546+
topic: string;
3547+
isCollection: boolean;
3548+
isTimeSensitive: boolean;
3549+
isSyndicated: boolean;
3550+
createdBy: string;
3551+
createdAt: number;
3552+
updatedBy?: string | null;
3553+
updatedAt: number;
3554+
authors: Array<{
3555+
__typename?: 'CorpusItemAuthor';
3556+
name: string;
3557+
sortOrder: number;
3558+
}>;
3559+
scheduledSurfaceHistory: Array<{
3560+
__typename?: 'ApprovedCorpusItemScheduledSurfaceHistory';
3561+
externalId: string;
3562+
createdBy: string;
3563+
scheduledDate: any;
3564+
scheduledSurfaceGuid: string;
3565+
}>;
3566+
};
3567+
};
3568+
};
3569+
35153570
export type RescheduleScheduledCorpusItemMutationVariables = Exact<{
35163571
externalId: Scalars['ID'];
35173572
scheduledDate: Scalars['Date'];
@@ -6267,6 +6322,57 @@ export type RemoveProspectMutationOptions = Apollo.BaseMutationOptions<
62676322
RemoveProspectMutation,
62686323
RemoveProspectMutationVariables
62696324
>;
6325+
export const RemoveSectionItemDocument = gql`
6326+
mutation RemoveSectionItem($externalId: String!) {
6327+
removeSectionItem(externalId: $externalId) {
6328+
...SectionItemData
6329+
}
6330+
}
6331+
${SectionItemDataFragmentDoc}
6332+
`;
6333+
export type RemoveSectionItemMutationFn = Apollo.MutationFunction<
6334+
RemoveSectionItemMutation,
6335+
RemoveSectionItemMutationVariables
6336+
>;
6337+
6338+
/**
6339+
* __useRemoveSectionItemMutation__
6340+
*
6341+
* To run a mutation, you first call `useRemoveSectionItemMutation` within a React component and pass it any options that fit your needs.
6342+
* When your component renders, `useRemoveSectionItemMutation` returns a tuple that includes:
6343+
* - A mutate function that you can call at any time to execute the mutation
6344+
* - An object with fields that represent the current status of the mutation's execution
6345+
*
6346+
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
6347+
*
6348+
* @example
6349+
* const [removeSectionItemMutation, { data, loading, error }] = useRemoveSectionItemMutation({
6350+
* variables: {
6351+
* externalId: // value for 'externalId'
6352+
* },
6353+
* });
6354+
*/
6355+
export function useRemoveSectionItemMutation(
6356+
baseOptions?: Apollo.MutationHookOptions<
6357+
RemoveSectionItemMutation,
6358+
RemoveSectionItemMutationVariables
6359+
>,
6360+
) {
6361+
const options = { ...defaultOptions, ...baseOptions };
6362+
return Apollo.useMutation<
6363+
RemoveSectionItemMutation,
6364+
RemoveSectionItemMutationVariables
6365+
>(RemoveSectionItemDocument, options);
6366+
}
6367+
export type RemoveSectionItemMutationHookResult = ReturnType<
6368+
typeof useRemoveSectionItemMutation
6369+
>;
6370+
export type RemoveSectionItemMutationResult =
6371+
Apollo.MutationResult<RemoveSectionItemMutation>;
6372+
export type RemoveSectionItemMutationOptions = Apollo.BaseMutationOptions<
6373+
RemoveSectionItemMutation,
6374+
RemoveSectionItemMutationVariables
6375+
>;
62706376
export const RescheduleScheduledCorpusItemDocument = gql`
62716377
mutation rescheduleScheduledCorpusItem(
62726378
$externalId: ID!
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { gql } from '@apollo/client';
2+
import { SectionItemData } from '../fragments/SectionItemData';
3+
4+
export const removeSectionItem = gql`
5+
mutation RemoveSectionItem($externalId: String!) {
6+
removeSectionItem(externalId: $externalId) {
7+
...SectionItemData
8+
}
9+
}
10+
${SectionItemData}
11+
`;

0 commit comments

Comments
 (0)