From 528d3955e582c16ba147944701c5e1b0bed85602 Mon Sep 17 00:00:00 2001 From: Tomas Kikutis Date: Tue, 17 Dec 2024 20:55:25 +0100 Subject: [PATCH] do not require "uploadFiles" prop in EditorFieldCoverages component it can be mapped to props in child component --- .../Coverages/CoverageArrayInput.tsx | 36 ++++++++++++------- .../fields/editor/coverages.interface.ts | 1 - .../coverages/editor.tsx | 1 - 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/client/components/Coverages/CoverageArrayInput.tsx b/client/components/Coverages/CoverageArrayInput.tsx index 976b5bbbb..74842d7c7 100644 --- a/client/components/Coverages/CoverageArrayInput.tsx +++ b/client/components/Coverages/CoverageArrayInput.tsx @@ -9,7 +9,6 @@ import { ICoverageProvider, IEventItem, IFile, IG2ContentType, IGenre, - IKeyword, IPlanningCoverageItem, IPlanningItem, IPlanningNewsCoverageStatus, } from '../../interfaces'; @@ -22,9 +21,10 @@ import * as selectors from '../../selectors'; import {InputArray} from '../UI/Form'; import {CoverageEditor} from './CoverageEditor'; import {CoverageAddButton} from './CoverageAddButton'; +import planningActions from '../../actions/planning/api'; -interface IProps { +interface IOwnProps { field: string; addButtonText?: string; // defaults to 'Add a coverage' item: IPlanningItem; @@ -42,34 +42,39 @@ interface IProps { testId?: string; editorType: EDITOR_TYPE; - // Redux state + onChange(field: string, value: any): void; + popupContainer(): HTMLElement; + onPopupOpen(): void; + onPopupClose(): void; + createUploadLink(file: IFile): void; + notifyValidationErrors(errors: Array): void; +} + +interface IReduxStateProps { users: Array; desks: Array; genres: Array; coverageProviders: Array; priorities: Array; - keywords: Array; contentTypes: Array; newsCoverageStatus: Array; formProfile: ICoverageFormProfile; planningAllowScheduledUpdates: boolean; coverageAddAdvancedMode: boolean; defaultDesk: IDesk; +} - onChange(field: string, value: any): void; - popupContainer(): HTMLElement; - onPopupOpen(): void; - onPopupClose(): void; - createUploadLink(file: IFile): void; +interface IReduxDispatchProps { uploadFiles(files: Array>): Promise>; - notifyValidationErrors(errors: Array): void; } +type IProps = IOwnProps & IReduxStateProps & IReduxDispatchProps; + interface IState { openCoverageIds: Array; } -const mapStateToProps = (state) => ({ +const mapStateToProps = (state): IReduxStateProps => ({ users: selectors.general.users(state), desks: selectors.general.desks(state), genres: state.genres, @@ -83,6 +88,10 @@ const mapStateToProps = (state) => ({ defaultDesk: selectors.general.defaultDesk(state), }); +const mapDispatchToProps = (dispatch): IReduxDispatchProps => ({ + uploadFiles: (files) => dispatch(planningActions.uploadFiles({files: files})), +}); + class CoverageArrayInputComponent extends React.Component { constructor(props) { super(props); @@ -232,4 +241,7 @@ class CoverageArrayInputComponent extends React.Component { } } -export const CoverageArrayInput = connect(mapStateToProps)(CoverageArrayInputComponent); +export const CoverageArrayInput = connect( + mapStateToProps, + mapDispatchToProps, +)(CoverageArrayInputComponent); diff --git a/client/components/fields/editor/coverages.interface.ts b/client/components/fields/editor/coverages.interface.ts index 25aedd3db..1f7edc30f 100644 --- a/client/components/fields/editor/coverages.interface.ts +++ b/client/components/fields/editor/coverages.interface.ts @@ -25,7 +25,6 @@ export interface IPropsEditorFieldCoverages extends IEditorFieldProps { popupContainer?(): HTMLElement; onPopupOpen?(): void; onPopupClose?(): void; - uploadFiles(files: Array>): Promise>; notifyValidationErrors(errors: Array): void; getRef?(field: string, value: IPlanningCoverageItem): React.RefObject; } 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 e7f57d5a9..2a069e125 100644 --- a/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx +++ b/client/planning-extension/src/authoring-react-fields/coverages/editor.tsx @@ -29,7 +29,6 @@ export class Editor extends React.PureComponent { related_events: this.props.item.related_events, } as IPlanningItem} // PR-TODO: implement functions below - uploadFiles={() => Promise.resolve([])} message={{}} notifyValidationErrors={noop} onChange={(fieldPath: any, value: any) => {