Skip to content

Commit

Permalink
port send to desk changes from angular based authoring (#4177)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Jan 18, 2023
1 parent 0c7f978 commit 1667cb1
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,11 @@ interface IState {
}

export class DuplicateToTab extends React.PureComponent<IProps, IState> {
availableDesks: OrderedMap<string, IDesk>;

constructor(props: IProps) {
super(props);

this.availableDesks = sdApi.desks.getAllDesks();
this.state = {
selectedDestination: getInitialDestination(
props.items,
canSendToPersonal(props.items),
this.availableDesks,
),
selectedDestination: getInitialDestination(props.items, canSendToPersonal(props.items)),
};

this.duplicateItems = this.duplicateItems.bind(this);
Expand Down Expand Up @@ -66,7 +59,6 @@ export class DuplicateToTab extends React.PureComponent<IProps, IState> {
<PanelContent markupV2={markupV2}>
<ToggleBox title={gettext('Destination')} initiallyOpen>
<DestinationSelect
availableDesks={this.availableDesks}
value={this.state.selectedDestination}
onChange={(value) => {
this.setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ interface IState {
}

export class FetchToTab extends React.PureComponent<IProps, IState> {
availableDesks: OrderedMap<string, IDesk>;

constructor(props: IProps) {
super(props);

this.availableDesks = sdApi.desks.getAllDesks();

this.state = {
selectedDestination: getInitialDestination(props.items, false, this.availableDesks),
selectedDestination: getInitialDestination(props.items, false),
};

this.fetchItems = this.fetchItems.bind(this);
Expand Down Expand Up @@ -59,7 +55,6 @@ export class FetchToTab extends React.PureComponent<IProps, IState> {
<PanelContent markupV2={markupV2}>
<ToggleBox title={gettext('Destination')} initiallyOpen>
<DestinationSelect
availableDesks={this.availableDesks}
value={this.state.selectedDestination}
onChange={(value) => {
this.setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ interface IState {
}

export class PublishTab extends React.PureComponent<IProps, IState> {
availableDesks: OrderedMap<string, IDesk>;

constructor(props: IProps) {
super(props);

this.availableDesks = sdApi.desks.getAllDesks();
this.state = {
...getInitialPublishingDateOptions([this.props.item]),
selectedDestination: getInitialDestination([this.props.item], false, this.availableDesks),
selectedDestination: getInitialDestination([this.props.item], false),
publishingDateOptions: getInitialPublishingDateOptions([props.item]),
publishingTarget: {
target_subscribers: [],
Expand Down Expand Up @@ -159,7 +156,6 @@ export class PublishTab extends React.PureComponent<IProps, IState> {
publishFromEnabled && (
<ToggleBox title={gettext('From')} initiallyOpen>
<DestinationSelect
availableDesks={this.availableDesks}
value={this.state.selectedDestination}
onChange={(value) => {
this.setState({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {IArticle, IDesk} from 'superdesk-api';
import {IArticle, IDesk, OrderedMap} from 'superdesk-api';
import {Button, Text, ToggleBox} from 'superdesk-ui-framework/react';
import {gettext, gettextPlural} from 'core/utils';
import {PanelContent} from '../panel/panel-content';
Expand All @@ -17,7 +17,6 @@ import {
PublishingDateOptions,
} from '../subcomponents/publishing-date-options';
import {authoringApiCommon} from 'apps/authoring-bridge/authoring-api-common';
import {OrderedMap} from 'immutable';

interface IProps {
items: Array<IArticle>;
Expand All @@ -32,13 +31,13 @@ interface IState {
}

export class SendToTab extends React.PureComponent<IProps, IState> {
availableDesks: OrderedMap<string, IDesk>;
private availableDesks: OrderedMap<string, IDesk>;

constructor(props: IProps) {
super(props);

this.availableDesks = sdApi.desks.getAllDesks()
.filter((desk) => desk.send_to_desk_not_allowed === false)
.filter((desk) => desk.send_to_desk_not_allowed !== true)
.toOrderedMap();

this.state = {
Expand Down Expand Up @@ -102,7 +101,7 @@ export class SendToTab extends React.PureComponent<IProps, IState> {
const sendPackages = this.props.items.every(({type}) => type === 'composite');
const dest = this.state.selectedDestination;

if (dest.type == 'desk' && dest.desk == null) {
if (dest.type === 'desk' && dest.desk == null) {
return (
<div
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {getInitialDestination} from '../utils/get-initial-destination';
import {DestinationSelect} from '../subcomponents/destination-select';
import {ISendToDestination} from '../interfaces';
import {sdApi} from 'api';
import {OrderedMap} from 'immutable';

interface IProps {
items: Array<IArticle>;
Expand All @@ -21,15 +20,11 @@ interface IState {
}

export class UnspikeTab extends React.PureComponent<IProps, IState> {
availableDesks: OrderedMap<string, IDesk>;

constructor(props: IProps) {
super(props);

this.availableDesks = sdApi.desks.getAllDesks();

this.state = {
selectedDestination: getInitialDestination(props.items, false, this.availableDesks),
selectedDestination: getInitialDestination(props.items, false),
};

this.doUnspike = this.doUnspike.bind(this);
Expand Down Expand Up @@ -59,7 +54,6 @@ export class UnspikeTab extends React.PureComponent<IProps, IState> {
<PanelContent markupV2={markupV2}>
<ToggleBox title={gettext('Destination')} initiallyOpen>
<DestinationSelect
availableDesks={this.availableDesks}
value={this.state.selectedDestination}
onChange={(value) => {
this.setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@ interface IProps {
includePersonalSpace: boolean;
disallowedStages?: Array<IStage['_id']>;
hideStages?: boolean;
availableDesks: OrderedMap<string, IDesk>;

// Defaults to all desks
availableDesks?: OrderedMap<string, IDesk>;
}

const PERSONAL_SPACE = 'PERSONAL_SPACE';

export class DestinationSelect extends React.PureComponent<IProps> {
render() {
const selectedDestination = this.props.value;

const destinationPersonalSpace: {id: string; label: string} = {
id: PERSONAL_SPACE, label: gettext('Personal space'),
};

const allDesks = this.props.availableDesks ?? sdApi.desks.getAllDesks();
let destinations: Array<{id: string; label: string}> =
this.props.availableDesks.toArray().map((desk) => ({id: desk._id, label: desk.name}));
allDesks.toArray().map((desk) => ({id: desk._id, label: desk.name}));

if (this.props.includePersonalSpace) {
destinations.push(destinationPersonalSpace);
Expand All @@ -46,7 +48,7 @@ export class DestinationSelect extends React.PureComponent<IProps> {
} else if (dest.type === 'desk') {
const destinationDesk: {id: string; label: string} = {
id: dest.desk,
label: this.props.availableDesks.find((desk) => desk._id === dest.desk).name,
label: allDesks.find((desk) => desk._id === dest.desk).name,
};

return destinationDesk;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ISendToDestination} from '../interfaces';
export function getInitialDestination(
items: Array<IArticle>,
canSendToPersonal: boolean,
availableDesks: OrderedMap<string, IDesk>,
availableDesks: OrderedMap<string, IDesk> = sdApi.desks.getAllDesks(),
): ISendToDestination {
const lastDestination: ISendToDestination | null = sdApi.preferences.get('destination:active');

Expand All @@ -29,7 +29,9 @@ export function getInitialDestination(
}
})();

if (!availableDesks.map((x) => x._id).includes(destinationDesk)) {
// If destinationDesk isn't found in availableDesks we set the
// destinationDesk to the first item from availableDesks
if (!availableDesks.has(destinationDesk)) {
destinationDesk = availableDesks.first()?._id;
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ declare module 'superdesk-api' {
sams_settings?: {
allowed_sets?: Array<string>;
};
send_to_desk_not_allowed: boolean;
send_to_desk_not_allowed?: boolean;
}

export interface IStage extends IBaseRestApiResponse {
Expand Down

0 comments on commit 1667cb1

Please sign in to comment.