diff --git a/client/planning-extension/src/assignments-overview/hiddenAssignmentsList.tsx b/client/planning-extension/src/assignments-overview/hiddenAssignmentsList.tsx new file mode 100644 index 000000000..1b4bf6b86 --- /dev/null +++ b/client/planning-extension/src/assignments-overview/hiddenAssignmentsList.tsx @@ -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(); + +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 ( + + { + (data) => { + const itemsCount = data._meta.total; + + superdesk.dispatchEvent( + 'menuItemBadgeValueChange', + {menuId: 'MENU_ITEM_PLANNING_ASSIGNMENTS', badgeValue: itemsCount.toString()}, + ); + + return null; + } + } + + ); + } +} diff --git a/client/planning-extension/src/assignments-overview/index.tsx b/client/planning-extension/src/assignments-overview/index.tsx index 95a52b9a7..280baae61 100644 --- a/client/planning-extension/src/assignments-overview/index.tsx +++ b/client/planning-extension/src/assignments-overview/index.tsx @@ -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'; @@ -27,16 +27,16 @@ interface IState { currentUser: IUser; } -function getAssignmentsQuery(userId: IUser['_id']): ISuperdeskQuery { +export function getAssignmentsQuery(userId: IUser['_id'], assignmentToState: Array): 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, }; @@ -68,7 +68,13 @@ export class AssignmentsList extends React.PureComponent + { (data) => { const assignments = data._items; diff --git a/client/planning-extension/src/extension.ts b/client/planning-extension/src/extension.ts index f4c03102f..6a723a912 100644 --- a/client/planning-extension/src/extension.ts +++ b/client/planning-extension/src/extension.ts @@ -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; @@ -251,7 +252,7 @@ const extension: IExtension = { }, }, ], - globalMenuHorizontal: displayTopbarWidget ? [AssignmentsList] : [], + globalMenuHorizontal: [AssignmentsCountTracker, ...(displayTopbarWidget ? [AssignmentsList] : [])], }, };