This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add system notice feature with API deprecation notice * Update notices.jsx * Update en.json * Updating css for annoucement message * Update snapshots
- Loading branch information
Showing
20 changed files
with
644 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import {ActionTypes} from 'utils/constants'; | ||
|
||
export function dismissNotice(type) { | ||
return (dispatch) => { | ||
dispatch({ | ||
type: ActionTypes.DISMISS_NOTICE, | ||
data: type, | ||
}); | ||
|
||
return {data: true}; | ||
}; | ||
} |
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
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,52 @@ | ||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import {connect} from 'react-redux'; | ||
import {createSelector} from 'reselect'; | ||
import {bindActionCreators} from 'redux'; | ||
import {makeGetCategory} from 'mattermost-redux/selectors/entities/preferences'; | ||
import {haveISystemPermission} from 'mattermost-redux/selectors/entities/roles'; | ||
import {savePreferences} from 'mattermost-redux/actions/preferences'; | ||
import {Permissions} from 'mattermost-redux/constants'; | ||
|
||
import {dismissNotice} from 'actions/views/notice'; | ||
import {Preferences} from 'utils/constants.jsx'; | ||
|
||
import Notices from './notices.jsx'; | ||
import SystemNotice from './system_notice.jsx'; | ||
|
||
function makeMapStateToProps() { | ||
const getCategory = makeGetCategory(); | ||
|
||
const getPreferenceNameMap = createSelector( | ||
getCategory, | ||
(preferences) => { | ||
const nameMap = {}; | ||
preferences.forEach((p) => { | ||
nameMap[p.name] = p; | ||
}); | ||
return nameMap; | ||
} | ||
); | ||
|
||
return function mapStateToProps(state) { | ||
return { | ||
currentUserId: state.entities.users.currentUserId, | ||
preferences: getPreferenceNameMap(state, Preferences.CATEGORY_SYSTEM_NOTICE), | ||
dismissedNotices: state.views.notice.hasBeenDismissed, | ||
isSystemAdmin: haveISystemPermission(state, {permission: Permissions.MANAGE_SYSTEM}), | ||
notices: Notices, | ||
}; | ||
}; | ||
} | ||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
actions: bindActionCreators({ | ||
savePreferences, | ||
dismissNotice, | ||
}, dispatch), | ||
}; | ||
} | ||
|
||
export default connect(makeMapStateToProps, mapDispatchToProps)(SystemNotice); |
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,35 @@ | ||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import React from 'react'; | ||
import {FormattedHTMLMessage} from 'react-intl'; | ||
|
||
import mattermostIcon from 'images/icon50x50.png'; | ||
|
||
// Notices are objects with the following fields: | ||
// - name - string identifier | ||
// - adminOnly - set to true if only system admins should see this message | ||
// - icon - the image to display for the notice icon | ||
// - title - JSX node to display for the notice title | ||
// - body - JSX node to display for the notice body | ||
// | ||
// Order is important! The notices at the top are shown first. | ||
export default [ | ||
{ | ||
name: 'apiv3_deprecation', | ||
adminOnly: true, | ||
title: ( | ||
<FormattedHTMLMessage | ||
id='system_notice.title' | ||
defaultMessage='<strong>System Message</strong> from Mattermost' | ||
/> | ||
), | ||
icon: mattermostIcon, | ||
body: ( | ||
<FormattedHTMLMessage | ||
id='system_notice.body.api3' | ||
defaultMessage='If you’ve created or installed integrations in the last two years, find out how <a href="https://about.mattermost.com/default-apiv3-deprecation-guide" target="_blank">upcoming changes</a> may affect them.' | ||
/> | ||
), | ||
}, | ||
]; |
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,136 @@ | ||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {FormattedMessage} from 'react-intl'; | ||
|
||
import {Preferences} from 'utils/constants.jsx'; | ||
import MattermostLogo from 'components/svg/mattermost_logo'; | ||
|
||
export default class SystemNotice extends React.PureComponent { | ||
static propTypes = { | ||
currentUserId: PropTypes.string.isRequired, | ||
notices: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
preferences: PropTypes.object.isRequired, | ||
dismissedNotices: PropTypes.object.isRequired, | ||
isSystemAdmin: PropTypes.bool, | ||
actions: PropTypes.shape({ | ||
savePreferences: PropTypes.func.isRequired, | ||
dismissNotice: PropTypes.func.isRequired, | ||
}).isRequired, | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
currentNotice: null, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
this.setCurrentNotice(); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
this.setCurrentNotice(nextProps); | ||
} | ||
|
||
setCurrentNotice = (props = this.props) => { | ||
for (const notice of props.notices) { | ||
// Skip if dismissed previously this session | ||
if (props.dismissedNotices[notice.name]) { | ||
continue; | ||
} | ||
|
||
// Skip if dismissed forever | ||
if (props.preferences[notice.name]) { | ||
continue; | ||
} | ||
|
||
if (notice.adminOnly && !props.isSystemAdmin) { | ||
continue; | ||
} | ||
|
||
this.setState({currentNotice: notice}); | ||
return; | ||
} | ||
|
||
this.setState({currentNotice: null}); | ||
} | ||
|
||
hide = (remind = false) => { | ||
const notice = this.state.currentNotice; | ||
if (!notice) { | ||
return; | ||
} | ||
|
||
if (!remind) { | ||
this.props.actions.savePreferences(this.props.currentUserId, [{ | ||
user_id: this.props.currentUserId, | ||
category: Preferences.CATEGORY_SYSTEM_NOTICE, | ||
name: notice.name, | ||
value: 'dismissed', | ||
}]); | ||
} | ||
|
||
this.props.actions.dismissNotice(notice.name); | ||
} | ||
|
||
hideAndRemind = () => { | ||
this.hide(true); | ||
} | ||
|
||
hideAndForget = () => { | ||
this.hide(false); | ||
} | ||
|
||
render() { | ||
const notice = this.state.currentNotice; | ||
|
||
if (notice == null) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
className='system-notice bg--white shadow--2' | ||
> | ||
<div className='system-notice__header'> | ||
<div className='system-notice__logo'> | ||
<MattermostLogo/> | ||
</div> | ||
<div className='system-notice__title'> | ||
{notice.title} | ||
</div> | ||
</div> | ||
<div className='system-notice__body'> | ||
{notice.body} | ||
</div> | ||
<div className='system-notice__footer'> | ||
<button | ||
id='systemnotice_remindme' | ||
className='btn btn-transparent' | ||
onClick={this.hideAndRemind} | ||
> | ||
<FormattedMessage | ||
id='system_notice_remind_me' | ||
defaultMessage='Remind me later' | ||
/> | ||
</button> | ||
<button | ||
id='systemnotice_dontshow' | ||
className='btn btn-transparent' | ||
onClick={this.hideAndForget} | ||
> | ||
<FormattedMessage | ||
id='system_notice_dont_show' | ||
defaultMessage="Don't show again" | ||
/> | ||
</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
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
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,19 @@ | ||
// Copyright (c) 2018-present Mattermost, Inc. All Rights Reserved. | ||
// See License.txt for license information. | ||
|
||
import {combineReducers} from 'redux'; | ||
|
||
import {ActionTypes} from 'utils/constants.jsx'; | ||
|
||
function hasBeenDismissed(state = {}, action) { | ||
switch (action.type) { | ||
case ActionTypes.DISMISS_NOTICE: | ||
return {...state, [action.data]: true}; | ||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default combineReducers({ | ||
hasBeenDismissed, | ||
}); |
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 |
---|---|---|
|
@@ -24,3 +24,4 @@ | |
@import 'videos'; | ||
@import 'webrtc'; | ||
@import 'color-input'; | ||
@import 'system-notice'; |
Oops, something went wrong.