From bc2ad83e69438e671516f1be0b85a47d5244e855 Mon Sep 17 00:00:00 2001 From: thecalcc Date: Mon, 6 Nov 2023 14:45:47 +0200 Subject: [PATCH 1/3] Add item action to superdesk api --- scripts/api/article.ts | 8 ++++++++ scripts/core/get-superdesk-api-implementation.tsx | 1 + scripts/core/superdesk-api.d.ts | 1 + 3 files changed, 10 insertions(+) diff --git a/scripts/api/article.ts b/scripts/api/article.ts index 1c07b756a8..8dc9dec130 100644 --- a/scripts/api/article.ts +++ b/scripts/api/article.ts @@ -378,6 +378,12 @@ function get(id: IArticle['_id']): Promise { return dataApi.findOne('archive', id); } +function itemAction(article: IArticle): any { + const authoring = ng.get('authoring'); + + return authoring.itemAction(article); +} + function isEditable(_article: IArticle): boolean { const itemState: ITEM_STATE = _article.state; const authoring = ng.get('authoring'); @@ -424,6 +430,7 @@ interface IArticleApi { */ isPublished(article: IArticle, includeScheduled?: boolean): boolean; + itemAction(article: IArticle): any; isKilled(article: IArticle): boolean; isIngested(article: IArticle): boolean; isPersonal(article: IArticle): boolean; @@ -491,6 +498,7 @@ export const article: IArticleApi = { rewrite, isLocked, isEditable, + itemAction, isLockedInCurrentSession, isLockedInOtherSession, isLockedByCurrentUser, diff --git a/scripts/core/get-superdesk-api-implementation.tsx b/scripts/core/get-superdesk-api-implementation.tsx index cb644addfa..b7abd14f29 100644 --- a/scripts/core/get-superdesk-api-implementation.tsx +++ b/scripts/core/get-superdesk-api-implementation.tsx @@ -283,6 +283,7 @@ export function getSuperdeskApiImplementation( patch: patchArticle, isArchived: sdApi.article.isArchived, isPublished: (article) => sdApi.article.isPublished(article), + itemAction: (article) => sdApi.article.itemAction(article), }, desk: { getStagesOrdered: (deskId: string) => diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index c9be4cf1b3..564a0a7329 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -2691,6 +2691,7 @@ declare module 'superdesk-api' { isArchived(article: IArticle): boolean; isPublished(article: IArticle): boolean; + itemAction(article: IArticle): any; }; contentProfile: { get(id: string): Promise; From 842b434fa3a6e065a979e518950157fe8c125dd8 Mon Sep 17 00:00:00 2001 From: thecalcc Date: Mon, 6 Nov 2023 14:59:58 +0200 Subject: [PATCH 2/3] Improve types --- scripts/api/article.ts | 4 ++-- scripts/core/superdesk-api.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/api/article.ts b/scripts/api/article.ts index 8dc9dec130..d27b27c2ec 100644 --- a/scripts/api/article.ts +++ b/scripts/api/article.ts @@ -378,7 +378,7 @@ function get(id: IArticle['_id']): Promise { return dataApi.findOne('archive', id); } -function itemAction(article: IArticle): any { +function itemAction(article: IArticle): {[key: string]: boolean} { const authoring = ng.get('authoring'); return authoring.itemAction(article); @@ -430,7 +430,7 @@ interface IArticleApi { */ isPublished(article: IArticle, includeScheduled?: boolean): boolean; - itemAction(article: IArticle): any; + itemAction(article: IArticle): {[key: string]: boolean}; isKilled(article: IArticle): boolean; isIngested(article: IArticle): boolean; isPersonal(article: IArticle): boolean; diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index 564a0a7329..cb88a2ca6a 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -2691,7 +2691,7 @@ declare module 'superdesk-api' { isArchived(article: IArticle): boolean; isPublished(article: IArticle): boolean; - itemAction(article: IArticle): any; + itemAction(article: IArticle): {[key: string]: boolean}; }; contentProfile: { get(id: string): Promise; From 3f4cd2c0f35fd1d215df1d32c224e96b07e45368 Mon Sep 17 00:00:00 2001 From: thecalcc Date: Mon, 6 Nov 2023 15:20:15 +0200 Subject: [PATCH 3/3] Fix types --- scripts/api/article.ts | 15 +++++++--- .../authoring/authoring-topbar-react.tsx | 5 ++-- .../authoring/authoring-topbar2-react.tsx | 5 ++-- .../services/AuthoringWorkspaceService.ts | 10 +++---- scripts/core/superdesk-api.d.ts | 30 ++++++++++++++++++- 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/scripts/api/article.ts b/scripts/api/article.ts index d27b27c2ec..db86468547 100644 --- a/scripts/api/article.ts +++ b/scripts/api/article.ts @@ -16,7 +16,14 @@ import {notify} from 'core/notify/notify'; import ng from 'core/services/ng'; import {gettext} from 'core/utils'; import {flatMap, trim} from 'lodash'; -import {IArticle, IDangerousArticlePatchingOptions, IDesk, IStage, onPublishMiddlewareResult} from 'superdesk-api'; +import { + IArticle, + IAuthoringActionType, + IDangerousArticlePatchingOptions, + IDesk, + IStage, + onPublishMiddlewareResult, +} from 'superdesk-api'; import {duplicateItems} from './article-duplicate'; import {fetchItems, fetchItemsToCurrentDesk} from './article-fetch'; import {patchArticle} from './article-patch'; @@ -378,10 +385,10 @@ function get(id: IArticle['_id']): Promise { return dataApi.findOne('archive', id); } -function itemAction(article: IArticle): {[key: string]: boolean} { +function itemAction(_article: IArticle): {[key in IAuthoringActionType]: boolean} { const authoring = ng.get('authoring'); - return authoring.itemAction(article); + return authoring.itemAction(_article); } function isEditable(_article: IArticle): boolean { @@ -430,7 +437,7 @@ interface IArticleApi { */ isPublished(article: IArticle, includeScheduled?: boolean): boolean; - itemAction(article: IArticle): {[key: string]: boolean}; + itemAction(article: IArticle): {[key in IAuthoringActionType]: boolean}; isKilled(article: IArticle): boolean; isIngested(article: IArticle): boolean; isPersonal(article: IArticle): boolean; diff --git a/scripts/apps/authoring/authoring/authoring-topbar-react.tsx b/scripts/apps/authoring/authoring/authoring-topbar-react.tsx index 8eb6f525b1..d5402978c7 100644 --- a/scripts/apps/authoring/authoring/authoring-topbar-react.tsx +++ b/scripts/apps/authoring/authoring/authoring-topbar-react.tsx @@ -1,14 +1,13 @@ import React from 'react'; -import {IArticle} from 'superdesk-api'; +import {IArticle, IAuthoringActionType} from 'superdesk-api'; import {flatMap} from 'lodash'; import {extensions} from 'appConfig'; -import {IAuthoringAction} from './services/AuthoringWorkspaceService'; import {registerToReceivePatches, unregisterFromReceivingPatches} from 'apps/authoring-bridge/receive-patches'; import {dataApi} from 'core/helpers/CrudManager'; interface IProps { article: IArticle; - action: IAuthoringAction; + action: IAuthoringActionType; onChange(article: IArticle): void; } diff --git a/scripts/apps/authoring/authoring/authoring-topbar2-react.tsx b/scripts/apps/authoring/authoring/authoring-topbar2-react.tsx index a8bdcbeee5..aef425f97e 100644 --- a/scripts/apps/authoring/authoring/authoring-topbar2-react.tsx +++ b/scripts/apps/authoring/authoring/authoring-topbar2-react.tsx @@ -1,8 +1,7 @@ import React from 'react'; -import {IArticle} from 'superdesk-api'; +import {IArticle, IAuthoringActionType} from 'superdesk-api'; import {flatMap} from 'lodash'; import {extensions} from 'appConfig'; -import {IAuthoringAction} from './services/AuthoringWorkspaceService'; import {dataApi} from 'core/helpers/CrudManager'; import {CreatedInfo} from './created-info'; import {ModifiedInfo} from './modified-info'; @@ -11,7 +10,7 @@ const defaultToolbarItems: Array> = [Cr interface IProps { article: IArticle; - action: IAuthoringAction; + action: IAuthoringActionType; onChange(article: IArticle): void; } diff --git a/scripts/apps/authoring/authoring/services/AuthoringWorkspaceService.ts b/scripts/apps/authoring/authoring/services/AuthoringWorkspaceService.ts index 69a5f769b1..6e82484013 100644 --- a/scripts/apps/authoring/authoring/services/AuthoringWorkspaceService.ts +++ b/scripts/apps/authoring/authoring/services/AuthoringWorkspaceService.ts @@ -1,11 +1,9 @@ import {includes} from 'lodash'; -import {IArticle} from 'superdesk-api'; +import {IArticle, IAuthoringActionType} from 'superdesk-api'; import {appConfig, extensions} from 'appConfig'; import {sdApi} from 'api'; import {notNullOrUndefined} from 'core/helpers/typescript-helpers'; -export type IAuthoringAction = 'view' | 'edit' | 'kill' | 'takedown' | 'correct'; - /** * @ngdoc service * @module superdesk.apps.authoring @@ -24,7 +22,7 @@ export class AuthoringWorkspaceService { private $window: any; item: any; - action: IAuthoringAction; + action: IAuthoringActionType; state: any; widgetVisibilityCheckerFuntions: Array<(arg) => Promise>; @@ -102,7 +100,7 @@ export class AuthoringWorkspaceService { */ edit( item: {_id: IArticle['_id'], _type?: IArticle['_type'], state?: IArticle['state']}, - action?: IAuthoringAction, + action?: IAuthoringActionType, ) { if (item) { // disable edit of external ingest sources that are not editable (editFeaturedImage false or not available) @@ -320,7 +318,7 @@ export class AuthoringWorkspaceService { /** * Fetch item by id and start editing it */ - private authoringOpen(itemId, action: IAuthoringAction, repo?, state?) { + private authoringOpen(itemId, action: IAuthoringActionType, repo?, state?) { return this.authoring.open(itemId, action === 'view', repo, action, state) .then((item: IArticle) => { this.item = item; diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index cb88a2ca6a..5d14664bf0 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -2328,6 +2328,34 @@ declare module 'superdesk-api' { type IResponseHandler = (res: IRestApiResponse) => any; + export type IAuthoringActionType = + 'view' + | 'kill' + | 'correct' + | 'deschedule' + | 'unlinkUpdate' + | 'cancelCorrection' + | 'export' + | 'unspike' + | 'mark_item_for_desks' + | 'mark_item_for_highlight' + | 'new_take' + | 're_write' + | 'save' + | 'edit' + | 'mark_item' + | 'duplicate' + | 'duplicateTo' + | 'copy' + | 'package_item' + | 'multi_edit' + | 'send' + | 'create_broadcast' + | 'add_to_current' + | 'resend' + | 'set_label' + | 'takedown'; + export interface IDataProvider { update: () => void; stop: () => void; @@ -2691,7 +2719,7 @@ declare module 'superdesk-api' { isArchived(article: IArticle): boolean; isPublished(article: IArticle): boolean; - itemAction(article: IArticle): {[key: string]: boolean}; + itemAction(article: IArticle): {[key in IAuthoringActionType]: boolean}; }; contentProfile: { get(id: string): Promise;