Skip to content

Commit

Permalink
Show reassign on auto add to workflow, types cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc committed Oct 31, 2024
1 parent 7a14184 commit 4d160d6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 67 deletions.
25 changes: 15 additions & 10 deletions client/components/Coverages/CoverageEditor/CoverageFormHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import {connect} from 'react-redux';
import {get} from 'lodash';

import {IPlanningCoverageItem, ICoverageScheduledUpdate} from '../../../interfaces';
import {IPlanningCoverageItem, ICoverageScheduledUpdate, IPlanningConfig} from '../../../interfaces';
import {IArticle, IDesk, IUser} from 'superdesk-api';

import {getCreator, getItemInArrayById, gettext, planningUtils, onEventCapture} from '../../../utils';
Expand All @@ -11,6 +11,10 @@ import {Button} from '../../UI';
import {UserAvatar} from '../../../components/UserAvatar';
import {StateLabel} from '../../StateLabel';
import * as actions from '../../../actions';
import {appConfig} from 'superdesk-core/scripts/appConfig';
import {ASSIGNMENTS} from '../../../constants/assignments';

const planningConfig: IPlanningConfig = appConfig as IPlanningConfig;

interface IProps {
field: string;
Expand Down Expand Up @@ -72,12 +76,13 @@ export class CoverageFormHeaderComponent extends React.PureComponent<IProps> {
} = this.props;

const userAssigned = getCreator(value, 'assigned_to.user', users);
const deskAssigned = getItemInArrayById(desks, get(value, 'assigned_to.desk'));
const coverageProvider = get(value, 'assigned_to.coverage_provider');
const assignmentState = get(value, 'assigned_to.state');
const cancelled = get(value, 'workflow_status') === 'cancelled';
const deskAssigned = getItemInArrayById(desks, value.assigned_to.desk);
const coverageProvider = value.assigned_to.coverage_provider;
const assignmentState = value.assigned_to.state;
const cancelled = value.workflow_status === ASSIGNMENTS.WORKFLOW_STATE.CANCELLED;
const canEditAssignment = planningUtils.isCoverageDraft(value) ||
(!!addNewsItemToPlanning && !get(value, 'coverage_id') && !get(value, 'scheduled_update_id'));
(!!addNewsItemToPlanning && !value.coverage_id && !get(value, 'scheduled_update_id'));
const shouldShowRemove = (onRemoveAssignment != null && planningConfig.planning_auto_assign_to_workflow === false);

Check failure on line 85 in client/components/Coverages/CoverageEditor/CoverageFormHeader.tsx

View workflow job for this annotation

GitHub Actions / client (14.x)

This line has a length of 123. Maximum allowed is 120

if (!deskAssigned && (!userAssigned || !coverageProvider)) {
return (
Expand Down Expand Up @@ -130,7 +135,7 @@ export class CoverageFormHeaderComponent extends React.PureComponent<IProps> {
<span className="sd-list-item__text-label sd-list-item__text-label--normal">
{gettext('Desk:')}
</span>
<span name={`${field}.assigned_to.desk`}>
<span key={`${field}.assigned_to.desk`}>
{get(deskAssigned, 'name', '')}
</span>
</span>
Expand All @@ -141,7 +146,7 @@ export class CoverageFormHeaderComponent extends React.PureComponent<IProps> {
<span className="sd-list-item__text-label sd-list-item__text-label--normal">
{gettext('Assignee:')}
</span>
<span name={`${field}.assigned_to.user`}>
<span key={`${field}.assigned_to.user`}>
{get(userAssigned, 'display_name', '')}
</span>
</span>
Expand All @@ -168,7 +173,7 @@ export class CoverageFormHeaderComponent extends React.PureComponent<IProps> {
</ListRow>
)}
</Column>
{canEditAssignment && !readOnly && (
{(canEditAssignment || planningConfig.planning_auto_assign_to_workflow) && !readOnly && (
<Column>
<ListRow>
<Button
Expand All @@ -181,7 +186,7 @@ export class CoverageFormHeaderComponent extends React.PureComponent<IProps> {
autoFocus
/>
</ListRow>
{!onRemoveAssignment ? null : (
{shouldShowRemove && (
<ListRow>
<Button
text={gettext('Remove')}
Expand Down
89 changes: 35 additions & 54 deletions client/components/UI/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,60 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import {KEYCODES} from './constants';
import {onEventCapture} from './utils';


/**
* @ngdoc react
* @name Button
* @description Generic Button component
*/
interface IButtonProps {
id?: string;
className?: string;
onClick: (...args: any) => any;
icon?: string;
title?: string;
text?: string;
disabled?: boolean;
textOnly?: boolean;
hollow?: boolean;
iconOnly?: boolean;
expanded?: boolean;
color?: 'primary' | 'success' | 'warning' | 'alert' | 'highlight' | 'sd-green' | 'ui-dark' | 'default';
size?: 'small' | 'large';
tabIndex?: number;
enterKeyIsClick?: boolean;
autoFocus?: boolean;
onKeyDown?: (e: React.KeyboardEvent) => any;
refNode?: (...args: any) => any;
iconOnlyCircle?: boolean;
children?: React.ReactNode;
pullRight?: boolean;
empty?: boolean;
}

const Button = ({
disabled = false,
textOnly = false,
hollow = false,
expanded = false,
enterKeyIsClick = false,
autoFocus = false,
iconOnlyCircle = false,
pullRight = false,
empty = false,
className,
onClick,
icon,
id,
title,
text,
disabled,
textOnly,
hollow,
expanded,
color,
size,
iconOnly,
tabIndex,
enterKeyIsClick,
autoFocus,
refNode,
onKeyDown,
iconOnlyCircle,
children,
pullRight,
empty,
...props
}) => {
}: IButtonProps) => {
const handeKeyDown = (event) => {
if (event.keyCode === KEYCODES.ENTER) {
onEventCapture(event);
Expand Down Expand Up @@ -82,42 +101,4 @@ const Button = ({
);
};

Button.propTypes = {
id: PropTypes.string,
className: PropTypes.string,
onClick: PropTypes.func.isRequired,
icon: PropTypes.string,
title: PropTypes.string,
text: PropTypes.string,
disabled: PropTypes.bool,
textOnly: PropTypes.bool,
hollow: PropTypes.bool,
iconOnly: PropTypes.bool,
expanded: PropTypes.bool,
color: PropTypes.oneOf(['primary', 'success', 'warning', 'alert', 'highlight', 'sd-green', 'ui-dark', 'default']),
size: PropTypes.oneOf(['small', 'large']),
tabIndex: PropTypes.number,
enterKeyIsClick: PropTypes.bool,
autoFocus: PropTypes.bool,
onKeyDown: PropTypes.func,
refNode: PropTypes.func,
iconOnlyCircle: PropTypes.bool,
children: PropTypes.node,
pullRight: PropTypes.bool,
empty: PropTypes.bool,
};

Button.defaultProps = {
disabled: false,
textOnly: false,
hollow: false,
iconOnly: false,
expanded: false,
enterKeyIsClick: false,
autoFocus: false,
iconOnlyCircle: false,
pullRight: false,
empty: false,
};

export default Button;
1 change: 0 additions & 1 deletion client/components/UI/List/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, {CSSProperties} from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

interface IProps {
Expand Down
4 changes: 2 additions & 2 deletions client/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
IPlanningCoverageItem,
IIngestProvider,
IFeaturedPlanningItem,
ISearchParams,
ICommonSearchParams,
JUMP_INTERVAL,
ICoverageScheduledUpdate,
} from '../interfaces';
import {IUser} from 'superdesk-api';
import {superdeskApi} from '../superdeskApi';
Expand Down Expand Up @@ -288,7 +288,7 @@ export const notifyError = (notify, error, defaultMessage) => {
* @return {object} The user object found or ingest provider id, otherwise nothing is returned
*/
export function getCreator(
item: IEventOrPlanningItem | IPlanningCoverageItem | IFeaturedPlanningItem,
item: IEventOrPlanningItem | IPlanningCoverageItem | IFeaturedPlanningItem | ICoverageScheduledUpdate,
creator: string,
users: Array<IUser>
): IUser | IIngestProvider['id'] | undefined {
Expand Down

0 comments on commit 4d160d6

Please sign in to comment.