From d06ca80ae34bdd7d9c97b13938a418499fbf5ca4 Mon Sep 17 00:00:00 2001 From: Konstantin Markov Date: Tue, 25 Jun 2024 12:01:30 +0300 Subject: [PATCH] Improve desk select (#2002) --- .../components/Planning/PlanningDateTime.tsx | 34 ++++++++++------- client/components/Planning/PlanningItem.tsx | 1 + client/components/UI/List/Column.tsx | 38 ++++++++++--------- client/components/UI/List/Row.tsx | 28 +++++--------- client/components/fields/coverages.tsx | 3 ++ .../EmbeddedCoverageForm.tsx | 28 +++++++++++--- client/utils/index.ts | 5 ++- 7 files changed, 81 insertions(+), 56 deletions(-) diff --git a/client/components/Planning/PlanningDateTime.tsx b/client/components/Planning/PlanningDateTime.tsx index 204514943..5f432f8b6 100644 --- a/client/components/Planning/PlanningDateTime.tsx +++ b/client/components/Planning/PlanningDateTime.tsx @@ -1,10 +1,23 @@ import React from 'react'; -import PropTypes from 'prop-types'; import {get} from 'lodash'; import moment from 'moment'; import {planningUtils} from '../../utils/index'; import {MAIN} from '../../constants'; import {CoverageIcons} from '../Coverages/CoverageIcons'; +import {IDesk, IUser} from 'superdesk-api'; +import {IPlanningItem} from 'interfaces'; + +interface IProps { + item: IPlanningItem; + date?: string; + users?: Array; + desks?: Array; + activeFilter?: string; + contentTypes?: Array; + includeScheduledUpdates?: boolean; + contacts?: any; + filterLanguage?: string; +} export const PlanningDateTime = ({ item, @@ -15,7 +28,8 @@ export const PlanningDateTime = ({ contentTypes, includeScheduledUpdates, contacts, -}) => { + filterLanguage, +}: IProps) => { const coverages = get(item, 'coverages', []); const coverageTypes = planningUtils.mapCoverageByDate(coverages); const hasAssociatedEvent = !!get(item, 'event_item'); @@ -23,6 +37,11 @@ export const PlanningDateTime = ({ const coverageToDisplay = coverageTypes.filter((coverage) => { const scheduled = get(coverage, 'planning.scheduled'); + // Display only the coverages that match the active filter language + if (filterLanguage !== '' && filterLanguage != null && coverage.planning.language != filterLanguage) { + return false; + } + if (includeScheduledUpdates && get(coverage, 'scheduled_updates.length') > 0) { for (let i = 0; i < coverage.scheduled_updates.length; i++) { if (isSameDay(coverage.scheduled_updates[i].planning.scheduled)) { @@ -53,14 +72,3 @@ export const PlanningDateTime = ({ /> ); }; - -PlanningDateTime.propTypes = { - item: PropTypes.object.isRequired, - date: PropTypes.string, - users: PropTypes.array, - desks: PropTypes.array, - activeFilter: PropTypes.string, - contentTypes: PropTypes.array, - includeScheduledUpdates: PropTypes.bool, - contacts: PropTypes.object, -}; diff --git a/client/components/Planning/PlanningItem.tsx b/client/components/Planning/PlanningItem.tsx index 1c5d7d9df..72719ae95 100644 --- a/client/components/Planning/PlanningItem.tsx +++ b/client/components/Planning/PlanningItem.tsx @@ -286,6 +286,7 @@ class PlanningItemComponent extends React.Component { activeFilter, contentTypes, contacts, + filterLanguage, })} diff --git a/client/components/UI/List/Column.tsx b/client/components/UI/List/Column.tsx index 3eac2e008..c8f9e0d1e 100644 --- a/client/components/UI/List/Column.tsx +++ b/client/components/UI/List/Column.tsx @@ -7,7 +7,26 @@ import classNames from 'classnames'; * @name Column * @description Column Component of a list item */ -export const Column = ({children, grow, border, noPadding, hasCheck, checked, className}) => ( + +interface IProps { + children: Array | JSX.Element; + grow?: boolean; + border?: boolean; + noPadding?: boolean; + hasCheck?: boolean; + checked?: boolean; + className?: string; +} + +export const Column = ({ + children, + grow = false, + border = true, + noPadding = false, + hasCheck = false, + checked, + className, +}: IProps) => (
); - -Column.propTypes = { - children: PropTypes.node.isRequired, - grow: PropTypes.bool, - border: PropTypes.bool, - noPadding: PropTypes.bool, - hasCheck: PropTypes.bool, - checked: PropTypes.bool, - className: PropTypes.string, -}; - -Column.defaultProps = { - grow: false, - border: true, - noPadding: false, - hasCheck: false, -}; diff --git a/client/components/UI/List/Row.tsx b/client/components/UI/List/Row.tsx index f9b3581e5..f9a3cb5ff 100644 --- a/client/components/UI/List/Row.tsx +++ b/client/components/UI/List/Row.tsx @@ -1,13 +1,21 @@ -import React from 'react'; +import React, {CSSProperties} from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; +interface IProps { + children: Array | JSX.Element; + classes?: string; + paddingBottom?: boolean; + testId?: string; + style?: CSSProperties; +} + /** * @ngdoc react * @name Row * @description Row Component in a list of item where each item is a row */ -export const Row = ({children, classes, paddingBottom, testId, style}) => ( +export const Row = ({children, classes = '', paddingBottom, testId, style}: IProps) => (
( {children}
); - -Row.propTypes = { - children: PropTypes.node.isRequired, - classes: PropTypes.string, - margin: PropTypes.bool, - marginTop: PropTypes.bool, - paddingBottom: PropTypes.bool, - testId: PropTypes.string, - style: PropTypes.object, -}; - -Row.defaultProps = { - classes: '', - margin: true, - marginTop: false, -}; diff --git a/client/components/fields/coverages.tsx b/client/components/fields/coverages.tsx index 2df1f57d6..b62ff4706 100644 --- a/client/components/fields/coverages.tsx +++ b/client/components/fields/coverages.tsx @@ -11,8 +11,10 @@ export const coverages = ({ activeFilter, contentTypes, contacts, + filterLanguage, }) => ( { +interface IState { + userList: Array; + selectedDeskId?: string; +} + +export class EmbeddedCoverageFormComponent extends React.PureComponent { constructor(props) { super(props); + this.state = { + userList: this.props.users, + selectedDeskId: null, + }; + this.onDeskChange = this.onDeskChange.bind(this); this.onStatusChange = this.onStatusChange.bind(this); this.onUserChange = this.onUserChange.bind(this); @@ -92,17 +102,23 @@ export class EmbeddedCoverageFormComponent extends React.PureComponent { } onDeskChange(deskId?: IDesk['_id']) { - const newDesk = deskId == null ? null : this.props.desks.find((desk) => desk._id === deskId); + const newDesk = deskId == null || deskId == '' ? null : this.props.desks.find((desk) => desk._id === deskId); const updates: Partial = { desk: newDesk, filteredUsers: getUsersForDesk(newDesk, this.props.users), + user: null, }; if ((this.props.coverage.language ?? '').length < 1) { - updates.language = newDesk.desk_language; + updates.language = newDesk?.desk_language ?? null; } + this.setState({ + selectedDeskId: deskId, + userList: updates.filteredUsers, + }); + this.props.update(updates); } @@ -155,7 +171,7 @@ export class EmbeddedCoverageFormComponent extends React.PureComponent { error={this.props.errors?.desk} >