From 92c036af10ed786c1e03f6eef73f165d51d3a2ae Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Mon, 11 Nov 2024 14:00:44 +0200 Subject: [PATCH 1/7] Fix article content profile switch in authoring --- .../authoring-integration-wrapper.tsx | 20 ++++++++- .../apps/authoring-react/authoring-react.tsx | 41 ++++++++----------- scripts/core/superdesk-api.d.ts | 3 ++ 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index 157c7f9acf..f570bc38c9 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -56,8 +56,8 @@ const defaultToolbarItems: Array void; }>> = [ - CreatedModifiedInfo, -]; + CreatedModifiedInfo, + ]; interface IProps { itemId: IArticle['_id']; @@ -361,6 +361,22 @@ export class AuthoringIntegrationWrapper extends React.PureComponent { dispatchCustomEvent('articleEditEnd', article); }} + customHeader={((options) => ( +
+ { + if (options.hasUnsavedChanges()) { + options.handleUnsavedChanges().then(() => { + options.onChangeToolbarWidget(item); + }); + } else { + options.onChangeToolbarWidget(item); + } + }} + /> +
+ ))} getActions={({ item, contentProfile, diff --git a/scripts/apps/authoring-react/authoring-react.tsx b/scripts/apps/authoring-react/authoring-react.tsx index 08264f2c62..5257c862b2 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, @@ -309,6 +308,7 @@ export class AuthoringReact extends React.PureCo this.setLoadingState = this.setLoadingState.bind(this); this.reinitialize = this.reinitialize.bind(this); this.setRef = this.setRef.bind(this); + this.onChangeToolbarWidget = this.onChangeToolbarWidget.bind(this); const setStateOriginal = this.setState.bind(this); @@ -1175,6 +1175,18 @@ export class AuthoringReact extends React.PureCo )); } + + onChangeToolbarWidget(item: T) { + const state = this.state; + + if (state.initialized === true) { + this.props.authoringStorage.getContentProfile(item, this.props.fieldsAdapter) + .then((res) => { + this.reinitialize(state, item, res); + }); + } + }; + render() { const state = this.state; const {authoringStorage, fieldsAdapter, storageAdapter, getLanguage, getSidePanel} = this.props; @@ -1219,6 +1231,7 @@ export class AuthoringReact extends React.PureCo }); } }, + onChangeToolbarWidget: this.onChangeToolbarWidget, addValidationErrors: (moreValidationErrors) => { this.setState({ ...state, @@ -1416,13 +1429,6 @@ export class AuthoringReact extends React.PureCo }, }; - const onChangeSideWidget = (item: T) => { - authoringStorage.getContentProfile(item, this.props.fieldsAdapter) - .then((res) => { - this.reinitialize(state, item, res); - }); - }; - return (
{ @@ -1465,10 +1471,10 @@ export class AuthoringReact extends React.PureCo reinitialize={(item) => { if (this.hasUnsavedChanges()) { exposed.handleUnsavedChanges().then(() => { - onChangeSideWidget(item); + this.onChangeToolbarWidget(item); }); } else { - onChangeSideWidget(item); + this.onChangeToolbarWidget(item); } }} item={state.itemWithChanges} @@ -1505,20 +1511,7 @@ export class AuthoringReact extends React.PureCo headerPadding={{top: 8}} authoringHeader={(
-
- { - if (this.hasUnsavedChanges()) { - exposed.handleUnsavedChanges().then(() => { - onChangeSideWidget(item); - }); - } else { - onChangeSideWidget(item); - } - }} - /> -
+ {this.props.customHeader(exposed)} >; + customHeader?: (options: IExposedFromAuthoring) => JSX.Element; + disableWidgetPinning?: boolean; // defaults to false getSidebarWidgetsCount(options: IExposedFromAuthoring): number; From bd800ca06537d51881492d2bf51b6a1e393eb01e Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Mon, 11 Nov 2024 14:02:50 +0200 Subject: [PATCH 2/7] Fix lint --- .../apps/authoring-react/authoring-integration-wrapper.tsx | 4 ++-- scripts/apps/authoring-react/authoring-react.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index f570bc38c9..776ef65f7f 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -56,8 +56,8 @@ const defaultToolbarItems: Array void; }>> = [ - CreatedModifiedInfo, - ]; + CreatedModifiedInfo, +]; interface IProps { itemId: IArticle['_id']; diff --git a/scripts/apps/authoring-react/authoring-react.tsx b/scripts/apps/authoring-react/authoring-react.tsx index 5257c862b2..8abd36802c 100644 --- a/scripts/apps/authoring-react/authoring-react.tsx +++ b/scripts/apps/authoring-react/authoring-react.tsx @@ -1185,7 +1185,7 @@ export class AuthoringReact extends React.PureCo this.reinitialize(state, item, res); }); } - }; + } render() { const state = this.state; From fd9c4e5541a41e89653109ba33d9874c82594f5b Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Wed, 13 Nov 2024 09:29:30 +0200 Subject: [PATCH 3/7] Changes after review --- .../authoring-integration-wrapper.tsx | 41 +++++++++++-------- .../apps/authoring-react/authoring-react.tsx | 6 ++- scripts/core/superdesk-api.d.ts | 2 +- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index dfb412af4d..334f2c9b4f 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -56,8 +56,8 @@ const defaultToolbarItems: Array void; }>> = [ - CreatedModifiedInfo, -]; + CreatedModifiedInfo, + ]; interface IProps { itemId: IArticle['_id']; @@ -359,22 +359,27 @@ export class AuthoringIntegrationWrapper extends React.PureComponent item.extra?.[fieldId] ?? null, }} - customHeader={((options) => ( -
- { - if (options.hasUnsavedChanges()) { - options.handleUnsavedChanges().then(() => { - options.onChangeToolbarWidget(item); - }); - } else { - options.onChangeToolbarWidget(item); - } - }} - /> -
- ))} + customHeader={((exposed) => [{ + component: ({entity}) => ( +
+ { + if (exposed.hasUnsavedChanges()) { + exposed.handleUnsavedChanges().then(() => { + exposed.onChangeToolbarWidget(item); + }); + } else { + exposed.onChangeToolbarWidget(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 0f4a09eaeb..0e3a2c6e47 100644 --- a/scripts/apps/authoring-react/authoring-react.tsx +++ b/scripts/apps/authoring-react/authoring-react.tsx @@ -1512,7 +1512,11 @@ export class AuthoringReact extends React.PureCo headerPadding={{top: 8}} authoringHeader={(
- {this.props.customHeader(exposed)} + >; - customHeader?: (options: IExposedFromAuthoring) => JSX.Element; + customHeader?: (options: IExposedFromAuthoring) => Array>; disableWidgetPinning?: boolean; // defaults to false From cfdac74fceeca8320a9ffff7110c48222c9d9e13 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Wed, 13 Nov 2024 10:36:14 +0200 Subject: [PATCH 4/7] Lint --- .../apps/authoring-react/authoring-integration-wrapper.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index 334f2c9b4f..3f9d9889e5 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -56,8 +56,8 @@ const defaultToolbarItems: Array void; }>> = [ - CreatedModifiedInfo, - ]; + CreatedModifiedInfo, +]; interface IProps { itemId: IArticle['_id']; @@ -378,7 +378,7 @@ export class AuthoringIntegrationWrapper extends React.PureComponent article.language ?? 'en'} onEditingStart={(article) => { From d0f3fa6edf94ffa95f89a3a098ba9889d0ec8546 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Wed, 13 Nov 2024 11:58:22 +0200 Subject: [PATCH 5/7] Changes v2 --- .../authoring-integration-wrapper.tsx | 52 +++++++++++-------- .../apps/authoring-react/authoring-react.tsx | 19 ++----- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index 3f9d9889e5..4256bf316d 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -359,27 +359,37 @@ export class AuthoringIntegrationWrapper extends React.PureComponent item.extra?.[fieldId] ?? null, }} - customHeader={((exposed) => [{ - component: ({entity}) => ( -
- { - if (exposed.hasUnsavedChanges()) { - exposed.handleUnsavedChanges().then(() => { - exposed.onChangeToolbarWidget(item); - }); - } else { - exposed.onChangeToolbarWidget(item); - } - }} - /> -
- ), - availableOffline: false, - group: 'start', - priority: 1, - }])} + customHeader={((exposed) => { + const getProfileAndReinitialize = (item: IArticle) => + this.props.authoringStorage.getContentProfile( + item, + exposed.fieldsAdapter, + ).then((profile) => { + exposed.reinitialize(item, profile); + }); + + return [{ + component: ({entity}) => ( +
+ { + if (exposed.hasUnsavedChanges()) { + exposed.handleUnsavedChanges().then(() => { + getProfileAndReinitialize(item); + }); + } else { + 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 0e3a2c6e47..025ba84209 100644 --- a/scripts/apps/authoring-react/authoring-react.tsx +++ b/scripts/apps/authoring-react/authoring-react.tsx @@ -308,7 +308,6 @@ export class AuthoringReact extends React.PureCo this.setLoadingState = this.setLoadingState.bind(this); this.reinitialize = this.reinitialize.bind(this); this.setRef = this.setRef.bind(this); - this.onChangeToolbarWidget = this.onChangeToolbarWidget.bind(this); const setStateOriginal = this.setState.bind(this); @@ -1178,18 +1177,6 @@ export class AuthoringReact extends React.PureCo )); } - - onChangeToolbarWidget(item: T) { - const state = this.state; - - if (state.initialized === true) { - this.props.authoringStorage.getContentProfile(item, this.props.fieldsAdapter) - .then((res) => { - this.reinitialize(state, item, res); - }); - } - } - render() { const state = this.state; const {authoringStorage, fieldsAdapter, storageAdapter, getLanguage, getSidePanel} = this.props; @@ -1232,7 +1219,7 @@ export class AuthoringReact extends React.PureCo pinnedId: id === activeWidgetId ? activeWidgetId : this.props.sideWidget?.pinnedId, }); }, - onChangeToolbarWidget: this.onChangeToolbarWidget, + reinitialize: (item, profile) => this.reinitialize(state, item, profile), addValidationErrors: (moreValidationErrors) => { this.setState({ ...state, @@ -1472,10 +1459,10 @@ export class AuthoringReact extends React.PureCo reinitialize={(item) => { if (this.hasUnsavedChanges()) { exposed.handleUnsavedChanges().then(() => { - this.onChangeToolbarWidget(item); + this.reinitialize(state, item); }); } else { - this.onChangeToolbarWidget(item); + this.reinitialize(state, item); } }} item={state.itemWithChanges} From 0164e43d783f31d6cf8781b26dc3fde461641dfe Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Wed, 13 Nov 2024 13:56:28 +0200 Subject: [PATCH 6/7] Changes after review --- .../authoring-integration-wrapper.tsx | 14 +++++++------- scripts/apps/authoring-react/authoring-react.tsx | 2 +- scripts/core/superdesk-api.d.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index 4256bf316d..c9cb74e605 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -359,7 +359,7 @@ export class AuthoringIntegrationWrapper extends React.PureComponent item.extra?.[fieldId] ?? null, }} - customHeader={((exposed) => { + headerToolbar={((exposed) => { const getProfileAndReinitialize = (item: IArticle) => this.props.authoringStorage.getContentProfile( item, @@ -374,13 +374,13 @@ export class AuthoringIntegrationWrapper extends React.PureComponent { - if (exposed.hasUnsavedChanges()) { - exposed.handleUnsavedChanges().then(() => { - getProfileAndReinitialize(item); - }); - } else { + const handledChanges = exposed.hasUnsavedChanges() + ? exposed.handleUnsavedChanges() + : Promise.resolve(); + + handledChanges.then(() => { getProfileAndReinitialize(item); - } + }); }} />
diff --git a/scripts/apps/authoring-react/authoring-react.tsx b/scripts/apps/authoring-react/authoring-react.tsx index 025ba84209..89bc8e757c 100644 --- a/scripts/apps/authoring-react/authoring-react.tsx +++ b/scripts/apps/authoring-react/authoring-react.tsx @@ -1501,7 +1501,7 @@ export class AuthoringReact extends React.PureCo
void; addValidationErrors(validationErrors: IAuthoringValidationErrors): void; } @@ -216,7 +216,7 @@ declare module 'superdesk-api' { reinitialize(itemWithChanges: T): void; }>>; - customHeader?: (options: IExposedFromAuthoring) => Array>; + headerToolbar?: (options: IExposedFromAuthoring) => Array>; disableWidgetPinning?: boolean; // defaults to false From dd1a1f81e691543b6253ad30dc8c9a39e4309d0c Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Wed, 13 Nov 2024 14:12:14 +0200 Subject: [PATCH 7/7] Fix lint --- scripts/apps/authoring-react/authoring-integration-wrapper.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index c9cb74e605..37883b8c76 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -388,7 +388,7 @@ export class AuthoringIntegrationWrapper extends React.PureComponent article.language ?? 'en'} onEditingStart={(article) => {