-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use AlertsList React component in /alerts_list
fix for #1803 * Refactors AlertsList component into seperate CampaignAlerts and AdminAlerts components with shared functionality * Allows for asynchronous 'resolving' for AdminAlerts * Campaign alerts functionality not changed * Sort options determined from available alerts to sort
- Loading branch information
1 parent
b7ab7c8
commit 85ba860
Showing
14 changed files
with
254 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react'; | ||
import createReactClass from 'create-react-class'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
import AlertsHandler from './alerts_handler.jsx'; | ||
import { fetchAdminAlerts } from '../../actions/alert_actions'; | ||
|
||
const AdminAlerts = createReactClass({ | ||
displayName: 'AdminAlerts', | ||
propTypes: { | ||
fetchAlerts: PropTypes.func, | ||
}, | ||
UNSAFE_componentWillMount() { | ||
// This adds ALL alerts to the state, to be used in AlertsHandler | ||
this.props.fetchAdminAlerts(); | ||
}, | ||
render() { | ||
return ( | ||
<AlertsHandler | ||
alertLabel={I18n.t('alerts.alert_label')} | ||
noAlertsLabel={I18n.t('alerts.no_alerts')} | ||
adminAlert={true} | ||
/> | ||
); | ||
} | ||
}); | ||
|
||
const mapDispatchToProps = { fetchAdminAlerts }; | ||
|
||
export default connect(null, mapDispatchToProps)(AdminAlerts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,55 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import moment from 'moment'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { handleResolveAlert } from '../../actions/alert_actions'; | ||
|
||
const Alert = ({ alert, adminAlert, resolveAlert }) => { | ||
let resolveCell; | ||
let alertTypeCell; | ||
|
||
if (adminAlert) { | ||
let resolveText; | ||
let resolveButton; | ||
if (alert.resolved) { | ||
resolveText = '✓'; | ||
} | ||
if (alert.resolvable && !alert.resolved) { | ||
resolveButton = ( | ||
<button className="button small danger dark" onClick={() => resolveAlert(alert.id)}>Resolve</button> | ||
); | ||
} | ||
resolveCell = ( | ||
<td className="desktop-only-tc">{resolveText} {resolveButton}</td> | ||
); | ||
alertTypeCell = ( | ||
<td className="alert-type"> | ||
<a href={`/alerts_list/${alert.id}`}>{alert.type}</a> | ||
</td> | ||
); | ||
} else { | ||
alertTypeCell = <td className="alert-type">{alert.type}</td>; | ||
} | ||
|
||
const Alert = ({ alert }) => { | ||
return ( | ||
<tr className="alert"> | ||
<td className="desktop-only-tc date">{moment(alert.created_at).format('YYYY-MM-DD h:mm A')}</td> | ||
<td className="alert-type">{alert.type}</td> | ||
{alertTypeCell} | ||
<td className="desktop-only-tc"><a target="_blank" href={`/courses/${alert.course_slug}`}>{alert.course}</a></td> | ||
<td className="desktop-only-tc"><a target="_blank" href={`/users/${alert.user}`}>{alert.user}</a></td> | ||
<td><a target="_blank" href={alert.article_url}>{alert.article}</a></td> | ||
{resolveCell} | ||
</tr> | ||
); | ||
}; | ||
|
||
Alert.propTypes = { | ||
alert: PropTypes.object | ||
alert: PropTypes.object, | ||
adminAlert: PropTypes.bool, | ||
resolveAlert: PropTypes.func, | ||
}; | ||
|
||
export default Alert; | ||
const mapDispatchToProps = { resolveAlert: handleResolveAlert }; | ||
|
||
export default connect(null, mapDispatchToProps)(Alert); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
app/assets/javascripts/components/alerts/campaign_alerts.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react'; | ||
import createReactClass from 'create-react-class'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
import AlertsHandler from './alerts_handler.jsx'; | ||
import { fetchCampaignAlerts, filterAlerts } from '../../actions/alert_actions'; | ||
|
||
const CampaignAlerts = createReactClass({ | ||
displayName: 'CampaignAlerts', | ||
propTypes: { | ||
fetchAlerts: PropTypes.func, | ||
filterAlerts: PropTypes.func, | ||
}, | ||
getCampaignSlug() { | ||
return `${this.props.match.params.campaign_slug}`; | ||
}, | ||
UNSAFE_componentWillMount() { | ||
// This adds the specific campaign alerts to the state, to be used in AlertsHandler | ||
this.props.fetchCampaignAlerts(this.getCampaignSlug()); | ||
this.props.filterAlerts(this.defaultFilters); | ||
}, | ||
defaultFilters: [ | ||
{ value: 'ArticlesForDeletionAlert', label: 'Articles For Deletion' }, | ||
{ value: 'DiscretionarySanctionsEditAlert', label: 'Discretionary Sanctions' } | ||
], | ||
render() { | ||
return ( | ||
<AlertsHandler | ||
alertLabel={I18n.t('campaign.alert_label')} | ||
noAlertsLabel={I18n.t('campaign.no_alerts')} | ||
/> | ||
); | ||
} | ||
}); | ||
|
||
const mapDispatchToProps = { fetchCampaignAlerts, filterAlerts }; | ||
|
||
export default connect(null, mapDispatchToProps)(CampaignAlerts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.