@bufferapp/report-list
Advanced tools
Comparing version 1.72.1 to 1.73.0
@@ -1,8 +0,6 @@ | ||
import React from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from 'styled-components'; | ||
import { | ||
ChartStateLoading as Loading, | ||
EmptyState, | ||
} from '@bufferapp/analyze-shared-components'; | ||
import { useUser } from '@bufferapp/app-shell'; | ||
import { ChartStateLoading as Loading, EmptyState, } from '@bufferapp/analyze-shared-components'; | ||
import Report from '../Report'; | ||
@@ -23,4 +21,11 @@ | ||
const ReportList = ({ loading, reports, selectReport, removeReport, small }) => | ||
(loading ? | ||
const ReportList = ({ loading, reports, selectReport, removeReport, small, fetch }) => { | ||
const user = useUser(); | ||
useEffect(function fetchReports() { | ||
if (user.currentOrganization.id) { | ||
fetch(user.currentOrganization.id); | ||
} | ||
}, [user.currentOrganization.id]); | ||
return (loading ? | ||
<Centered> | ||
@@ -48,3 +53,5 @@ <Loading active noBorder transparent /> | ||
); | ||
} | ||
ReportList.defaultProps = { | ||
@@ -66,4 +73,5 @@ reports: [], | ||
small: PropTypes.bool, | ||
fetch: PropTypes.func, | ||
}; | ||
export default ReportList; |
@@ -14,2 +14,3 @@ import { push } from 'connected-react-router'; | ||
removeReport: id => dispatch(actions.removeReport(id)), | ||
fetch: id => dispatch(actions.fetch(id)), | ||
}), | ||
@@ -16,0 +17,0 @@ )(ReportList); |
@@ -8,12 +8,9 @@ import { LOCATION_CHANGE } from 'connected-react-router'; | ||
switch (action.type) { | ||
case `profiles_${actionTypes.FETCH_SUCCESS}`: { | ||
const profiles = getAllProfilesFromResult(action.result); | ||
if (profiles.length) { | ||
store.dispatch(actions.fetch({ | ||
name: 'list_reports', | ||
args: { | ||
organizationId: profiles[0].organizationId, | ||
}, | ||
})); | ||
} | ||
case reportListActionTypes.FETCH: { | ||
store.dispatch(actions.fetch({ | ||
name: 'list_reports', | ||
args: { | ||
organizationId: action.id, | ||
}, | ||
})); | ||
break; | ||
@@ -39,2 +36,10 @@ } | ||
break; | ||
case 'ORGANIZATION_CHANGED': | ||
store.dispatch(actions.fetch({ | ||
name: 'list_reports', | ||
args: { | ||
organizationId: action.organizationId, | ||
}, | ||
})); | ||
break; | ||
default: | ||
@@ -41,0 +46,0 @@ break; |
@@ -28,11 +28,6 @@ import { actions, actionTypes } from '@bufferapp/async-data-fetch'; | ||
it('should fetch the reports list on profiles load', () => { | ||
it('should fetch the reports list on ORGANIZATION_CHANGED', () => { | ||
const action = { | ||
type: `profiles_${actionTypes.FETCH_SUCCESS}`, | ||
result: { | ||
social: [{ | ||
organizationId: 'organization1234', | ||
}], | ||
nonSocial: [] | ||
}, | ||
type: 'ORGANIZATION_CHANGED', | ||
organizationId: 'organization1234' | ||
}; | ||
@@ -39,0 +34,0 @@ middleware(store)(next)(action); |
{ | ||
"name": "@bufferapp/report-list", | ||
"version": "1.72.1", | ||
"version": "1.73.0", | ||
"description": "Report list package for Analyze", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@bufferapp/analyze-shared-components": "^1.72.1" | ||
"@bufferapp/analyze-shared-components": "^1.73.0" | ||
}, | ||
@@ -25,3 +25,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "378ccdbb558b3384d497d384a4a621a4a9f39272" | ||
"gitHead": "1c8558a5e1bca7c468e3091361662c9bbcf6fb33" | ||
} |
@@ -6,2 +6,3 @@ import { actionTypes as asyncDataFetchActionTypes } from '@bufferapp/async-data-fetch'; | ||
REMOVE_REPORT: 'REMOVE_REPORT', | ||
FETCH: 'FETCH' | ||
}); | ||
@@ -56,2 +57,6 @@ | ||
}), | ||
fetch: id => ({ | ||
type: actionTypes.FETCH, | ||
id, | ||
}) | ||
}; |
222108
51
1327