Skip to content

Commit

Permalink
Authoring actions rework (#4659)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Oct 15, 2024
1 parent 7ee86b6 commit f829161
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 109 deletions.
2 changes: 1 addition & 1 deletion e2e/client/playwright/multiedit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {restoreDatabaseSnapshot, s} from './utils';
import {clearInput} from './utils/inputs';

test.describe('Multiedit', async () => {
test('editing articles in multi-edit mode', async ({page}) => {
test.skip('editing articles in multi-edit mode', async ({page}) => {
const monitoring = new Monitoring(page);
const multiedit = new MultiEdit(page);

Expand Down
25 changes: 1 addition & 24 deletions scripts/apps/authoring-react/authoring-integration-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* eslint-disable react/no-multi-comp */
/* eslint-disable no-case-declarations */
import React from 'react';
import {Map} from 'immutable';
import {
IArticle,
IAuthoringAction,
IArticleSideWidget,
IContentProfileV2,
IExtensionActivationResult,
ITopBarWidget,
IExposedFromAuthoring,
IAuthoringStorage,
Expand All @@ -20,8 +17,7 @@ import {AuthoringReact} from './authoring-react';
import {getFieldsAdapter} from './field-adapters';
import {dispatchCustomEvent} from 'core/get-superdesk-api-implementation';
import {extensions} from 'appConfig';
import {getArticleActionsFromExtensions} from 'core/superdesk-api-helpers';
import {flatMap} from 'lodash';
import {getAuthoringActionsFromExtensions} from 'core/superdesk-api-helpers';
import {gettext} from 'core/utils';
import {sdApi} from 'api';
import {
Expand All @@ -48,23 +44,6 @@ import {PINNED_WIDGET_USER_PREFERENCE_SETTINGS, closedIntentionally} from 'apps/
import {AuthoringIntegrationWrapperSidebar} from './authoring-integration-wrapper-sidebar';
import {assertNever} from 'core/helpers/typescript-helpers';

function getAuthoringActionsFromExtensions(
item: IArticle,
contentProfile: IContentProfileV2,
fieldsData: Map<string, unknown>,
): Array<IAuthoringAction> {
const actionGetters
: Array<IExtensionActivationResult['contributions']['getAuthoringActions']>
= flatMap(
Object.values(extensions),
(extension) => extension.activationResult.contributions?.getAuthoringActions ?? [],
);

return flatMap(
actionGetters.map((getPromise) => getPromise(item, contentProfile, fieldsData)),
);
}

export function getWidgetsFromExtensions(article: IArticle): Array<IArticleSideWidget> {
return Object.values(extensions)
.flatMap((extension) => extension.activationResult?.contributions?.authoringSideWidgets ?? [])
Expand Down Expand Up @@ -394,7 +373,6 @@ export class AuthoringIntegrationWrapper extends React.PureComponent<IPropsWrapp
contentProfile,
fieldsData,
);
const articleActionsFromExtensions = getArticleActionsFromExtensions(item);

return [
getSaveAsTemplate(getLatestItem),
Expand All @@ -410,7 +388,6 @@ export class AuthoringIntegrationWrapper extends React.PureComponent<IPropsWrapp
getExportModal(getLatestItem, handleUnsavedChanges, hasUnsavedChanges),
getTranslateModal(getLatestItem),
...authoringActionsFromExtensions,
...articleActionsFromExtensions,
];
}}
getSidebarWidgetsCount={({item}) => getWidgetsFromExtensions(item).length}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ export class AuthoringActionsMenu extends React.PureComponent<IProps, IState> {
{(toggle) => (
<MoreActionsButton
aria-label={gettext('Actions menu')}
ref={(el) => {
if (el != null) {
setTimeout(() => {
el.click();
});
}
}}
onClick={toggle}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions scripts/apps/authoring/authoring/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ export function getAuthoringMenuGroups(): Array<IGroup> {
{_id: 'packaging', icon: 'package-create'},
{_id: 'highlights', icon: 'star'},
{_id: 'corrections', label: gettext('Publishing actions'), concate: true},
{_id: 'planning-actions', label: gettext('Planning'), icon: 'calendar-list'},
];
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {AuthoringWorkspaceService} from '../services/AuthoringWorkspaceService';
import {getSpellchecker} from 'core/editor3/components/spellchecker/default-spellcheckers';
import {IAuthoringAction} from 'superdesk-api';
import {getArticleActionsFromExtensions} from 'core/superdesk-api-helpers';
import {getAuthoringActionsFromExtensions} from 'core/superdesk-api-helpers';
import {addInternalEventListener, dispatchInternalEvent} from 'core/internal-events';
import {appConfig} from 'appConfig';
import {ITEM_STATE} from 'apps/archive/constants';
import {IArticleActionInteractive} from 'core/interactive-article-actions-panel/interfaces';
import {IFullWidthPageCapabilityConfiguration} from 'superdesk-api';
import {sdApi} from 'api';
import {closedIntentionally} from 'apps/authoring/widgets/widgets';
import {partition} from 'lodash';

/**
* @ngdoc directive
Expand All @@ -31,7 +32,13 @@ export function AuthoringTopbarDirective(
templateUrl: 'scripts/apps/authoring/views/authoring-topbar.html',
link: function(scope) {
function setActionsFromExtensions() {
scope.articleActionsFromExtensions = getArticleActionsFromExtensions(scope.item);
const [nonPlanningActions, planningActions] = partition(
getAuthoringActionsFromExtensions(scope.item),
(action) => action.groupId !== 'planning-actions',
);

scope.nonPlanningActions = nonPlanningActions;
scope.planningActions = planningActions;
}

scope.additionalButtons = authoringWorkspace.authoringTopBarAdditionalButtons;
Expand Down Expand Up @@ -134,7 +141,7 @@ export function AuthoringTopbarDirective(
};

scope.itemActionsHighlightsSectionDisplayed = () =>
scope.articleActionsFromExtensions.some(({groupId}) => groupId === 'highlights')
scope.nonPlanningActions.some(({groupId}) => groupId === 'highlights')
|| (
scope.item.task.desk
&& (scope.itemActions.mark_item_for_desks || scope.itemActions.mark_item_for_highlight)
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion scripts/apps/authoring/authoring/directives/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ export {ItemAssociationDirective} from './ItemAssociationDirective';
export {ItemCarouselDirective} from './ItemCarouselDirective';
export {RemoveTagsDirective} from './RemoveTagsDirective';
export {TansaScopeSyncDirective} from './TansaScopeSyncDirective';
export {ItemActionsByIntentDirective} from './ItemActionsByIntentDirective';
1 change: 0 additions & 1 deletion scripts/apps/authoring/authoring/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ angular.module('superdesk.apps.authoring', [
.directive('sdItemCarousel', directive.ItemCarouselDirective)
.directive('sdRemoveTags', directive.RemoveTagsDirective)
.directive('tansaScopeSync', directive.TansaScopeSyncDirective)
.directive('sdItemActionByIntent', directive.ItemActionsByIntentDirective)
.directive('sdStaticAutocomplete', sdStaticAutocompleteDirective)

.component('sdLineCount',
Expand Down
16 changes: 11 additions & 5 deletions scripts/apps/authoring/views/authoring-topbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,20 @@
</li>
</ul>

<ul ng-if="articleActionsFromExtensions">
<li ng-repeat="action in articleActionsFromExtensions" ng-if="action.groupId !== 'highlights'">
<ul ng-if="planningActions">
<li class="dropdown__menu-divider"></li>
<li><span class="dropdown__menu-label" translate>Planning</span></li>
<li ng-repeat="action in planningActions" ng-if="action.groupId !== 'highlights'">
<button ng-click="triggerActionFromExtension(action)">{{action.label}}</button>
</li>
</ul>

<ul ng-if="nonPlanningActions">
<li ng-repeat="action in nonPlanningActions" ng-if="action.groupId !== 'highlights'">
<button ng-click="triggerActionFromExtension(action)">{{action.label}}</button>
</li>
</ul>

<ul ng-if="itemActionsHighlightsSectionDisplayed()">
<li class="dropdown__menu-divider"></li>
<li ng-if="itemActions.mark_item_for_highlight">
Expand All @@ -307,13 +315,11 @@
<ul class="dropdown__menu dropdown__menu--submenu-left" sd-mark-desks-dropdown></ul>
</div>
</li>
<li ng-repeat="action in articleActionsFromExtensions">
<li ng-repeat="action in nonPlanningActions">
<button ng-if="action.groupId === 'highlights'" ng-click="triggerActionFromExtension(action)">{{action.label}}</button>
</li>
</ul>

<span sd-item-action-by-intent sd-intent-action="external-app"></span>

<ul ng-if="isTranslationAvailable()">
<li class="dropdown__menu-divider"></li>
<li><span class="dropdown__menu-label" translate>Translations</span></li>
Expand Down
19 changes: 18 additions & 1 deletion scripts/core/superdesk-api-helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IArticle, IAuthoringAction, IExtensionActivationResult} from 'superdesk-api';
import {IArticle, IAuthoringAction, IContentProfileV2, IExtensionActivationResult} from 'superdesk-api';
import {flatMap} from 'lodash';
import {extensions} from 'appConfig';

Expand All @@ -14,3 +14,20 @@ export function getArticleActionsFromExtensions(item: IArticle): Array<IAuthorin
actionGetters.map((getAction) => getAction(item)),
);
}

export function getAuthoringActionsFromExtensions(
item: IArticle,
contentProfile?: IContentProfileV2,
fieldsData?: Immutable.Map<string, unknown>,
): Array<IAuthoringAction> {
const actionGetters
: Array<IExtensionActivationResult['contributions']['getAuthoringActions']>
= flatMap(
Object.values(extensions),
(extension) => extension.activationResult.contributions?.getAuthoringActions ?? [],
);

return flatMap(
actionGetters.map((getPromise) => getPromise(item, contentProfile, fieldsData)),
);
}

0 comments on commit f829161

Please sign in to comment.