File size: 2,884 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Card } from '@automattic/components';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import PopoverMenuItem from 'calypso/components/popover-menu/item';
import SplitButton from 'calypso/components/split-button';
import { decodeEntities } from 'calypso/lib/formatting';
import ActivityIcon from '../activity-log-item/activity-icon';

class ActivityLogTaskUpdate extends Component {
	static propTypes = {
		toUpdate: PropTypes.object.isRequired,
		disable: PropTypes.bool,
		name: PropTypes.string,
		slug: PropTypes.string,
		version: PropTypes.string,
		type: PropTypes.string,

		linked: PropTypes.bool,
		goToPage: PropTypes.func,
		enqueueTheme: PropTypes.func,
		dismissTheme: PropTypes.func,

		// Plugin specific
		enqueue: PropTypes.func,
		dismiss: PropTypes.func,

		// Localize
		translate: PropTypes.func.isRequired,
	};

	handleEnqueue = () => this.props.enqueue( this.props.toUpdate );
	handleDismiss = () => this.props.dismiss( this.props.toUpdate );
	handleNameClick = () => this.props.goToPage( this.props.slug, this.props.type );

	render() {
		const { translate, name, version, type, disable, linked, slug, siteSlug } = this.props;

		let updateType = translate( 'Plugin update available' );
		if ( 'theme' === type ) {
			updateType = translate( 'Theme update available' );
		} else if ( 'core' === type ) {
			updateType = translate( 'Core update available' );
		}

		const url =
			'plugin' === type ? `/plugins/${ slug }/${ siteSlug }` : `/theme/${ slug }/${ siteSlug }`;
		return (
			<Card className="activity-log-tasklist__task" compact>
				<ActivityIcon
					activityIcon={ 'plugin' === type || 'theme' === type ? `${ type }s` : 'my-sites' }
					activityStatus="warning"
				/>
				<span className="activity-log-tasklist__update-item">
					<div className="activity-log-tasklist__update-text">
						{ linked ? (
							<a href={ url } onClick={ this.handleNameClick }>
								{ decodeEntities( name ) }
							</a>
						) : (
							// Add button classes so unlinked names look the same.
							<span className="activity-log-tasklist__unlinked">{ decodeEntities( name ) }</span>
						) }
						<span className="activity-log-tasklist__update-bullet">&bull;</span>
						<span className="activity-log-tasklist__update-version">{ version }</span>
					</div>
					<div className="activity-log-tasklist__update-type">{ updateType }</div>
				</span>
				<span className="activity-log-tasklist__update-action">
					<SplitButton
						compact
						label={ translate( 'Update' ) }
						onClick={ this.handleEnqueue }
						disabled={ disable }
					>
						<PopoverMenuItem icon="trash" onClick={ this.handleDismiss }>
							{ translate( 'Dismiss' ) }
						</PopoverMenuItem>
					</SplitButton>
				</span>
			</Card>
		);
	}
}

export default localize( ActivityLogTaskUpdate );