Skip to content

Commit

Permalink
Fix article content profile switch in authoring (#4684)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Nov 13, 2024
1 parent 3c8a335 commit 2c1f3ac
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
31 changes: 31 additions & 0 deletions scripts/apps/authoring-react/authoring-integration-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,37 @@ export class AuthoringIntegrationWrapper extends React.PureComponent<IPropsWrapp
},
retrieveStoredValue: (item: IArticle, fieldId) => 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}) => (
<div className="authoring-header__general-info">
<ContentProfileDropdown
item={entity}
reinitialize={(item) => {
const handledChanges = exposed.hasUnsavedChanges()
? exposed.handleUnsavedChanges()
: Promise.resolve();

handledChanges.then(() => {
getProfileAndReinitialize(item);
});
}}
/>
</div>
),
availableOffline: false,
group: 'start',
priority: 1,
}];
})}
getLanguage={(article) => article.language ?? 'en'}
onEditingStart={(article) => {
dispatchCustomEvent('articleEditStart', article);
Expand Down
32 changes: 8 additions & 24 deletions scripts/apps/authoring-react/authoring-react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
item: T,
Expand Down Expand Up @@ -1220,6 +1219,7 @@ export class AuthoringReact<T extends IBaseRestApiResponse> extends React.PureCo
pinnedId: id === activeWidgetId ? activeWidgetId : this.props.sideWidget?.pinnedId,
});
},
reinitialize: (item, profile) => this.reinitialize(state, item, profile),
addValidationErrors: (moreValidationErrors) => {
this.setState({
...state,
Expand Down Expand Up @@ -1417,13 +1417,6 @@ export class AuthoringReact<T extends IBaseRestApiResponse> 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 (
<div style={{display: 'contents'}} ref={this.setRef}>
{
Expand Down Expand Up @@ -1466,10 +1459,10 @@ export class AuthoringReact<T extends IBaseRestApiResponse> 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}
Expand Down Expand Up @@ -1506,20 +1499,11 @@ export class AuthoringReact<T extends IBaseRestApiResponse> extends React.PureCo
headerPadding={{top: 8}}
authoringHeader={(
<div style={{width: '100%'}}>
<div className="authoring-header__general-info">
<ContentProfileDropdown
item={state.itemWithChanges}
reinitialize={(item) => {
if (this.hasUnsavedChanges()) {
exposed.handleUnsavedChanges().then(() => {
onChangeSideWidget(item);
});
} else {
onChangeSideWidget(item);
}
}}
/>
</div>
<AuthoringToolbar
entity={state.itemWithChanges}
coreWidgets={this.props.headerToolbar(exposed)}
backgroundColor={authoringOptions?.toolbarBgColor}
/>
<AuthoringSection
fields={state.profile.header}
fieldsData={state.fieldsDataWithChanges}
Expand Down
3 changes: 3 additions & 0 deletions scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ declare module 'superdesk-api' {
initiateClosing(): void;
keepChangesAndClose(): void;
stealLock(): void;
reinitialize: (item: T, profile?: IContentProfileV2) => void;
addValidationErrors(validationErrors: IAuthoringValidationErrors): void;
}

Expand Down Expand Up @@ -215,6 +216,8 @@ declare module 'superdesk-api' {
reinitialize(itemWithChanges: T): void;
}>>;

headerToolbar?: (options: IExposedFromAuthoring<T>) => Array<ITopBarWidget<T>>;

disableWidgetPinning?: boolean; // defaults to false

getSidebarWidgetsCount(options: IExposedFromAuthoring<T>): number;
Expand Down

0 comments on commit 2c1f3ac

Please sign in to comment.