diff --git a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx index 73cb637dff..bea368ab5b 100644 --- a/scripts/apps/authoring-react/authoring-integration-wrapper.tsx +++ b/scripts/apps/authoring-react/authoring-integration-wrapper.tsx @@ -34,6 +34,8 @@ import {dispatchInternalEvent} from 'core/internal-events'; import {IArticleActionInteractive} from 'core/interactive-article-actions-panel/interfaces'; import {ARTICLE_RELATED_RESOURCE_NAMES} from 'core/constants'; import {IProps} from './authoring-angular-integration'; +import {showModal} from '@superdesk/common'; +import ExportModal from './toolbar/export-modal'; function getAuthoringActionsFromExtensions( item: IArticle, @@ -103,6 +105,30 @@ function getPublishToolbarWidget( return publishWidgetButton; } +const getExportModal = ( + getLatestItem: () => IArticle, + handleUnsavedChanges: () => Promise, + hasUnsavedChanges: () => boolean, +): IAuthoringAction => ({ + label: gettext('Export'), + onTrigger: () => { + const openModal = (article: IArticle) => showModal(({closeModal}) => { + return ( + + ); + }); + + if (hasUnsavedChanges()) { + handleUnsavedChanges().then((article) => openModal(article)); + } else { + openModal(getLatestItem()); + } + }, +}); + interface IPropsWrapper extends IProps { onClose?(): void; getInlineToolbarActions?(options: IExposedFromAuthoring): { @@ -228,7 +254,14 @@ export class AuthoringIntegrationWrapper extends React.PureComponent { dispatchCustomEvent('articleEditEnd', article); }} - getActions={({item, contentProfile, fieldsData}) => { + getActions={({ + item, + contentProfile, + fieldsData, + getLatestItem, + handleUnsavedChanges, + hasUnsavedChanges, + }) => { return Promise.all([ getAuthoringActionsFromExtensions(item, contentProfile, fieldsData), getArticleActionsFromExtensions(item), @@ -236,6 +269,7 @@ export class AuthoringIntegrationWrapper extends React.PureComponent | null; +} + +type IState = IStateLoaded | IStateLoading; + +export default class ExportModal extends React.PureComponent { + constructor(props: IProps) { + super(props); + + this.state = { + initialized: false, + }; + + this.exportArticle = this.exportArticle.bind(this); + } + + componentDidMount(): void { + httpRequestJsonLocal>({ + method: 'GET', + path: '/formatters', + urlParams: { + criteria: 'can_export', + }, + }).then((result) => { + this.setState({ + ...this.state, + initialized: true, + availableFormatters: result._items, + }); + }); + } + + private exportArticle() { + if (this.state.initialized) { + return httpRequestJsonLocal({ + method: 'POST', + path: '/export', + payload: { + item_ids: [this.props.article._id], + validate: this.state.validate, + format_type: this.state.selectedFormatter, + }, + }).then((response: any) => { + window.open(response.url); + this.props.closeModal(); + }); + } + } + + render(): JSX.Element { + const state = this.state; + + if (!state.initialized) { + return null; + } + + return ( + + + + this.setState({...state, validate: value})} + /> + +