Skip to content

Commit

Permalink
use EditorFieldCoverages through extensions bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis committed Dec 11, 2024
1 parent 3bbce89 commit 7c8d673
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 53 deletions.
53 changes: 3 additions & 50 deletions client/components/fields/editor/Coverages.tsx
Original file line number Diff line number Diff line change
@@ -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<void>;
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<Array<File>>): Promise<Array<IFile>>;
notifyValidationErrors(errors: Array<string>): void;
getRef?(field: string, value: IPlanningCoverageItem): React.RefObject<CoverageEditor>;
}

export class EditorFieldCoverages extends React.PureComponent<IProps> {
export class EditorFieldCoverages extends React.PureComponent<IPropsEditorFieldCoverages> {
render() {
const {gettext} = superdeskApi.localization;
const field = this.props.field ?? 'coverages';
Expand All @@ -68,6 +24,3 @@ export class EditorFieldCoverages extends React.PureComponent<IProps> {
);
}
}

// PR-TODO: pass using the bridge
window.EditorFieldCoverages = EditorFieldCoverages;
48 changes: 48 additions & 0 deletions client/components/fields/editor/coverages.interface.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
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<Array<File>>): Promise<Array<IFile>>;
notifyValidationErrors(errors: Array<string>): void;
getRef?(field: string, value: IPlanningCoverageItem): React.RefObject<CoverageEditor>;
}
12 changes: 12 additions & 0 deletions client/extension_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -38,6 +40,11 @@ interface IExtensionBridge {
planning: {
getItemPlanningInfo(item: {assignment_id?: string}): Promise<IPlanningItem>;
},
editor: {
fields: {
EditorFieldCoverages: React.ComponentType<IPropsEditorFieldCoverages>;
},
}
ui: {
utils: {
getUserInterfaceLanguageFromCV(): string;
Expand Down Expand Up @@ -91,6 +98,11 @@ export const extensionBridge: IExtensionBridge = {
planning: {
getItemPlanningInfo,
},
editor: {
fields: {
EditorFieldCoverages: EditorFieldCoverages,
},
},
ui: {
utils: {
getUserInterfaceLanguageFromCV,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,38 @@ 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<ICoveragesValueOperational, IUrlsFieldConfig, IUrlsFieldUserPreferences>;

export class Editor extends React.PureComponent<IProps> {
render() {
const Container = this.props.container;

// PR-TODO: consume from extensions bridge
const {EditorFieldCoverages} = window as any;
const {EditorFieldCoverages} = extensionBridge.editor.fields;

return (
<Container>
<EditorFieldCoverages
field='coverages'
item={{
// coverages are the main value
coverages: this.props.value,

// related_events are used if available to prefill coverage fields when adding a new coverage
related_events: this.props.item.related_events,
}}
} as IPlanningItem}
// PR-TODO: implement functions below
onAddCoverageToWorkflow={noop}
onRemoveAssignment={noop}
setCoverageDefaultDesk={noop}
setCoverageAddAdvancedMode={() => Promise.resolve()}
preferredCoverageDesks={{}}
uploadFiles={() => Promise.resolve([])}
onAddScheduledUpdateToWorkflow={noop}
message={{}}
notifyValidationErrors={noop}
onChange={(fieldPath: any, value: any) => {
/**
* sample of arguments:
Expand Down
6 changes: 6 additions & 0 deletions client/planning-extension/src/extension_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
Expand Down Expand Up @@ -32,6 +33,11 @@ interface IExtensionBridge {
planning: {
getItemPlanningInfo(item: {assignment_id?: string}): Promise<IPlanningItem>;
},
editor: {
fields: {
EditorFieldCoverages: React.ComponentType<IPropsEditorFieldCoverages>;
},
}
ui: {
utils: {
getUserInterfaceLanguageFromCV(): string;
Expand Down

0 comments on commit 7c8d673

Please sign in to comment.