-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use ui alertbar instead of material-ui (#1149)
The following changes have been made in this PR: * switch from material-ui to @dhis2/ui AlertStack/AlertBar. ** One consequence of this is that we lose the formatting (bold) of the dashboard name in the message. ** Slight visual difference - previously the bar rested on the bottom of the viewport, now it is positioned slightly above the bottom * rename snackbar to alert for reducers, actions and the component * simplify the alert redux store to only include the message string
- Loading branch information
1 parent
2077c78
commit 6fb0c99
Showing
16 changed files
with
177 additions
and
295 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,10 @@ | ||
import { SET_ALERT_MESSAGE, CLEAR_ALERT_MESSAGE } from '../reducers/alert' | ||
|
||
export const acSetAlertMessage = value => ({ | ||
type: SET_ALERT_MESSAGE, | ||
value, | ||
}) | ||
|
||
export const acClearAlertMessage = () => ({ | ||
type: CLEAR_ALERT_MESSAGE, | ||
}) |
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 was deleted.
Oops, something went wrong.
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,29 @@ | ||
import React from 'react' | ||
import { connect } from 'react-redux' | ||
import { AlertBar, AlertStack } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
|
||
import { sGetAlertMessage } from '../../reducers/alert' | ||
import { acClearAlertMessage } from '../../actions/alert' | ||
|
||
export const Alert = ({ message, onClose }) => | ||
message ? ( | ||
<AlertStack> | ||
<AlertBar onHidden={onClose} permanent> | ||
{message} | ||
</AlertBar> | ||
</AlertStack> | ||
) : null | ||
|
||
Alert.propTypes = { | ||
message: PropTypes.string, | ||
onClose: PropTypes.func, | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
message: sGetAlertMessage(state), | ||
}) | ||
|
||
export default connect(mapStateToProps, { | ||
onClose: acClearAlertMessage, | ||
})(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import toJson from 'enzyme-to-json' | ||
import { Alert } from '../AlertBar' | ||
|
||
describe('AlertBar', () => { | ||
it('renders alert message', () => { | ||
const AlertBar = shallow( | ||
<Alert message="Luke I am your father" onClose={jest.fn()} /> | ||
) | ||
expect(toJson(AlertBar)).toMatchSnapshot() | ||
}) | ||
|
||
it('renders nothing when no message', () => { | ||
const AlertBar = shallow(<Alert />) | ||
expect(toJson(AlertBar)).toMatchSnapshot() | ||
}) | ||
}) |
19 changes: 19 additions & 0 deletions
19
src/components/AlertBar/__tests__/__snapshots__/AlertBar.spec.js.snap
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 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AlertBar renders alert message 1`] = ` | ||
<AlertStack | ||
dataTest="dhis2-uicore-alertstack" | ||
> | ||
<AlertBar | ||
dataTest="dhis2-uicore-alertbar" | ||
duration={8000} | ||
icon={true} | ||
onHidden={[MockFunction]} | ||
permanent={true} | ||
> | ||
Luke I am your father | ||
</AlertBar> | ||
</AlertStack> | ||
`; | ||
|
||
exports[`AlertBar renders nothing when no message 1`] = `""`; |
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 was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
src/components/SnackbarMessage/__tests__/SnackbarMessage.spec.js
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import reducer, { | ||
DEFAULT_STATE_ALERT, | ||
SET_ALERT_MESSAGE, | ||
CLEAR_ALERT_MESSAGE, | ||
sGetAlertMessage, | ||
} from '../alert' | ||
|
||
describe('alert reducer', () => { | ||
it('should return the default state', () => { | ||
const actualState = reducer(undefined, {}) | ||
|
||
expect(actualState).toEqual(DEFAULT_STATE_ALERT) | ||
}) | ||
|
||
it('sets the alert message', () => { | ||
const message = 'Loading dashboard: Rainbow dash' | ||
const action = { | ||
type: SET_ALERT_MESSAGE, | ||
value: message, | ||
} | ||
|
||
const expectedState = message | ||
|
||
const actualState = reducer(DEFAULT_STATE_ALERT, action) | ||
expect(actualState).toEqual(expectedState) | ||
}) | ||
|
||
it('clears the alert message', () => { | ||
const action = { | ||
type: CLEAR_ALERT_MESSAGE, | ||
} | ||
|
||
const currentState = 'Loading dashboard: Rainbow dash' | ||
|
||
const actualState = reducer(currentState, action) | ||
|
||
expect(actualState).toEqual(DEFAULT_STATE_ALERT) | ||
}) | ||
|
||
it('gets the current message from state', () => { | ||
const message = 'Loading dashboard: Rainbow dash' | ||
const action = { | ||
type: SET_ALERT_MESSAGE, | ||
value: message, | ||
} | ||
const alert = reducer(null, action) | ||
|
||
const messageInState = sGetAlertMessage({ alert }) | ||
|
||
expect(messageInState).toEqual(message) | ||
}) | ||
}) |
Oops, something went wrong.