Skip to content

Commit

Permalink
[SDESK-7299] fix: Load ContentProfile after loading article in AddToP…
Browse files Browse the repository at this point in the history
…lanning (#2037)
  • Loading branch information
MarkLark86 authored Jul 24, 2024
1 parent a91cbfd commit 1280faa
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions client/controllers/AddToPlanningController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {get, isEmpty, isNumber} from 'lodash';
import {registerNotifications, getErrorMessage, isExistingItem} from '../utils';
import {WORKSPACE, MODALS, MAIN} from '../constants';
import {GET_LABEL_MAP} from 'superdesk-core/scripts/apps/workspace/content/constants';
import {IArticle, IContentProfile} from 'superdesk-api';
import {planningApi, superdeskApi} from '../superdeskApi';

const DEFAULT_PLANNING_SCHEMA = {
Expand Down Expand Up @@ -191,12 +192,36 @@ export class AddToPlanningController {
}
}

getArchiveItemAndProfile(): Promise<{
newsItem: IArticle,
contentProfile: IContentProfile
}> {
return this.api.find('archive', this.item._id)
.then((newsItem: IArticle) => (
superdeskApi.entities.contentProfile.get(newsItem.profile)
.then((contentProfile) => ({
newsItem,
contentProfile,
}))
.catch((error) => {
this.notify.error(
getErrorMessage(error, this.gettext('Failed to load content profile.'))
);
this.$scope.resolve(error);
return Promise.reject(error);
})
), (error) => {
this.notify.error(
getErrorMessage(error, this.gettext('Failed to load the item.'))
);
this.$scope.resolve(error);
return Promise.reject(error);
});
}

loadArchiveItem() {
return Promise.all([
superdeskApi.entities.contentProfile.get(this.item.profile),
this.api.find('archive', this.item._id),
])
.then(([contentProfile, newsItem]) => {
return this.getArchiveItemAndProfile()
.then(({newsItem, contentProfile}) => {
const errMessages = [];
const profile = planningProfile(this.store.getState());
const planningSchema = profile.schema || DEFAULT_PLANNING_SCHEMA;
Expand Down Expand Up @@ -252,12 +277,6 @@ export class AddToPlanningController {
}

return Promise.resolve(newsItem);
}, (error) => {
this.notify.error(
getErrorMessage(error, this.gettext('Failed to load the item.'))
);
this.$scope.resolve(error);
return Promise.reject(error);
});
}
}
Expand Down

0 comments on commit 1280faa

Please sign in to comment.