Skip to content

Commit c5f79c4

Browse files
mmiermansDre Grant
andauthored
HNT-1345: Allow curators to update publisher names (#1263)
* feat: add publisher domain mapping functionality * fix: simplify deep subdomain test case formatting * Implement changes after review * Simplify tldts call --------- Co-authored-by: Dre Grant <[email protected]>
1 parent 6ab0b02 commit c5f79c4

File tree

11 files changed

+652
-123
lines changed

11 files changed

+652
-123
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
.env.development.local
2121
.env.test.local
2222
.env.production.local
23+
*.tsbuildinfo
2324

2425
npm-debug.log*
2526
yarn-debug.log*

package-lock.json

Lines changed: 49 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"stream-browserify": "^3.0.0",
8787
"style-loader": "^3.3.4",
8888
"terser-webpack-plugin": "^5.3.14",
89+
"tldts": "^6.1.86",
8990
"ts-pnp": "1.2.0",
9091
"typescript": "4.9.5",
9192
"url": "^0.11.4",

src/_shared/hooks/useRunMutation/useRunMutation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const useRunMutation = () => {
1414
options: any,
1515
message?: string,
1616
successCallback?: (data?: any) => void,
17-
errorCallback?: () => void,
17+
errorCallback?: (error?: Error) => void,
1818
refetch?: any,
1919
): void => {
2020
mutateFunction(options)
@@ -39,7 +39,7 @@ export const useRunMutation = () => {
3939

4040
// execute any additional actions, i.e. hiding the edit form
4141
if (errorCallback) {
42-
errorCallback();
42+
errorCallback(error);
4343
}
4444
});
4545
};

