From 2c1f3ac5ed4736070af84106491d478b63717c72 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Wed, 13 Nov 2024 14:59:10 +0200 Subject: [PATCH] Fix article content profile switch in authoring (#4684) --- .../authoring-integration-wrapper.tsx | 31 ++++++++++++++++++ .../apps/authoring-react/authoring-react.tsx | 32 +++++-------------- scripts/core/superdesk-api.d.ts | 3 ++ 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index f4a3f65017..37883b8c76 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -359,6 +359,37 @@ export class AuthoringIntegrationWrapper extends React.PureComponent item.extra?.[fieldId] ?? null, }} + headerToolbar={((exposed) => { + const getProfileAndReinitialize = (item: IArticle) => + this.props.authoringStorage.getContentProfile( + item, + exposed.fieldsAdapter, + ).then((profile) => { + exposed.reinitialize(item, profile); + }); + + return [{ + component: ({entity}) => ( +
+ { + const handledChanges = exposed.hasUnsavedChanges() + ? exposed.handleUnsavedChanges() + : Promise.resolve(); + + handledChanges.then(() => { + getProfileAndReinitialize(item); + }); + }} + /> +
+ ), + availableOffline: false, + group: 'start', + priority: 1, + }]; + })} getLanguage={(article) => article.language ?? 'en'} onEditingStart={(article) => { dispatchCustomEvent('articleEditStart', article); diff --git a/scripts/apps/authoring-react/authoring-react.tsx b/scripts/apps/authoring-react/authoring-react.tsx index c03676ad7f..89bc8e757c 100644 --- a/scripts/apps/authoring-react/authoring-react.tsx +++ b/scripts/apps/authoring-react/authoring-react.tsx @@ -58,7 +58,6 @@ import {IFontSizeOption, ITheme, ProofreadingThemeModal} from './toolbar/proofre import {showModal} from '@superdesk/common'; import ng from 'core/services/ng'; import {focusFirstChildInput} from 'utils/focus-first-child-input'; -import {ContentProfileDropdown} from './subcomponents/content-profile-dropdown'; export function getFieldsData( item: T, @@ -1220,6 +1219,7 @@ export class AuthoringReact extends React.PureCo pinnedId: id === activeWidgetId ? activeWidgetId : this.props.sideWidget?.pinnedId, }); }, + reinitialize: (item, profile) => this.reinitialize(state, item, profile), addValidationErrors: (moreValidationErrors) => { this.setState({ ...state, @@ -1417,13 +1417,6 @@ export class AuthoringReact extends React.PureCo const isPinned = this.props.sideWidget?.pinnedId != null; - const onChangeSideWidget = (item: T) => { - authoringStorage.getContentProfile(item, this.props.fieldsAdapter) - .then((res) => { - this.reinitialize(state, item, res); - }); - }; - return (
{ @@ -1466,10 +1459,10 @@ export class AuthoringReact extends React.PureCo reinitialize={(item) => { if (this.hasUnsavedChanges()) { exposed.handleUnsavedChanges().then(() => { - onChangeSideWidget(item); + this.reinitialize(state, item); }); } else { - onChangeSideWidget(item); + this.reinitialize(state, item); } }} item={state.itemWithChanges} @@ -1506,20 +1499,11 @@ export class AuthoringReact extends React.PureCo headerPadding={{top: 8}} authoringHeader={(
-
- { - if (this.hasUnsavedChanges()) { - exposed.handleUnsavedChanges().then(() => { - onChangeSideWidget(item); - }); - } else { - onChangeSideWidget(item); - } - }} - /> -
+ void; addValidationErrors(validationErrors: IAuthoringValidationErrors): void; } @@ -215,6 +216,8 @@ declare module 'superdesk-api' { reinitialize(itemWithChanges: T): void; }>>; + headerToolbar?: (options: IExposedFromAuthoring) => Array>; + disableWidgetPinning?: boolean; // defaults to false getSidebarWidgetsCount(options: IExposedFromAuthoring): number;