Skip to content

Commit

Permalink
do not require "uploadFiles" prop in EditorFieldCoverages component
Browse files Browse the repository at this point in the history
it can be mapped to props in child component
  • Loading branch information
tomaskikutis committed Dec 17, 2024
1 parent da94fcf commit 528d395
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
36 changes: 24 additions & 12 deletions client/components/Coverages/CoverageArrayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
ICoverageProvider, IEventItem, IFile,
IG2ContentType,
IGenre,
IKeyword,
IPlanningCoverageItem, IPlanningItem,
IPlanningNewsCoverageStatus,
} from '../../interfaces';
Expand All @@ -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;
Expand All @@ -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<string>): void;
}

interface IReduxStateProps {
users: Array<IUser>;
desks: Array<IDesk>;
genres: Array<IGenre>;
coverageProviders: Array<ICoverageProvider>;
priorities: Array<IAssignmentPriority>;
keywords: Array<IKeyword>;
contentTypes: Array<IG2ContentType>;
newsCoverageStatus: Array<IPlanningNewsCoverageStatus>;
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<Array<File>>): Promise<Array<IFile>>;
notifyValidationErrors(errors: Array<string>): void;
}

type IProps = IOwnProps & IReduxStateProps & IReduxDispatchProps;

interface IState {
openCoverageIds: Array<IPlanningCoverageItem['coverage_id']>;
}

const mapStateToProps = (state) => ({
const mapStateToProps = (state): IReduxStateProps => ({
users: selectors.general.users(state),
desks: selectors.general.desks(state),
genres: state.genres,
Expand All @@ -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<IProps, IState> {
constructor(props) {
super(props);
Expand Down Expand Up @@ -232,4 +241,7 @@ class CoverageArrayInputComponent extends React.Component<IProps, IState> {
}
}

export const CoverageArrayInput = connect(mapStateToProps)(CoverageArrayInputComponent);
export const CoverageArrayInput = connect<IReduxStateProps, IReduxDispatchProps, IOwnProps>(
mapStateToProps,
mapDispatchToProps,
)(CoverageArrayInputComponent);
1 change: 0 additions & 1 deletion client/components/fields/editor/coverages.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface IPropsEditorFieldCoverages extends IEditorFieldProps {
popupContainer?(): HTMLElement;
onPopupOpen?(): void;
onPopupClose?(): void;
uploadFiles(files: Array<Array<File>>): Promise<Array<IFile>>;
notifyValidationErrors(errors: Array<string>): void;
getRef?(field: string, value: IPlanningCoverageItem): React.RefObject<CoverageEditor>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class Editor extends React.PureComponent<IProps> {
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) => {
Expand Down

0 comments on commit 528d395

Please sign in to comment.