From 7c8d673ab09bcce2bd0e59f4702ba7fc9a761948 Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Wed, 11 Dec 2024 18:06:22 +0100 Subject: [PATCH] use EditorFieldCoverages through extensions bridge --- client/components/fields/editor/Coverages.tsx | 53 ++----------------- .../fields/editor/coverages.interface.ts | 48 +++++++++++++++++ client/extension_bridge.ts | 12 +++++ .../coverages/editor.tsx | 14 +++-- .../src/extension_bridge.ts | 6 +++ 5 files changed, 80 insertions(+), 53 deletions(-) create mode 100644 client/components/fields/editor/coverages.interface.ts diff --git a/client/components/fields/editor/Coverages.tsx b/client/components/fields/editor/Coverages.tsx index 84a0a0769..e36aa92d8 100644 --- a/client/components/fields/editor/Coverages.tsx +++ b/client/components/fields/editor/Coverages.tsx @@ -1,57 +1,13 @@ import * as React from 'react'; import {get} from 'lodash'; -import { - ICoverageScheduledUpdate, - IEditorFieldProps, - IEventItem, IFile, - IG2ContentType, - IPlanningCoverageItem, - IPlanningItem -} from '../../../interfaces'; -import {IArticle} from 'superdesk-api'; import {superdeskApi} from '../../../superdeskApi'; -import {CoverageArrayInput, CoverageEditor} from '../../Coverages'; +import {CoverageArrayInput} from '../../Coverages'; import {getFileDownloadURL} from '../../../utils'; +import {IPropsEditorFieldCoverages} from './coverages.interface'; -interface IProps extends IEditorFieldProps { - item: IPlanningItem; - addButtonText?: string; // defaults to 'Add a coverage' - addNewsItemToPlanning?: IArticle; - useLocalNavigation?: boolean; - navigation?: any; - maxCoverageCount?: number; - addOnly?: boolean; - originalCount?: number; - message: string | {[key: string]: any}; - event?: IEventItem; - preferredCoverageDesks: {[key: string]: string}; - - popupContainer?(): HTMLElement; - onPopupOpen?(): void; - onPopupClose?(): void; - setCoverageDefaultDesk(coverage: IPlanningCoverageItem): void; - setCoverageAddAdvancedMode(enabled: boolean): Promise; - onAddCoverageToWorkflow(coverage: IPlanningCoverageItem, index: number): void; - onAddScheduledUpdateToWorkflow( - coverage: IPlanningCoverageItem, - index: number, - scheduledUpdate?: ICoverageScheduledUpdate, - scheduledUpdateIndex?: number - ): void; - onRemoveAssignment( - coverage: IPlanningCoverageItem, - index: number, - scheduledUpdate?: ICoverageScheduledUpdate, - scheduledUpdateIndex?: number - ): void; - uploadFiles(files: Array>): Promise>; - notifyValidationErrors(errors: Array): void; - getRef?(field: string, value: IPlanningCoverageItem): React.RefObject; -} - -export class EditorFieldCoverages extends React.PureComponent { +export class EditorFieldCoverages extends React.PureComponent { render() { const {gettext} = superdeskApi.localization; const field = this.props.field ?? 'coverages'; @@ -68,6 +24,3 @@ export class EditorFieldCoverages extends React.PureComponent { ); } } - -// PR-TODO: pass using the bridge -window.EditorFieldCoverages = EditorFieldCoverages; \ No newline at end of file diff --git a/client/components/fields/editor/coverages.interface.ts b/client/components/fields/editor/coverages.interface.ts new file mode 100644 index 000000000..57e258731 --- /dev/null +++ b/client/components/fields/editor/coverages.interface.ts @@ -0,0 +1,48 @@ +import { + ICoverageScheduledUpdate, + IEditorFieldProps, + IEventItem, IFile, + IPlanningCoverageItem, + IPlanningItem +} from '../../../interfaces'; +import {IArticle} from 'superdesk-api'; + + +// can't import CoverageEditor from '../../Coverages' because it would break compilation of planning extension +type CoverageEditor = any; + +export interface IPropsEditorFieldCoverages extends IEditorFieldProps { + item: IPlanningItem; + addButtonText?: string; // defaults to 'Add a coverage' + addNewsItemToPlanning?: IArticle; + useLocalNavigation?: boolean; + navigation?: any; + maxCoverageCount?: number; + addOnly?: boolean; + originalCount?: number; + message: string | {[key: string]: any}; + event?: IEventItem; + preferredCoverageDesks: {[key: string]: string}; + + popupContainer?(): HTMLElement; + onPopupOpen?(): void; + onPopupClose?(): void; + setCoverageDefaultDesk(coverage: IPlanningCoverageItem): void; + setCoverageAddAdvancedMode(enabled: boolean): Promise; + onAddCoverageToWorkflow(coverage: IPlanningCoverageItem, index: number): void; + onAddScheduledUpdateToWorkflow( + coverage: IPlanningCoverageItem, + index: number, + scheduledUpdate?: ICoverageScheduledUpdate, + scheduledUpdateIndex?: number + ): void; + onRemoveAssignment( + coverage: IPlanningCoverageItem, + index: number, + scheduledUpdate?: ICoverageScheduledUpdate, + scheduledUpdateIndex?: number + ): void; + uploadFiles(files: Array>): Promise>; + notifyValidationErrors(errors: Array): void; + getRef?(field: string, value: IPlanningCoverageItem): React.RefObject; +} diff --git a/client/extension_bridge.ts b/client/extension_bridge.ts index bc91fb73c..8ff21b144 100644 --- a/client/extension_bridge.ts +++ b/client/extension_bridge.ts @@ -18,6 +18,8 @@ import {isContentLinkToCoverageAllowed} from './utils/archive'; import PlanningDetailsWidget, {getItemPlanningInfo} from './components/PlanningDetailsWidget'; import {AttachmentsInputStandalone} from './components/AttachmentsInputStandalone'; import {IPropsAttachmentsEditorStandalone} from './components/AttachmentsInputStandalone.interface'; +import {IPropsEditorFieldCoverages} from './components/fields/editor/coverages.interface'; +import {EditorFieldCoverages} from './components/fields/editor/Coverages'; // KEEP IN SYNC WITH client/planning-extension/src/extension_bridge.ts interface IExtensionBridge { @@ -38,6 +40,11 @@ interface IExtensionBridge { planning: { getItemPlanningInfo(item: {assignment_id?: string}): Promise; }, + editor: { + fields: { + EditorFieldCoverages: React.ComponentType; + }, + } ui: { utils: { getUserInterfaceLanguageFromCV(): string; @@ -91,6 +98,11 @@ export const extensionBridge: IExtensionBridge = { planning: { getItemPlanningInfo, }, + editor: { + fields: { + EditorFieldCoverages: EditorFieldCoverages, + }, + }, ui: { utils: { getUserInterfaceLanguageFromCV, diff --git a/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx b/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx index 8b80d1f4d..22560377a 100644 --- a/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx +++ b/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx @@ -6,6 +6,8 @@ import { } from 'superdesk-api'; import {ICoveragesValueOperational} from './interfaces'; import {cloneDeep, noop, set} from 'lodash'; +import {extensionBridge} from '../../extension_bridge'; +import {IPlanningItem} from '../../../../interfaces'; type IProps = IEditorComponentProps; @@ -13,23 +15,29 @@ export class Editor extends React.PureComponent { render() { const Container = this.props.container; - // PR-TODO: consume from extensions bridge - const {EditorFieldCoverages} = window as any; + const {EditorFieldCoverages} = extensionBridge.editor.fields; return ( Promise.resolve()} + preferredCoverageDesks={{}} + uploadFiles={() => Promise.resolve([])} + onAddScheduledUpdateToWorkflow={noop} + message={{}} + notifyValidationErrors={noop} onChange={(fieldPath: any, value: any) => { /** * sample of arguments: diff --git a/client/planning-extension/src/extension_bridge.ts b/client/planning-extension/src/extension_bridge.ts index bc0b5b517..08656bde3 100644 --- a/client/planning-extension/src/extension_bridge.ts +++ b/client/planning-extension/src/extension_bridge.ts @@ -2,6 +2,7 @@ import * as React from 'react'; import {IArticle, IVocabularyItem} from 'superdesk-api'; import {IAssignmentItem, IEditorFieldProps, IPlanningAppState, IPlanningItem} from '../../interfaces'; import {IPropsAttachmentsEditorStandalone} from '../../components/AttachmentsInputStandalone.interface'; +import {IPropsEditorFieldCoverages} from '../../components/fields/editor/coverages.interface' interface IEditorFieldVocabularyProps extends IEditorFieldProps { options: Array; @@ -32,6 +33,11 @@ interface IExtensionBridge { planning: { getItemPlanningInfo(item: {assignment_id?: string}): Promise; }, + editor: { + fields: { + EditorFieldCoverages: React.ComponentType; + }, + } ui: { utils: { getUserInterfaceLanguageFromCV(): string;