Skip to content

Commit

Permalink
Merge pull request #165 from sephcoster/api-updates
Browse files Browse the repository at this point in the history
Use a different static download endpoint
  • Loading branch information
sephcoster authored Dec 31, 2019
2 parents 89c5a14 + e43a20f commit d751a3b
Showing 8 changed files with 5 additions and 112 deletions.
12 changes: 1 addition & 11 deletions src/Dialogs/DataExport.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import './DataExport.less'
import {
exportAllResults, exportSomeResults, visitSocrata
exportAllResults, exportSomeResults
} from '../actions/dataExport'
import { bindAll } from '../utils'
import { connect } from 'react-redux'
@@ -204,15 +204,6 @@ export class DataExport extends React.Component {
<label className="a-label" htmlFor="format_json">JSON</label>
</div>
</div>
<div className="other-formats">
Or you can&nbsp;
<button className="a-btn a-btn__link"
data-gtm_ignore="true"
onClick={this.props.onOtherFormats}>
download the data in a different format
</button>
, if needed.
</div>
</div>
}

@@ -281,7 +272,6 @@ export const mapStateToProps = state => {
}

export const mapDispatchToProps = dispatch => ( {
onOtherFormats: () => dispatch( visitSocrata() ),
exportAll: format => dispatch( exportAllResults( format ) ),
exportSome: ( format, size ) => dispatch( exportSomeResults( format, size ) )
} )
11 changes: 0 additions & 11 deletions src/Dialogs/__tests__/DataExport.spec.jsx
Original file line number Diff line number Diff line change
@@ -76,12 +76,6 @@ describe('component::DataExport', () => {
expect(target.state('dataset')).toEqual('filtered')
})

it('provides link to Socrata', () => {
const btn = target.find('.other-formats button')
btn.simulate('click')
expect(props.onOtherFormats).toHaveBeenCalled()
})

