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

Fix article content profile switch in authoring #4684

Merged
merged 8 commits into from
Nov 13, 2024
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
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),
Copy link
Member

Choose a reason for hiding this comment

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

you didn't add reinitialize to the interface.

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