Skip to content

Commit 91c3078

Browse files
authored
fix send to tab desk preferred desks handling (#5138)
use it for preselected value as well SDESK-7438
1 parent 742e04e commit 91c3078

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

scripts/core/interactive-article-actions-panel/actions/duplicate-to-tab.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@ interface IState {
2323
}
2424

2525
export class DuplicateToTab extends React.PureComponent<IProps, IState> {
26+
private userPreferredDesks: {[key: string]: boolean};
27+
2628
constructor(props: IProps) {
2729
super(props);
2830

31+
const preferredDesks = sdApi.preferences.get('desks:preferred');
32+
33+
this.userPreferredDesks = preferredDesks?.selected ?? {};
34+
2935
this.state = {
30-
selectedDestination: getInitialDestination(props.items, canSendToPersonal(props.items)),
36+
selectedDestination: getInitialDestination(
37+
props.items,
38+
canSendToPersonal(props.items),
39+
undefined,
40+
this.userPreferredDesks,
41+
),
3142
};
3243

3344
this.duplicateItems = this.duplicateItems.bind(this);
@@ -59,6 +70,7 @@ export class DuplicateToTab extends React.PureComponent<IProps, IState> {
5970
<PanelContent markupV2={markupV2}>
6071
<ToggleBox variant="simple" title={gettext('Destination')} initiallyOpen>
6172
<DestinationSelect
73+
preferredDesks={this.userPreferredDesks}
6274
value={this.state.selectedDestination}
6375
onChange={(value) => {
6476
this.setState({

scripts/core/interactive-article-actions-panel/actions/fetch-to-tab.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ interface IState {
2424
}
2525

2626
export class FetchToTab extends React.PureComponent<IProps, IState> {
27+
private userPreferredDesks: {[key: string]: boolean};
28+
2729
constructor(props: IProps) {
2830
super(props);
2931

32+
const preferredDesks = sdApi.preferences.get('desks:preferred');
33+
34+
this.userPreferredDesks = preferredDesks?.selected ?? {};
35+
3036
this.state = {
31-
selectedDestination: getInitialDestination(props.items, false),
37+
selectedDestination: getInitialDestination(props.items, false, undefined, this.userPreferredDesks),
3238
};
3339

3440
this.fetchItems = this.fetchItems.bind(this);
@@ -76,6 +82,7 @@ export class FetchToTab extends React.PureComponent<IProps, IState> {
7682
<PanelContent markupV2={markupV2}>
7783
<ToggleBox variant="simple" title={gettext('Destination')} initiallyOpen>
7884
<DestinationSelect
85+
preferredDesks={this.userPreferredDesks}
7986
value={this.state.selectedDestination}
8087
onChange={(value) => {
8188
this.setState({

scripts/core/interactive-article-actions-panel/actions/send-to-tab.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class SendToTab extends React.PureComponent<IProps, IState> {
5050
props.items,
5151
canSendToPersonal(props.items),
5252
this.availableDesks,
53+
this.userPreferredDesks,
5354
),
5455
publishingDateOptions: getInitialPublishingDateOptions(props.items),
5556
};

scripts/core/interactive-article-actions-panel/utils/get-initial-destination.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function getInitialDestination(
88
items: Array<IArticle>,
99
canSendToPersonal: boolean,
1010
availableDesks: OrderedMap<string, IDesk> = sdApi.desks.getAllDesks(),
11+
userPreferredDesks: {[key: string]: boolean} = {},
1112
): ISendToDestination {
1213
const lastDestination: ISendToDestination | null = sdApi.preferences.get('destination:active');
1314

@@ -25,14 +26,17 @@ export function getInitialDestination(
2526
} else if (items.length === 1 && items[0].task?.desk != null) {
2627
return items[0].task.desk;
2728
} else {
28-
return availableDesks.first()?._id ?? null;
29+
return availableDesks.find((desk) => desk != null && userPreferredDesks[desk._id] === true)?._id
30+
?? availableDesks.first()?._id
31+
?? null;
2932
}
3033
})();
3134

32-
// If destinationDesk isn't found in availableDesks we set the
33-
// destinationDesk to the first item from availableDesks
35+
// If destinationDesk is no longer available, use the same fallback priority
36+
// as initial selection: preferred desk first, then first available desk.
3437
if (!availableDesks.has(destinationDesk)) {
35-
destinationDesk = availableDesks.first()?._id;
38+
destinationDesk = availableDesks.find((desk) => desk != null && userPreferredDesks[desk._id] === true)?._id
39+
?? availableDesks.first()?._id;
3640
}
3741

3842
if (destinationDesk == null) {

0 commit comments

Comments
 (0)