Skip to content

Commit

Permalink
Add notification for bulk action, adjust based on mark/unmark
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc committed Oct 31, 2024
1 parent 95aa992 commit e800553
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import {gettext} from 'core/utils';
import {getArticleLabel, gettext} from 'core/utils';
import {connectServices} from 'core/helpers/ReactRenderAsync';
import {IDesk, IArticle} from 'superdesk-api';
import {getHighlightsLabel, IHighlight} from '../services/HighlightsService';
import {Modal} from 'superdesk-ui-framework/react/components/Modal';
import {Button, ButtonGroup} from 'superdesk-ui-framework/react';
import {notify} from 'core/notify/notify';

interface IProps {
closeModal(): void;
Expand All @@ -28,20 +29,27 @@ export function getModalForMultipleHighlights(articles: Array<IArticle>, deskId:
this.handleChange = this.handleChange.bind(this);
this.markHighlights = this.markHighlights.bind(this);
}

componentDidMount() {
this.props.highlightsService.get(deskId).then((res) => {
this.setState({
highlightsForDesk: res._items,
});
});
}

markHighlights() {
var promises = Promise.resolve();

articles.forEach((article) => {
this.state.selectedHighlights.forEach((highlightId) => {
if (article.highlights == null || article.highlights.includes(highlightId) === false) {
promises.then(() => this.props.highlightsService.markItem(highlightId, article));
} else {
notify.error(gettext(
"Article {{ slug }} is already marked for this highlight",

Check failure on line 50 in scripts/apps/highlights/components/SetHighlightsForMultipleArticlesModal.tsx

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote

Check failure on line 50 in scripts/apps/highlights/components/SetHighlightsForMultipleArticlesModal.tsx

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote

Check failure on line 50 in scripts/apps/highlights/components/SetHighlightsForMultipleArticlesModal.tsx

View workflow job for this annotation

GitHub Actions / test

Strings must use singlequote
{slug: getArticleLabel(article)},
));
}
});
});
Expand All @@ -50,6 +58,7 @@ export function getModalForMultipleHighlights(articles: Array<IArticle>, deskId:
this.props.closeModal();
});
}

handleChange(event: React.ChangeEvent<HTMLSelectElement>) {
const selected = [];
const {options} = event.target;
Expand All @@ -66,6 +75,7 @@ export function getModalForMultipleHighlights(articles: Array<IArticle>, deskId:
selectedHighlights: selected,
});
}

render() {
if (this.state.highlightsForDesk == null) {
return null;
Expand Down
13 changes: 7 additions & 6 deletions scripts/apps/highlights/services/HighlightsService.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import _ from 'lodash';
import {gettext} from 'core/utils';
import {IPackagesService} from 'types/Services/Packages';
import {IBaseRestApiResponse} from 'superdesk-api';
import {notify} from 'core/notify/notify';
import {IArticle, IBaseRestApiResponse} from 'superdesk-api';
import {trackArticleActionProgress} from 'core/helpers/network';

export interface IHighlight extends IBaseRestApiResponse {
Expand Down Expand Up @@ -112,17 +111,19 @@ export function HighlightsService(api, $q, $cacheFactory, packages: IPackagesSer
};

/**
* Mark an item for a highlight
* Mark/Unmark an item for a highlight
*/
service.markItem = function(highlight, markedItem) {
service.markItem = function(highlight: string, markedItem: IArticle) {
const addToHighlight = markedItem.highlights.includes(highlight) === false;

return trackArticleActionProgress(
() => api.save(
'marked_for_highlights',
{highlights: [highlight], marked_item: markedItem._id},
),
markedItem._id,
gettext('Item marked'),
gettext('Couldn\'t mark item'),
gettext(addToHighlight ? 'Item marked' : 'Item unmarked'),
gettext(addToHighlight ? 'Couldn\'t mark item' : 'Couldn\'t unmark item'),
);
};

Expand Down

0 comments on commit e800553

Please sign in to comment.