diff --git a/src/admin/actions/GetAudit.js b/src/admin/actions/GetAudit.js index 7165cda244030e4fa01a778b525d330c64b4b561..67f0acca8921029e2f28a3972c76bca37c7d1add 100644 --- a/src/admin/actions/GetAudit.js +++ b/src/admin/actions/GetAudit.js @@ -6,6 +6,9 @@ export const GET_AUDIT = 'GET_AUDIT'; export const GET_AUDIT_SUCCESS = 'GET_AUDIT_SUCCESS'; export const GET_AUDIT_FAILURE = 'GET_AUDIT_FAILURE'; +export const GET_CHANNEL_PATH = 'channels'; +export const GET_NOTIFICATION_PATH = 'notifications'; + export const getAudit = (target, id) => ({ [RSAA]: { endpoint: `${process.env.REACT_APP_BASE_URL}/audit/${target}/${id}`, diff --git a/src/admin/components/AuditDisplay.jsx b/src/admin/components/AuditDisplay.jsx index 0c5d53584f1d93efb5166a50f50356d0a0d48a2a..326df30767fff6ae71cd59ab271ad43e4488b597 100644 --- a/src/admin/components/AuditDisplay.jsx +++ b/src/admin/components/AuditDisplay.jsx @@ -5,14 +5,17 @@ import {connect} from 'react-redux'; import {Button, Form, Header, Modal} from 'semantic-ui-react'; import isEmpty from 'lodash/isEmpty'; -import * as getAudit from 'admin/actions/GetAudit'; +import * as getAuditActionCreator from 'admin/actions/GetAudit'; import * as showSnackBarActionCreator from 'common/actions/Snackbar'; import JSONTree from 'react-json-tree'; +import {GET_CHANNEL_PATH, GET_NOTIFICATION_PATH} from 'admin/actions/GetAudit'; -const AuditDisplay = ({showSnackbar, loadingAudit, getAudit, auditData}) => { - const [searchId, setSearchId] = useState(''); +const AuditDisplay = ({showSnackbar, loadingAudit, auditData, getAudit}) => { + const [channelId, setChannelId] = useState(''); + const [notificationId, setNotificationId] = useState(''); const [open, setOpen] = useState(false); + const [downloadId, setDownloadId] = useState(''); const theme = { scheme: 'monokai', @@ -35,7 +38,7 @@ const AuditDisplay = ({showSnackbar, loadingAudit, getAudit, auditData}) => { base0F: '#cc6633', }; - async function loadAudit(prefix) { + async function loadAudit(prefix, searchId) { if (!searchId) return; const response = await getAudit(prefix, searchId); @@ -46,6 +49,7 @@ const AuditDisplay = ({showSnackbar, loadingAudit, getAudit, auditData}) => { ); } else { setOpen(true); + setDownloadId(`${prefix}-${searchId}`); showSnackbar('The audit has been loaded successfully', 'success'); } } @@ -61,9 +65,9 @@ const AuditDisplay = ({showSnackbar, loadingAudit, getAudit, auditData}) => { name="notificationId" placeholder="Notification ID" // value={searchId} - onChange={(e, d) => setSearchId(d.value)} + onChange={(e, d) => setNotificationId(d.value)} /> - <Button type="button" onClick={() => loadAudit('notifications')}> + <Button type="button" onClick={() => loadAudit(GET_NOTIFICATION_PATH, notificationId)}> Show Notification Audit </Button> </Form.Group> @@ -75,9 +79,9 @@ const AuditDisplay = ({showSnackbar, loadingAudit, getAudit, auditData}) => { name="channelId" placeholder="Channel ID" // value={searchId} - onChange={(e, d) => setSearchId(d.value)} + onChange={(e, d) => setChannelId(d.value)} /> - <Button type="button" onClick={() => loadAudit('channels')}> + <Button type="button" onClick={() => loadAudit(GET_CHANNEL_PATH, channelId)}> Show Channel Audit </Button> </Form.Group> @@ -104,7 +108,7 @@ const AuditDisplay = ({showSnackbar, loadingAudit, getAudit, auditData}) => { href={URL.createObjectURL( new Blob([JSON.stringify(auditData)], {type: 'application/json'}) )} - download={`${searchId}.json`} + download={`${downloadId}.json`} icon="download" /> <Button onClick={() => setOpen(false)}>Close</Button> @@ -117,7 +121,9 @@ const AuditDisplay = ({showSnackbar, loadingAudit, getAudit, auditData}) => { AuditDisplay.propTypes = { showSnackbar: PropTypes.func.isRequired, - loadingAudit: PropTypes.bool, + loadingAudit: PropTypes.bool.isRequired, + auditData: PropTypes.oneOfType([PropTypes.object]).isRequired, + getAudit: PropTypes.func.isRequired, }; const mapStateToProps = state => { @@ -130,7 +136,7 @@ const mapStateToProps = state => { const mapDispatchToProps = dispatch => { return { ...bindActionCreators(showSnackBarActionCreator, dispatch), - ...bindActionCreators(getAudit, dispatch), + ...bindActionCreators(getAuditActionCreator, dispatch), }; };