Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add item action to superdesk api #4366

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion scripts/api/article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -378,6 +385,12 @@ function get(id: IArticle['_id']): Promise<IArticle> {
return dataApi.findOne<IArticle>('archive', id);
}

function itemAction(_article: IArticle): {[key in IAuthoringActionType]: boolean} {
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');
Expand Down Expand Up @@ -424,6 +437,7 @@ interface IArticleApi {
*/
isPublished(article: IArticle, includeScheduled?: boolean): boolean;

itemAction(article: IArticle): {[key in IAuthoringActionType]: boolean};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid repeating the type you could use ReturnType<typeof itemAction>. If it was repeated more heavily I'd suggest to create another type like type IItemActionsResult = {[key in IAuthoringActionType]: boolean}

isKilled(article: IArticle): boolean;
isIngested(article: IArticle): boolean;
isPersonal(article: IArticle): boolean;
Expand Down Expand Up @@ -491,6 +505,7 @@ export const article: IArticleApi = {
rewrite,
isLocked,
isEditable,
itemAction,
isLockedInCurrentSession,
isLockedInOtherSession,
isLockedByCurrentUser,
Expand Down
5 changes: 2 additions & 3 deletions scripts/apps/authoring/authoring/authoring-topbar-react.tsx
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
5 changes: 2 additions & 3 deletions scripts/apps/authoring/authoring/authoring-topbar2-react.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -11,7 +10,7 @@ const defaultToolbarItems: Array<React.ComponentType<{article: IArticle}>> = [Cr

interface IProps {
article: IArticle;
action: IAuthoringAction;
action: IAuthoringActionType;
onChange(article: IArticle): void;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,7 +22,7 @@ export class AuthoringWorkspaceService {
private $window: any;

item: any;
action: IAuthoringAction;
action: IAuthoringActionType;
state: any;

widgetVisibilityCheckerFuntions: Array<(arg) => Promise<boolean>>;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions scripts/core/get-superdesk-api-implementation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
29 changes: 29 additions & 0 deletions scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2328,6 +2328,34 @@ declare module 'superdesk-api' {

type IResponseHandler = (res: IRestApiResponse<T>) => 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;
Expand Down Expand Up @@ -2691,6 +2719,7 @@ declare module 'superdesk-api' {

isArchived(article: IArticle): boolean;
isPublished(article: IArticle): boolean;
itemAction(article: IArticle): {[key in IAuthoringActionType]: boolean};
};
contentProfile: {
get(id: string): Promise<IContentProfile>;
Expand Down
Loading