Skip to content

Commit

Permalink
Missing 'assignment available' circle on SD left panel (#2116)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzonidoo authored Oct 24, 2024
1 parent 575f205 commit 7a14184
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import * as React from 'react';
import {IUser} from 'superdesk-api';
import {getAssignmentsQuery} from '.';
import {ASSIGNMENT_STATE, IAssignmentItem} from '../../../interfaces';
import {superdesk} from '../superdesk';
const {getLiveQueryHOC} = superdesk.components;
const LiveAssignmentsHOC = getLiveQueryHOC<IAssignmentItem>();

interface IState {
loading: false;
currentUser: IUser;
}

export class AssignmentsCountTracker extends React.PureComponent<{}, {loading: true} | IState> {
constructor(props: {}) {
super(props);

this.state = {loading: true};
}

componentDidMount() {
superdesk.session.getCurrentUser()
.then((currentUser) => {
this.setState({
loading: false,
currentUser: currentUser,
});
});
}

render() {
if (this.state.loading === true) {
return null;
}

const {currentUser} = this.state;

return (
<LiveAssignmentsHOC
resource="assignments"
query={getAssignmentsQuery(currentUser._id, [ASSIGNMENT_STATE.ASSIGNED])}
>
{
(data) => {
const itemsCount = data._meta.total;

superdesk.dispatchEvent(
'menuItemBadgeValueChange',
{menuId: 'MENU_ITEM_PLANNING_ASSIGNMENTS', badgeValue: itemsCount.toString()},
);

return null;
}
}
</LiveAssignmentsHOC>
);
}
}
16 changes: 11 additions & 5 deletions client/planning-extension/src/assignments-overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
IUser,
IVocabulary,
} from 'superdesk-api';
import {IAssignmentItem} from '../../../interfaces';
import {ASSIGNMENT_STATE, IAssignmentItem} from '../../../interfaces';
import {superdesk} from '../superdesk';
import {Badge} from 'superdesk-ui-framework';
import {AssignmentsOverviewListItem} from './assignments-overview-list-item';
Expand All @@ -27,16 +27,16 @@ interface IState {
currentUser: IUser;
}

function getAssignmentsQuery(userId: IUser['_id']): ISuperdeskQuery {
export function getAssignmentsQuery(userId: IUser['_id'], assignmentToState: Array<ASSIGNMENT_STATE>): ISuperdeskQuery {
const query: ISuperdeskQuery = {
filter: {
$and: [
{'assigned_to.user': {$eq: userId}},
{'assigned_to.state': {$in: ['assigned', 'submitted', 'in_progress']}},
{'assigned_to.state': {$in: assignmentToState}},
],
},
sort: [{'planning.scheduled': 'asc'}],
page: 0,
page: 1,
max_results: 100,
};

Expand Down Expand Up @@ -68,7 +68,13 @@ export class AssignmentsList extends React.PureComponent<IProps, {loading: true}
const {currentUser} = this.state;

return (
<LiveAssignmentsHOC resource="assignments" query={getAssignmentsQuery(currentUser._id)}>
<LiveAssignmentsHOC
resource="assignments"
query={getAssignmentsQuery(
currentUser._id,
[ASSIGNMENT_STATE.ASSIGNED, ASSIGNMENT_STATE.SUBMITTED, ASSIGNMENT_STATE.IN_PROGRESS],
)}
>
{
(data) => {
const assignments = data._items;
Expand Down
3 changes: 2 additions & 1 deletion client/planning-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
PLANNING_DETAILS_WIDGET_ID,
PLANNING_DETAILS_WIDGET_LABEL,
} from './planning-details-widget';
import {AssignmentsCountTracker} from './assignments-overview/hiddenAssignmentsList';

function onSpike(superdesk: ISuperdesk, item: IArticle) {
const {gettext} = superdesk.localization;
Expand Down Expand Up @@ -251,7 +252,7 @@ const extension: IExtension = {
},
},
],
globalMenuHorizontal: displayTopbarWidget ? [AssignmentsList] : [],
globalMenuHorizontal: [AssignmentsCountTracker, ...(displayTopbarWidget ? [AssignmentsList] : [])],
},
};

Expand Down

0 comments on commit 7a14184

Please sign in to comment.