Skip to content

Commit 1d4a195

Browse files
MC-1680: adding a disable/enable switch for Sections (#1232)
* MC-1680: adding a disable/enable switch for Sections
1 parent 24ea24e commit 1d4a195

File tree

5 files changed

+249
-33
lines changed

5 files changed

+249
-33
lines changed

src/api/fragments/SectionData.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const BaseSectionData = gql`
88
scheduledSurfaceGuid
99
sort
1010
createSource
11+
disabled
1112
active
1213
}
1314
`;

src/api/generatedTypes.ts

+140-30
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ export type ApprovedCorpusItem = {
8686
excerpt: Scalars['String'];
8787
/** An alternative primary key in UUID format that is generated on creation. */
8888
externalId: Scalars['ID'];
89-
/** The quality grade associated with this CorpusItem. */
90-
grade?: Maybe<ApprovedItemGrade>;
9189
/** True if the domain of the corpus item has been scheduled in the past. */
9290
hasTrustedDomain: Scalars['Boolean'];
9391
/**
@@ -208,13 +206,6 @@ export type ApprovedCorpusItemScheduledSurfaceHistoryFilters = {
208206
scheduledSurfaceGuid?: InputMaybe<Scalars['ID']>;
209207
};
210208

211-
/** Valid grade values for CorpusItem (public graph) and ApprovedItem (admin graph) */
212-
export enum ApprovedItemGrade {
213-
A = 'A',
214-
B = 'B',
215-
C = 'C',
216-
}
217-
218209
export type ArticleMarkdown = {
219210
__typename?: 'ArticleMarkdown';
220211
images?: Maybe<Array<MarkdownImagePosition>>;
@@ -521,8 +512,6 @@ export type CreateApprovedCorpusItemInput = {
521512
datePublished?: InputMaybe<Scalars['Date']>;
522513
/** The excerpt of the Approved Item. */
523514
excerpt: Scalars['String'];
524-
/** The quality grade associated with this CorpusItem. */
525-
grade?: InputMaybe<ApprovedItemGrade>;
526515
/** The image URL for this item's accompanying picture. */
527516
imageUrl: Scalars['Url'];
528517
/** Whether this story is a Pocket Collection. */
@@ -732,6 +721,17 @@ export type DeleteScheduledCorpusItemInput = {
732721
reasons?: InputMaybe<Scalars['String']>;
733722
};
734723

724+
/** Input data for disabling or enabling a Section */
725+
export type DisableEnableSectionInput = {
726+
/**
727+
* Indicates whether or not a Section is fully disabled from display on NewTab. Can only be controlled
728+
* in the admin tool.
729+
*/
730+
disabled: Scalars['Boolean'];
731+
/** An alternative primary key in UUID format supplied by ML. */
732+
externalId: Scalars['ID'];
733+
};
734+
735735
/** Metadata from a domain, originally populated from ClearBit */
736736
export type DomainMetadata = {
737737
__typename?: 'DomainMetadata';
@@ -1227,6 +1227,8 @@ export type Mutation = {
12271227
deleteCollectionStory: CollectionStory;
12281228
/** Deletes an item from a Scheduled Surface. */
12291229
deleteScheduledCorpusItem: ScheduledCorpusItem;
1230+
/** Disables or enables a Section. Can only be done from the admin tool. */
1231+
disableEnableSection: Section;
12301232
/**
12311233
* Lets an automated process create an Approved Item and optionally schedule it to appear
12321234
* on a Scheduled Surface.
@@ -1254,8 +1256,6 @@ export type Mutation = {
12541256
rescheduleScheduledCorpusItem: ScheduledCorpusItem;
12551257
/** Updates an Approved Item. */
12561258
updateApprovedCorpusItem: ApprovedCorpusItem;
1257-
/** Updates the grade of an Approved Item */
1258-
updateApprovedCorpusItemGrade: ApprovedCorpusItem;
12591259
/** Updates a Collection. */
12601260
updateCollection: Collection;
12611261
/** Updates a CollectionAuthor. */
@@ -1373,6 +1373,10 @@ export type MutationDeleteScheduledCorpusItemArgs = {
13731373
data: DeleteScheduledCorpusItemInput;
13741374
};
13751375

1376+
export type MutationDisableEnableSectionArgs = {
1377+
data: DisableEnableSectionInput;
1378+
};
1379+
13761380
export type MutationImportApprovedCorpusItemArgs = {
13771381
data: ImportApprovedCorpusItemInput;
13781382
};
@@ -1405,10 +1409,6 @@ export type MutationUpdateApprovedCorpusItemArgs = {
14051409
data: UpdateApprovedCorpusItemInput;
14061410
};
14071411

1408-
export type MutationUpdateApprovedCorpusItemGradeArgs = {
1409-
data: UpdateApprovedCorpusItemGradeInput;
1410-
};
1411-
14121412
export type MutationUpdateCollectionArgs = {
14131413
data: UpdateCollectionInput;
14141414
};
@@ -1689,7 +1689,7 @@ export type Query = {
16891689
getScheduledCorpusItems: Array<ScheduledCorpusItemsResult>;
16901690
/** Retrieves all ScheduledSurfaces available to the given SSO user. Requires an Authorization header. */
16911691
getScheduledSurfacesForUser: Array<ScheduledSurface>;
1692-
/** Retrieves a list of active Sections with their corresponding active SectionItems for a scheduled surface. */
1692+
/** Retrieves a list of active and enabled/disabled Sections with their corresponding active SectionItems for a scheduled surface. */
16931693
getSectionsWithSectionItems: Array<Section>;
16941694
/** returns parser meta data for a given url */
16951695
getUrlMetadata: UrlMetadata;
@@ -2081,6 +2081,11 @@ export type Section = {
20812081
createSource: ActivitySource;
20822082
/** A Unix timestamp of when the Section was created. */
20832083
createdAt: Scalars['Int'];
2084+
/**
2085+
* Indicates whether or not a Section is fully disabled from display on NewTab. Can only be controlled
2086+
* in the admin tool.
2087+
*/
2088+
disabled: Scalars['Boolean'];
20842089
/** An alternative primary key in UUID format. */
20852090
externalId: Scalars['ID'];
20862091
/** The GUID of the Scheduled Surface. Example: 'NEW_TAB_EN_US'. */
@@ -2273,16 +2278,6 @@ export type UnMarseable = {
22732278
html: Scalars['String'];
22742279
};
22752280

2276-
/** Input data for updating the grade of an Approved Item. */
2277-
export type UpdateApprovedCorpusItemGradeInput = {
2278-
/** The UI screen where the approved corpus item is being graded from. */
2279-
actionScreen: ActionScreen;
2280-
/** Approved Item ID. */
2281-
externalId: Scalars['ID'];
2282-
/** The quality grade associated with this CorpusItem. */
2283-
grade: ApprovedItemGrade;
2284-
};
2285-
22862281
/** Input data for updating an Approved Item. */
22872282
export type UpdateApprovedCorpusItemInput = {
22882283
/**
@@ -2298,8 +2293,6 @@ export type UpdateApprovedCorpusItemInput = {
22982293
excerpt: Scalars['String'];
22992294
/** Approved Item ID. */
23002295
externalId: Scalars['ID'];
2301-
/** The quality grade associated with this CorpusItem. */
2302-
grade?: InputMaybe<ApprovedItemGrade>;
23032296
/** The image URL for this item's accompanying picture. */
23042297
imageUrl: Scalars['Url'];
23052298
/**
@@ -2636,6 +2629,7 @@ export type BaseSectionDataFragment = {
26362629
scheduledSurfaceGuid: string;
26372630
sort?: number | null;
26382631
createSource: ActivitySource;
2632+
disabled: boolean;
26392633
active: boolean;
26402634
};
26412635

@@ -2648,6 +2642,7 @@ export type SectionDataFragment = {
26482642
scheduledSurfaceGuid: string;
26492643
sort?: number | null;
26502644
createSource: ActivitySource;
2645+
disabled: boolean;
26512646
active: boolean;
26522647
sectionItems: Array<{
26532648
__typename?: 'SectionItem';
@@ -3373,6 +3368,68 @@ export type DeleteScheduledItemMutation = {
33733368
};
33743369
};
33753370

3371+
export type DisableEnableSectionMutationVariables = Exact<{
3372+
data: DisableEnableSectionInput;
3373+
}>;
3374+
3375+
export type DisableEnableSectionMutation = {
3376+
__typename?: 'Mutation';
3377+
disableEnableSection: {
3378+
__typename?: 'Section';
3379+
createdAt: number;
3380+
updatedAt: number;
3381+
externalId: string;
3382+
title: string;
3383+
scheduledSurfaceGuid: string;
3384+
sort?: number | null;
3385+
createSource: ActivitySource;
3386+
disabled: boolean;
3387+
active: boolean;
3388+
sectionItems: Array<{
3389+
__typename?: 'SectionItem';
3390+
createdAt: number;
3391+
updatedAt: number;
3392+
externalId: string;
3393+
rank?: number | null;
3394+
approvedItem: {
3395+
__typename?: 'ApprovedCorpusItem';
3396+
externalId: string;
3397+
prospectId?: string | null;
3398+
title: string;
3399+
language: CorpusLanguage;
3400+
publisher: string;
3401+
datePublished?: any | null;
3402+
url: any;
3403+
hasTrustedDomain: boolean;
3404+
imageUrl: any;
3405+
excerpt: string;
3406+
status: CuratedStatus;
3407+
source: CorpusItemSource;
3408+
topic: string;
3409+
isCollection: boolean;
3410+
isTimeSensitive: boolean;
3411+
isSyndicated: boolean;
3412+
createdBy: string;
3413+
createdAt: number;
3414+
updatedBy?: string | null;
3415+
updatedAt: number;
3416+
authors: Array<{
3417+
__typename?: 'CorpusItemAuthor';
3418+
name: string;
3419+
sortOrder: number;
3420+
}>;
3421+
scheduledSurfaceHistory: Array<{
3422+
__typename?: 'ApprovedCorpusItemScheduledSurfaceHistory';
3423+
externalId: string;
3424+
createdBy: string;
3425+
scheduledDate: any;
3426+
scheduledSurfaceGuid: string;
3427+
}>;
3428+
};
3429+
}>;
3430+
};
3431+
};
3432+
33763433
export type ImageUploadMutationVariables = Exact<{
33773434
image: Scalars['Upload'];
33783435
width: Scalars['Int'];
@@ -4874,6 +4931,7 @@ export type GetSectionsWithSectionItemsQuery = {
48744931
scheduledSurfaceGuid: string;
48754932
sort?: number | null;
48764933
createSource: ActivitySource;
4934+
disabled: boolean;
48774935
active: boolean;
48784936
sectionItems: Array<{
48794937
__typename?: 'SectionItem';
@@ -5117,6 +5175,7 @@ export const BaseSectionDataFragmentDoc = gql`
51175175
scheduledSurfaceGuid
51185176
sort
51195177
createSource
5178+
disabled
51205179
active
51215180
}
51225181
`;
@@ -6053,6 +6112,57 @@ export type DeleteScheduledItemMutationOptions = Apollo.BaseMutationOptions<
60536112
DeleteScheduledItemMutation,
60546113
DeleteScheduledItemMutationVariables
60556114
>;
6115+
export const DisableEnableSectionDocument = gql`
6116+
mutation disableEnableSection($data: DisableEnableSectionInput!) {
6117+
disableEnableSection(data: $data) {
6118+
...SectionData
6119+
}
6120+
}
6121+
${SectionDataFragmentDoc}
6122+
`;
6123+
export type DisableEnableSectionMutationFn = Apollo.MutationFunction<
6124+
DisableEnableSectionMutation,
6125+
DisableEnableSectionMutationVariables
6126+
>;
6127+
6128+
/**
6129+
* __useDisableEnableSectionMutation__
6130+
*
6131+
* To run a mutation, you first call `useDisableEnableSectionMutation` within a React component and pass it any options that fit your needs.
6132+
* When your component renders, `useDisableEnableSectionMutation` returns a tuple that includes:
6133+
* - A mutate function that you can call at any time to execute the mutation
6134+
* - An object with fields that represent the current status of the mutation's execution
6135+
*
6136+
* @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;
6137+
*
6138+
* @example
6139+
* const [disableEnableSectionMutation, { data, loading, error }] = useDisableEnableSectionMutation({
6140+
* variables: {
6141+
* data: // value for 'data'
6142+
* },
6143+
* });
6144+
*/
6145+
export function useDisableEnableSectionMutation(
6146+
baseOptions?: Apollo.MutationHookOptions<
6147+
DisableEnableSectionMutation,
6148+
DisableEnableSectionMutationVariables
6149+
>,
6150+
) {
6151+
const options = { ...defaultOptions, ...baseOptions };
6152+
return Apollo.useMutation<
6153+
DisableEnableSectionMutation,
6154+
DisableEnableSectionMutationVariables
6155+
>(DisableEnableSectionDocument, options);
6156+
}
6157+
export type DisableEnableSectionMutationHookResult = ReturnType<
6158+
typeof useDisableEnableSectionMutation
6159+
>;
6160+
export type DisableEnableSectionMutationResult =
6161+
Apollo.MutationResult<DisableEnableSectionMutation>;
6162+
export type DisableEnableSectionMutationOptions = Apollo.BaseMutationOptions<
6163+
DisableEnableSectionMutation,
6164+
DisableEnableSectionMutationVariables
6165+
>;
60566166
export const ImageUploadDocument = gql`
60576167
mutation imageUpload(
60586168
$image: Upload!
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { gql } from '@apollo/client';
2+
import { SectionData } from '../fragments/SectionData';
3+
4+
/**
5+
* Disables or enables a Section.
6+
*/
7+
export const disableEnableSection = gql`
8+
mutation disableEnableSection($data: DisableEnableSectionInput!) {
9+
disableEnableSection(data: $data) {
10+
...SectionData
11+
}
12+
}
13+
${SectionData}
14+
`;

src/curated-corpus/components/SectionDetails/SectionDetails.test.tsx

+42
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import { getTestApprovedItem } from '../../helpers/approvedItem';
1414
describe('The SectionDetails component', () => {
1515
const item: ApprovedCorpusItem = getTestApprovedItem();
1616
const mockSections: Section[] = [
17+
// enabled section
1718
{
1819
externalId: '1',
1920
title: 'Section 1',
2021
active: true,
22+
disabled: false,
2123
sectionItems: [
2224
{
2325
externalId: 'item-1',
@@ -31,10 +33,12 @@ describe('The SectionDetails component', () => {
3133
createSource: ActivitySource.Ml,
3234
scheduledSurfaceGuid: 'NEW_TAB_EN_US',
3335
},
36+
// disabled section
3437
{
3538
externalId: '2',
3639
title: 'Section 2',
3740
active: true,
41+
disabled: true,
3842
sectionItems: [
3943
{
4044
externalId: 'item-2',
@@ -162,4 +166,42 @@ describe('The SectionDetails component', () => {
162166
mockSections[0].sectionItems[0],
163167
);
164168
});
169+
170+
it('should render & toggle the Disable switch', async () => {
171+
render(
172+
<MockedProvider>
173+
<SnackbarProvider maxSnack={3}>
174+
<SectionDetails
175+
sections={mockSections}
176+
currentSection="Section 1" // section to be disabled
177+
setCurrentSectionItem={mockSetCurrentSectionItem}
178+
currentScheduledSurfaceGuid="NEW_TAB_EN_US"
179+
toggleEditModal={mockToggleEditModal}
180+
refetch={mockRefetch}
181+
/>
182+
</SnackbarProvider>
183+
</MockedProvider>,
184+
);
185+
const disableSwitch = screen.getByRole('checkbox', { name: /disable/i });
186+
expect(disableSwitch).toBeInTheDocument();
187+
});
188+
189+
it('should render & toggle the Enable switch', async () => {
190+
render(
191+
<MockedProvider>
192+
<SnackbarProvider maxSnack={3}>
193+
<SectionDetails
194+
sections={mockSections}
195+
currentSection="Section 2" // section to be disabled
196+
setCurrentSectionItem={mockSetCurrentSectionItem}
197+
currentScheduledSurfaceGuid="NEW_TAB_EN_US"
198+
toggleEditModal={mockToggleEditModal}
199+
refetch={mockRefetch}
200+
/>
201+
</SnackbarProvider>
202+
</MockedProvider>,
203+
);
204+
const enableSwitch = screen.getByRole('checkbox', { name: /enable/i });
205+
expect(enableSwitch).toBeInTheDocument();
206+
});
165207
});

0 commit comments

Comments
 (0)