Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI feedback #4679

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import HighlightBtn from '../components/HighlightBtn';
import {Loader, Spinner} from 'superdesk-ui-framework/react';

/**
* @ngdoc directive
Expand Down
26 changes: 19 additions & 7 deletions scripts/apps/highlights/services/HighlightsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import {gettext} from 'core/utils';
import {IPackagesService} from 'types/Services/Packages';
import {IBaseRestApiResponse} from 'superdesk-api';
import {notify} from 'core/notify/notify';
import {trackArticleActionProgress} from 'core/helpers/network';

export interface IHighlight extends IBaseRestApiResponse {
name: string;
Expand Down Expand Up @@ -54,11 +56,13 @@
var criteria = {};

if (desk) {
criteria = {where: {$or: [
{desks: desk},
{desks: {$size: 0}},
],
},
criteria = {
where: {
$or: [
{desks: desk},
{desks: {$size: 0}},
],
},
};
}

Expand Down Expand Up @@ -111,8 +115,16 @@
* Mark an item for a highlight
*/
service.markItem = function(highlight, markedItem) {
return api.save('marked_for_highlights', {highlights: [highlight], marked_item: markedItem._id});
};
return trackArticleActionProgress(
() => api.save(
'marked_for_highlights',
{highlights: [highlight], marked_item: markedItem._id},
),
markedItem._id,
gettext('Item marked'),
gettext('Couldn\'t mark item'),
);
}

Check failure on line 127 in scripts/apps/highlights/services/HighlightsService.ts

View workflow job for this annotation

GitHub Actions / test

Missing semicolon

Check failure on line 127 in scripts/apps/highlights/services/HighlightsService.ts

View workflow job for this annotation

GitHub Actions / test

Missing semicolon

Check failure on line 127 in scripts/apps/highlights/services/HighlightsService.ts

View workflow job for this annotation

GitHub Actions / test

Missing semicolon

/**
* Create empty highlight package
Expand Down
10 changes: 10 additions & 0 deletions scripts/apps/search/components/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class Item extends React.Component<IProps, IState> {
this.onDragStart = this.onDragStart.bind(this);
this.openAuthoringView = this.openAuthoringView.bind(this);
this.toggleNested = this.toggleNested.bind(this);
this.handleActionLoading = this.handleActionLoading.bind(this);
}

componentWillMount() {
Expand All @@ -119,13 +120,21 @@ export class Item extends React.Component<IProps, IState> {
}
}

handleActionLoading(e: CustomEvent) {
if (e.detail.itemId === this.props.item._id) {
this.setState({loading: e.detail.loading});
}
}

componentDidMount() {
addEventListener('action-loading', this.handleActionLoading);
this._mounted = true;
}

componentWillUnmount() {
this._mounted = false;
closeActionsMenu(this.props.item._id);
removeEventListener('action-loading', this.handleActionLoading);
}

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -358,6 +367,7 @@ export class Item extends React.Component<IProps, IState> {
default:
return (
<ListItemTemplate
loading={this.state.loading}
item={item}
relatedEntities={this.props.relatedEntities}
itemSelected={itemSelected}
Expand Down
2 changes: 2 additions & 0 deletions scripts/apps/search/components/ItemListTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IPropsItemsListTemplate extends IPropsItemListInfo {
selectingDisabled: boolean;
getActionsMenu: () => any;
multiSelect: IMultiSelectNew | ILegacyMultiSelect;
loading?: boolean;
}

export class ListItemTemplate extends React.Component<IPropsItemsListTemplate> {
Expand All @@ -29,6 +30,7 @@ export class ListItemTemplate extends React.Component<IPropsItemsListTemplate> {
: null
}
<ListItemInfo
loading={this.props.loading}
item={item}
relatedEntities={this.props.relatedEntities}
openAuthoringView={this.props.openAuthoringView}
Expand Down
3 changes: 3 additions & 0 deletions scripts/apps/search/components/ListItemInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {flatMap} from 'lodash';
import {extensions} from 'appConfig';
import {IDesk, IArticle, IListViewFieldWithOptions} from 'superdesk-api';
import {IRelatedEntities} from 'core/getRelatedEntities';
import {Loader} from 'superdesk-ui-framework/react';

export interface IPropsItemListInfo {
item: IArticle;
Expand All @@ -14,6 +15,7 @@ export interface IPropsItemListInfo {
ingestProvider: any;
profilesById: any;
highlightsById: any;
loading?: boolean;
markedDesksById: any;
openAuthoringView: (rewrittenBy?: string) => void;
narrow: any;
Expand Down Expand Up @@ -69,6 +71,7 @@ export class ListItemInfo extends React.PureComponent<IPropsItemListInfo> {
className={className}
style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}
>
{this.props.loading && <Loader overlay />}
{listItems}
{
articleDisplayWidgets.length < 1 ? null : (
Expand Down
28 changes: 28 additions & 0 deletions scripts/core/helpers/network.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ng from 'core/services/ng';
import {appConfig} from '../../appConfig';
import {notify} from 'core/notify/notify';

interface IHttpRequestOptions {
method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
Expand Down Expand Up @@ -173,3 +174,30 @@ export function uploadFileWithProgress<T>(
});
});
}

export function trackArticleActionProgress<T>(
p: () => Promise<T>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPromise would be a better name. p was a placeholder in my initial snippet.

itemId: string,
successMessage: string,
errorMessage: string,
): Promise<T> {
dispatchEvent(new CustomEvent('action-loading', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to call it article-action-loading so if anyone is logging events they would discover quicker from which part is it coming from.

detail: {loading: true, itemId},
}));

return p()
.then((res) => {
notify.success(successMessage);

return res;
}).catch((error) => {
notify.error(errorMessage);

return error;
})
.finally(() => {
dispatchEvent(new CustomEvent('action-loading', {
detail: {loading: true, itemId},
}));
});
}
Loading