src/api/generatedTypes.ts

Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,13 @@ export type CreateApprovedCorpusItemInput = {
527527
language: CorpusLanguage;
528528
/** The GUID of the corresponding Prospect ID. Will be empty for manually added items. */
529529
prospectId?: InputMaybe<Scalars['ID']>;
530-
/** The name of the online publication that published this story. */
531-
publisher: Scalars['String'];
530+
/**
531+
* The name of the online publication that published this story.
532+
* If not provided, it will be derived from the PublisherDomain table
533+
* (looking up by subdomain first, then registrable domain),
534+
* falling back to the URL's hostname if no match is found.
535+
*/
536+
publisher?: InputMaybe<Scalars['String']>;
532537
/** Optionally, specify the date this item should be appearing on a Scheduled Surface. Format: YYYY-MM-DD */
533538
scheduledDate?: InputMaybe<Scalars['Date']>;
534539
/** Optionally, specify the source of the Scheduled Item. Could be one of: MANUAL or ML */
@@ -637,6 +642,19 @@ export type CreateCustomSectionInput = {
637642
title: Scalars['String'];
638643
};
639644

645+
/** Input data for creating or updating a publisher domain mapping. */
646+
export type CreateOrUpdatePublisherDomainInput = {
647+
/**
648+
* The domain name (hostname only, not a full URL).
649+
* Will be sanitized: trimmed, lowercased, converted to ASCII (punycode), www. prefix stripped.
650+
* Must be a registrable domain (e.g., "example.com") or subdomain (e.g., "news.example.com").
651+
* Cannot be a public suffix (e.g., "co.uk"), IP address, or wildcard.
652+
*/
653+
domainName: Scalars['String'];
654+
/** The display name for the publisher. Will be trimmed but case is preserved. */
655+
publisher: Scalars['String'];
656+
};
657+
640658
/** Input data for creating a Section */
641659
export type CreateOrUpdateSectionInput = {
642660
/** Indicates whether or not a Section is available for display. */
@@ -1212,6 +1230,14 @@ export type Mutation = {
12121230
createCustomSection: Section;
12131231
/** Creates a Label. */
12141232
createLabel: Label;
1233+
/**
1234+
* Creates or updates a publisher domain mapping.
1235+
* If a mapping for the domain already exists, updates the publisher name.
1236+
* Otherwise, creates a new mapping.
1237+
* Domain names are sanitized (trimmed, lowercased, converted to ASCII, www. stripped)
1238+
* and validated before storage.
1239+
*/
1240+
createOrUpdatePublisherDomain: PublisherDomain;
12151241
/**
12161242
* Creates a new Section entity. If a Section already exists, the existing
12171243
* Section gets updated, associated active SectionItems are set to in-active.
@@ -1356,6 +1382,10 @@ export type MutationCreateLabelArgs = {
13561382
name: Scalars['String'];
13571383
};
13581384

1385+
export type MutationCreateOrUpdatePublisherDomainArgs = {
1386+
data: CreateOrUpdatePublisherDomainInput;
1387+
};
1388+
13591389
export type MutationCreateOrUpdateSectionArgs = {
13601390
data: CreateOrUpdateSectionInput;
13611391
};
@@ -1660,6 +1690,30 @@ export enum ProspectType {
16601690
TopSaved = 'TOP_SAVED',
16611691
}
16621692

1693+
/**
1694+
* A mapping between a domain name and its publisher display name.
1695+
* Used to auto-populate the publisher field when creating corpus items.
1696+
*/
1697+
export type PublisherDomain = {
1698+
__typename?: 'PublisherDomain';
1699+
/** A Unix timestamp of when the entity was created. */
1700+
createdAt: Scalars['Int'];
1701+
/** A single sign-on user identifier of the user who created this entity. */
1702+
createdBy: Scalars['String'];
1703+
/**
1704+
* The domain name (hostname). This is the unique identifier.
1705+
* Stored normalized: lowercase, ASCII (punycode), without www. prefix.
1706+
* Can be a registrable domain (e.g., "example.com") or subdomain (e.g., "news.example.com").
1707+
*/
1708+
domainName: Scalars['String'];
1709+
/** The display name for the publisher. */
1710+
publisher: Scalars['String'];
1711+
/** A Unix timestamp of when the entity was last updated. */
1712+
updatedAt: Scalars['Int'];
1713+
/** A single sign-on user identifier of the user who last updated this entity. Null on creation. */
1714+
updatedBy?: Maybe<Scalars['String']>;
1715+
};
1716+
16631717
export type Query = {
16641718
__typename?: 'Query';
16651719
/** Retrieves an approved item with the given external ID. */
@@ -1710,7 +1764,7 @@ export type Query = {
17101764
getScheduledSurfacesForUser: Array<ScheduledSurface>;
17111765
/** Retrieves a list of active and enabled/disabled Sections with their corresponding active SectionItems for a scheduled surface. */
17121766
getSectionsWithSectionItems: Array<Section>;
1713-
/** returns parser meta data for a given url */
1767+
/** returns meta data for a given url */
17141768
getUrlMetadata: UrlMetadata;
17151769
/** Look up Item info by a url. */
17161770
itemByUrl?: Maybe<Item>;
@@ -3371,6 +3425,23 @@ export type CreateLabelMutation = {
33713425
createLabel: { __typename?: 'Label'; externalId: string; name: string };
33723426
};
33733427

3428+
export type CreateOrUpdatePublisherDomainMutationVariables = Exact<{
3429+
data: CreateOrUpdatePublisherDomainInput;
3430+
}>;
3431+
3432+
export type CreateOrUpdatePublisherDomainMutation = {
3433+
__typename?: 'Mutation';
3434+
createOrUpdatePublisherDomain: {
3435+
__typename?: 'PublisherDomain';
3436+
domainName: string;
3437+
publisher: string;
3438+
createdAt: number;
3439+
createdBy: string;
3440+
updatedAt: number;
3441+
updatedBy?: string | null;
3442+
};
3443+
};
3444+
33743445
export type CreateScheduledCorpusItemMutationVariables = Exact<{
33753446
approvedItemExternalId: Scalars['ID'];
33763447
scheduledSurfaceGuid: Scalars['ID'];
@@ -6170,6 +6241,64 @@ export type CreateLabelMutationOptions = Apollo.BaseMutationOptions<
61706241
CreateLabelMutation,
61716242
CreateLabelMutationVariables
61726243
>;
6244+
export const CreateOrUpdatePublisherDomainDocument = gql`
6245+
mutation createOrUpdatePublisherDomain(
6246+
$data: CreateOrUpdatePublisherDomainInput!
6247+
) {
6248+
createOrUpdatePublisherDomain(data: $data) {
6249+
domainName
6250+
publisher
6251+
createdAt
6252+
createdBy
6253+
updatedAt
6254+
updatedBy
6255+
}
6256+
}
6257+
`;
6258+
export type CreateOrUpdatePublisherDomainMutationFn = Apollo.MutationFunction<
6259+
CreateOrUpdatePublisherDomainMutation,
6260+
CreateOrUpdatePublisherDomainMutationVariables
6261+
>;
6262+
6263+
/**
6264+
* __useCreateOrUpdatePublisherDomainMutation__
6265+
*
6266+
* To run a mutation, you first call `useCreateOrUpdatePublisherDomainMutation` within a React component and pass it any options that fit your needs.
6267+
* When your component renders, `useCreateOrUpdatePublisherDomainMutation` returns a tuple that includes:
6268+
* - A mutate function that you can call at any time to execute the mutation
6269+
* - An object with fields that represent the current status of the mutation's execution
6270+
*
6271+
* @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;
6272+
*
6273+
* @example
6274+
* const [createOrUpdatePublisherDomainMutation, { data, loading, error }] = useCreateOrUpdatePublisherDomainMutation({
6275+
* variables: {
6276+
* data: // value for 'data'
6277+
* },
6278+
* });
6279+
*/
6280+
export function useCreateOrUpdatePublisherDomainMutation(
6281+
baseOptions?: Apollo.MutationHookOptions<
6282+
CreateOrUpdatePublisherDomainMutation,
6283+
CreateOrUpdatePublisherDomainMutationVariables
6284+
>,
6285+
) {
6286+
const options = { ...defaultOptions, ...baseOptions };
6287+
return Apollo.useMutation<
6288+
CreateOrUpdatePublisherDomainMutation,
6289+
CreateOrUpdatePublisherDomainMutationVariables
6290+
>(CreateOrUpdatePublisherDomainDocument, options);
6291+
}
6292+
export type CreateOrUpdatePublisherDomainMutationHookResult = ReturnType<
6293+
typeof useCreateOrUpdatePublisherDomainMutation
6294+
>;
6295+
export type CreateOrUpdatePublisherDomainMutationResult =
6296+
Apollo.MutationResult<CreateOrUpdatePublisherDomainMutation>;
6297+
export type CreateOrUpdatePublisherDomainMutationOptions =
6298+
Apollo.BaseMutationOptions<
6299+
CreateOrUpdatePublisherDomainMutation,
6300+
CreateOrUpdatePublisherDomainMutationVariables
6301+
>;
61736302
export const CreateScheduledCorpusItemDocument = gql`
61746303
mutation createScheduledCorpusItem(
61756304
$approvedItemExternalId: ID!
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { gql } from '@apollo/client';
2+
3+
/**
4+
* Create or update a publisher domain mapping
5+
*/
6+
export const createOrUpdatePublisherDomain = gql`
7+
mutation createOrUpdatePublisherDomain(
8+
$data: CreateOrUpdatePublisherDomainInput!
9+
) {
10+
createOrUpdatePublisherDomain(data: $data) {
11+
domainName
12+
publisher
13+
createdAt
14+
createdBy
15+
updatedAt
16+
updatedBy
17+
}
18+
}
19+
`;

0 commit comments

Comments
 (0)