@superdesk/planning-extension
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -21,7 +21,4 @@ "use strict"; | ||
var assignments_overview_list_item_1 = require("./assignments-overview-list-item"); | ||
var addWebsocketMessageListener = superdesk_1.superdesk.addWebsocketMessageListener; | ||
var DropdownTree = superdesk_1.superdesk.components.getDropdownTree(); | ||
var _a = superdesk_1.superdesk.dataApi, queryRawJson = _a.queryRawJson, findOne = _a.findOne, fetchChangedResourcesObj = _a.fetchChangedResourcesObj; | ||
var _b = superdesk_1.superdesk.components, GroupLabel = _b.GroupLabel, IconBig = _b.IconBig, TopMenuDropdownButton = _b.TopMenuDropdownButton, getLiveQueryHOC = _b.getLiveQueryHOC; | ||
var throttleAndCombineArray = superdesk_1.superdesk.utilities.throttleAndCombineArray; | ||
var _a = superdesk_1.superdesk.components, GroupLabel = _a.GroupLabel, IconBig = _a.IconBig, TopMenuDropdownButton = _a.TopMenuDropdownButton, getLiveQueryHOC = _a.getLiveQueryHOC, WithLiveResources = _a.WithLiveResources; | ||
var LiveAssignmentsHOC = getLiveQueryHOC(); | ||
@@ -42,17 +39,2 @@ function getAssignmentsQuery(userId) { | ||
} | ||
function fetchDesks() { | ||
return queryRawJson('desks').then(function (desksResponse) { | ||
var desks = desksResponse._items.reduce(function (acc, item) { | ||
acc[item._id] = item; | ||
return acc; | ||
}, {}); | ||
return desks; | ||
}); | ||
} | ||
function fetchContentTypes() { | ||
return findOne('vocabularies', 'g2_content_type').then(function (_a) { | ||
var items = _a.items; | ||
return (items); | ||
}); | ||
} | ||
var AssignmentsList = /** @class */ (function (_super) { | ||
@@ -63,48 +45,4 @@ __extends(AssignmentsList, _super); | ||
_this.state = { loading: true }; | ||
_this.eventListenersToRemoveBeforeUnmounting = []; | ||
_this.handleContentChanges = _this.handleContentChanges.bind(_this); | ||
_this.handleContentChangesThrottled = throttleAndCombineArray(function (changes) { | ||
_this.handleContentChanges(changes); | ||
}, 300); | ||
_this.eventListenersToRemoveBeforeUnmounting.push(addWebsocketMessageListener('resource:created', function (event) { | ||
var _a = event.detail.extra, resource = _a.resource, _id = _a._id; | ||
_this.handleContentChangesThrottled([{ changeType: 'created', resource: resource, itemId: _id }]); | ||
})); | ||
_this.eventListenersToRemoveBeforeUnmounting.push(addWebsocketMessageListener('resource:updated', function (event) { | ||
var _a = event.detail.extra, resource = _a.resource, _id = _a._id, fields = _a.fields; | ||
_this.handleContentChangesThrottled([{ | ||
changeType: 'updated', | ||
resource: resource, | ||
itemId: _id, | ||
fields: fields, | ||
}]); | ||
})); | ||
_this.eventListenersToRemoveBeforeUnmounting.push(addWebsocketMessageListener('resource:deleted', function (event) { | ||
var _a = event.detail.extra, resource = _a.resource, _id = _a._id; | ||
_this.handleContentChangesThrottled([{ changeType: 'deleted', resource: resource, itemId: _id }]); | ||
})); | ||
return _this; | ||
} | ||
AssignmentsList.prototype.handleContentChanges = function (changes) { | ||
var _this = this; | ||
var state = this.state; | ||
if (state.loading === true) { | ||
return; | ||
} | ||
var refetchContentTypes = changes.find(function (_a) { | ||
var resource = _a.resource, itemId = _a.itemId; | ||
return resource === 'vocabularies' && itemId === 'g2_content_type'; | ||
}) != null; | ||
Promise.all([ | ||
fetchChangedResourcesObj('desks', changes, state.desks), | ||
refetchContentTypes ? fetchContentTypes() : Promise.resolve(state.contentTypes), | ||
]).then(function (_a) { | ||
var desks = _a[0], contentTypes = _a[1]; | ||
_this.setState({ | ||
loading: false, | ||
desks: desks, | ||
contentTypes: contentTypes, | ||
}); | ||
}); | ||
}; | ||
AssignmentsList.prototype.componentDidMount = function () { | ||
@@ -114,21 +52,8 @@ var _this = this; | ||
.then(function (currentUser) { | ||
return Promise.all([ | ||
fetchDesks(), | ||
fetchContentTypes(), | ||
]).then(function (_a) { | ||
var desks = _a[0], contentTypes = _a[1]; | ||
_this.setState({ | ||
loading: false, | ||
currentUser: currentUser, | ||
desks: desks, | ||
contentTypes: contentTypes, | ||
}); | ||
_this.setState({ | ||
loading: false, | ||
currentUser: currentUser, | ||
}); | ||
}); | ||
}; | ||
AssignmentsList.prototype.componentWillUnmount = function () { | ||
this.eventListenersToRemoveBeforeUnmounting.forEach(function (removeListener) { | ||
removeListener(); | ||
}); | ||
}; | ||
AssignmentsList.prototype.render = function () { | ||
@@ -138,21 +63,34 @@ if (this.state.loading === true) { | ||
} | ||
var _a = this.state, desks = _a.desks, contentTypes = _a.contentTypes, currentUser = _a.currentUser; | ||
var currentUser = this.state.currentUser; | ||
return (React.createElement(LiveAssignmentsHOC, { resource: "assignments", query: getAssignmentsQuery(currentUser._id) }, function (data) { | ||
var assignments = data._items; | ||
var itemsCount = assignments.length; | ||
var itemsCount = data._meta.total; | ||
var grouped = lodash_1.groupBy(assignments, function (item) { return item.assigned_to.desk; }); | ||
superdesk_1.superdesk.dispatchEvent('menuItemBadgeValueChange', { menuId: 'MENU_ITEM_PLANNING_ASSIGNMENTS', badgeValue: data._meta.total.toString() }); | ||
return (React.createElement(DropdownTree, { groups: Object.keys(grouped).map(function (deskId) { return ({ | ||
render: function () { return (React.createElement(GroupLabel, null, | ||
React.createElement(superdesk_ui_framework_1.Badge, { type: "highlight", text: grouped[deskId].length.toString() }), | ||
React.createElement("span", { style: { marginLeft: 6 } }, desks[deskId].name))); }, | ||
items: grouped[deskId], | ||
}); }), getToggleElement: function (isOpen, onClick) { return (React.createElement(TopMenuDropdownButton, { onClick: function () { | ||
if (itemsCount > 0) { | ||
onClick(); | ||
} | ||
}, active: isOpen, disabled: itemsCount < 1, pulsate: false, "data-test-id": "toggle-button" }, | ||
React.createElement(superdesk_ui_framework_1.Badge, { type: "highlight", text: itemsCount.toString() }, | ||
React.createElement("span", { style: { color: isOpen ? '#3783A2' : 'white' } }, | ||
React.createElement(IconBig, { name: "tasks" }))))); }, renderItem: function (key, assignment, closeDropdown) { return (React.createElement(assignments_overview_list_item_1.AssignmentsOverviewListItem, { key: key, assignment: assignment, contentTypes: contentTypes, onClick: closeDropdown })); }, wrapperStyles: { whiteSpace: 'nowrap', padding: 15, paddingTop: 0 } })); | ||
superdesk_1.superdesk.dispatchEvent('menuItemBadgeValueChange', { menuId: 'MENU_ITEM_PLANNING_ASSIGNMENTS', badgeValue: itemsCount.toString() }); | ||
var resources = [ | ||
{ resource: 'desks', ids: Object.keys(grouped) }, | ||
{ resource: 'vocabularies', ids: ['g2_content_type'] }, | ||
]; | ||
return (React.createElement(WithLiveResources, { resources: resources }, function (resourcesResponse) { | ||
var desksResponse = resourcesResponse[0]; | ||
var desks = lodash_1.keyBy(desksResponse._items, function (_a) { | ||
var _id = _a._id; | ||
return _id; | ||
}); | ||
var vocabulariesResponse = resourcesResponse[1]; | ||
var contentTypes = vocabulariesResponse._items[0].items; | ||
return (React.createElement(DropdownTree, { groups: Object.keys(grouped).map(function (deskId) { return ({ | ||
render: function () { return (React.createElement(GroupLabel, null, | ||
React.createElement(superdesk_ui_framework_1.Badge, { type: "highlight", text: grouped[deskId].length.toString() }), | ||
React.createElement("span", { className: "sd-margin-l--1" }, desks[deskId].name))); }, | ||
items: grouped[deskId], | ||
}); }), getToggleElement: function (isOpen, onClick) { return (React.createElement(TopMenuDropdownButton, { onClick: function () { | ||
if (itemsCount > 0) { | ||
onClick(); | ||
} | ||
}, active: isOpen, disabled: itemsCount < 1, pulsate: false, "data-test-id": "toggle-button" }, | ||
React.createElement(superdesk_ui_framework_1.Badge, { type: "highlight", text: itemsCount.toString() }, | ||
React.createElement("span", { style: { color: isOpen ? 'var(--sd-slugline-color)' : 'var(--color-bg-00)' } }, | ||
React.createElement(IconBig, { name: "tasks" }))))); }, renderItem: function (key, assignment, closeDropdown) { return (React.createElement(assignments_overview_list_item_1.AssignmentsOverviewListItem, { key: key, assignment: assignment, contentTypes: contentTypes, onClick: closeDropdown })); }, wrapperStyles: { whiteSpace: 'nowrap', padding: 16, paddingTop: 0 } })); | ||
})); | ||
})); | ||
@@ -159,0 +97,0 @@ }; |
{ | ||
"name": "@superdesk/planning-extension", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
17607
362