describe('clicking Start Export', () => {
let startExport
beforeEach(() => {
@@ -124,11 +118,6 @@ describe('component::DataExport', () => {
})

describe('mapDispatchToProps', () => {
it('provides a way to call visitSocrata', () => {
const dispatch = jest.fn()
mapDispatchToProps(dispatch).onOtherFormats()
expect(dispatch.mock.calls.length).toEqual(1)
})

it('provides a way to call exportAllResults', () => {
const dispatch = jest.fn()
26 changes: 0 additions & 26 deletions src/Dialogs/__tests__/__snapshots__/DataExport.spec.jsx.snap
Original file line number Diff line number Diff line change
@@ -90,19 +90,6 @@ exports[`component::DataExport initial state hides the dataset radio buttons whe
</label>
</div>
</div>
<div
className="other-formats"
>
Or you can 
<button
className="a-btn a-btn__link"
data-gtm_ignore="true"
onClick={[Function]}
>
download the data in a different format
</button>
, if needed.
</div>
</div>
<div
className="timeliness-warning"
@@ -222,19 +209,6 @@ exports[`component::DataExport initial state renders without crashing 1`] = `
</label>
</div>
</div>
<div
className="other-formats"
>
Or you can 
<button
className="a-btn a-btn__link"
data-gtm_ignore="true"
onClick={[Function]}
>
download the data in a different format
</button>
, if needed.
</div>
</div>
<div
className="group"
8 changes: 0 additions & 8 deletions src/Hero.jsx
Original file line number Diff line number Diff line change
@@ -18,9 +18,6 @@ export function showMoreAboutDialog() {

export class Hero extends React.Component {
render() {
const socrataUrl = 'https://data.consumerfinance.gov/dataset/' +
'Consumer-Complaints/s6ew-h6mp'

return (
<header className="content_hero">
<h1 className="content-header">Consumer Complaint Database</h1>
@@ -53,11 +50,6 @@ export class Hero extends React.Component {
Technical documentation
</a>
</li>
<li className="m-list_item">
<a href={socrataUrl} target="_blank">
View complaint data in Socrata
</a>
</li>
</ul>
</header>
);
10 changes: 0 additions & 10 deletions src/__tests__/__snapshots__/App.spec.jsx.snap
Original file line number Diff line number Diff line change
@@ -118,16 +118,6 @@ exports[`initial state renders without crashing 1`] = `
Technical documentation
</a>
</li>
<li
className="m-list_item"
>
<a
href="https://data.consumerfinance.gov/dataset/Consumer-Complaints/s6ew-h6mp"
target="_blank"
>
View complaint data in Socrata
</a>
</li>
</ul>
</header>
<div
10 changes: 0 additions & 10 deletions src/__tests__/__snapshots__/Hero.spec.jsx.snap
Original file line number Diff line number Diff line change
@@ -50,16 +50,6 @@ exports[`initial state renders without crashing 1`] = `
Technical documentation
</a>
</li>
<li
className="m-list_item"
>
<a
href="https://data.consumerfinance.gov/dataset/Consumer-Complaints/s6ew-h6mp"
target="_blank"
>
View complaint data in Socrata
</a>
</li>
</ul>
</header>
`;
16 changes: 1 addition & 15 deletions src/actions/__tests__/dataExport.spec.jsx
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ describe('action:dataExport', () => {
store.dispatch(sut.exportAllResults('json'))
expect(store.getActions()).toEqual(expectedActions)
expect(mockDomUtils.buildLink).toHaveBeenCalledWith(
expect.stringMatching(/.*s6ew-h6mp.*/),
expect.stringMatching(/.*files.consumerfinance.gov.*/),
'download.json'
)
expect(mockDomUtils.simulateClick).toHaveBeenCalled()
@@ -63,19 +63,5 @@ describe('action:dataExport', () => {
})
})

describe('visitSocrata', () => {
it('executes a chain of actions', () => {
const expectedActions = [
{ type: types.MODAL_HID }
]

store.dispatch(sut.visitSocrata())
expect(store.getActions()).toEqual(expectedActions)
expect(mockDomUtils.buildLink).toHaveBeenCalledWith(
expect.stringMatching(/.*s6ew-h6mp.*/)
)
expect(mockDomUtils.simulateClick).toHaveBeenCalled()
})
})
})
})
24 changes: 3 additions & 21 deletions src/actions/dataExport.jsx
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@
// https://stackoverflow.com/questions/3916191

import { buildLink, simulateClick } from './domUtils'
import { MODAL_HID, MODAL_SHOWN, MODAL_TYPE_DATA_EXPORT } from '../constants'
import { MODAL_SHOWN, MODAL_TYPE_DATA_EXPORT } from '../constants'
import Analytics from './analytics'
import { stateToQS } from '../reducers/query'

const DATA_HOST = 'https://data.consumerfinance.gov'
const DATA_HOST = 'https://files.consumerfinance.gov'

// ----------------------------------------------------------------------------
// Action Creators
@@ -39,7 +39,7 @@ export function exportAllResults( format ) {
Analytics.getDataLayerOptions( 'Export All Data', format )
)
return () => {
const uri = DATA_HOST + '/api/views/s6ew-h6mp/rows.' + format
const uri = DATA_HOST + '/ccdb/complaints.' + format + '.zip'
const link = buildLink( uri, 'download.' + format )
simulateClick( link )
}
@@ -71,21 +71,3 @@ export function exportSomeResults( format, size ) {
simulateClick( link )
}
}

/**
* Navigate to Socrata in a different window
*
* @returns {function} a set of steps to execute
*/
export function visitSocrata() {
Analytics.sendEvent(
Analytics.getDataLayerOptions( 'Export', 'User redirects to Socrata' )
)
return dispatch => {
dispatch( { type: MODAL_HID } )

const uri = DATA_HOST + '/dataset/Consumer-Complaints/s6ew-h6mp'
const link = buildLink( uri )
simulateClick( link )
}
}

0 comments on commit d751a3b

Please sign in to comment.