-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Downloading media library archive from the export page. (#27581)
* Add the action types and the action creators for the media export substate. * Implement the media exporter reducer. * Add the data-layer handlers for interacting with the `/sites/{id}/exports/media` endpoint. * Implement a new component specifically for exporting media library: ExportMediaCard. * Implement the selector: get-media-export-data * Implement <QueryMediaExport /> as a query component for sending `requestMediaExport()` action. * Dock <ExportMediaCard /> component into the export page when `export-media` flag is on. * CSS tweaks so <ExportCard /> and <ExportMediaCard /> looks consistent. * Disable the action button if there is no `mediaExportUrl` * Record a track event on clicking the media download button. * Reword and add more detailed description. * Add the test suite for the data-layer handler of `/sites/{id}/exports/media` endpoint. * Rename the selector as `get-media-export-url` and add the test suite. * Trim the nested `mediaExportData` down as a plain `mediaExportUrl` * <QueryMediaExport> should only send the request if the data is not there. * Add the missing action type. * Fix the breaking test. * Show and keep the old subtitle of <ExportCard> when `export-media` is off. * Reword according to editorial comments. * For future proofing, do not show <ExportMedia /> component for Jetpack sites. * Rebase against the latest master. * Add `propTypes` to `<QueryMediaExportData>` component. * Remove `export-media` feature flag from `<ExportCard>` component * Make the whole export card clickable, and reword accordingly. * Add missing `isRequired` declarations to `recordMediaExportClicks` and `translate` * Remove redundant `true` value assignment for `buttonPrimary` * Destructure out `recordMediaExportClick` and simplify the `react-redux` `connect` call. * Remove unnecessary mock. * Remove `export-media` feature flag. * Add two more missing proptypes. * mediaExportUrl shouldn't be required, since it is valid to be null at the beginning. * Remove the `clickableHeader` prop and update the description.
- Loading branch information
Showing
12 changed files
with
299 additions
and
3 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,41 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { requestMediaExport } from 'state/site-settings/exporter/actions'; | ||
import getMediaExportUrl from 'state/selectors/get-media-export-url'; | ||
|
||
class QueryMediaExport extends Component { | ||
static propTypes = { | ||
mediaExportUrl: PropTypes.string, | ||
requestMediaExport: PropTypes.func.isRequired, | ||
siteId: PropTypes.number.isRequired, | ||
}; | ||
|
||
componentDidMount() { | ||
if ( this.props.mediaExportUrl ) { | ||
return; | ||
} | ||
|
||
this.props.requestMediaExport( this.props.siteId ); | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} | ||
|
||
export default connect( | ||
state => ( { | ||
mediaExportUrl: getMediaExportUrl( state ), | ||
} ), | ||
{ requestMediaExport } | ||
)( QueryMediaExport ); |
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,58 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { localize } from 'i18n-calypso'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ActionCard from 'components/action-card'; | ||
import QueryMediaExport from 'components/data/query-media-export'; | ||
import getMediaExportUrl from 'state/selectors/get-media-export-url'; | ||
import { recordTracksEvent } from 'state/analytics/actions'; | ||
|
||
class ExportMediaCard extends Component { | ||
static propTypes = { | ||
siteId: PropTypes.number.isRequired, | ||
mediaExportUrl: PropTypes.string, | ||
recordMediaExportClick: PropTypes.func.isRequired, | ||
translate: PropTypes.func.isRequired, | ||
}; | ||
|
||
render() { | ||
const { mediaExportUrl, siteId, translate, recordMediaExportClick } = this.props; | ||
|
||
return ( | ||
<div className="export-media-card"> | ||
<QueryMediaExport siteId={ siteId } /> | ||
<ActionCard | ||
className="export-media-card__content export-card" | ||
headerText={ translate( 'Export media library' ) } | ||
mainText={ translate( | ||
'Download your entire media library (images, videos, audios …) of your site.' | ||
) } | ||
buttonText={ translate( 'Download' ) } | ||
buttonHref={ mediaExportUrl } | ||
buttonDisabled={ ! mediaExportUrl } | ||
buttonOnClick={ recordMediaExportClick } | ||
compact={ false } | ||
buttonPrimary | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
state => ( { | ||
mediaExportUrl: getMediaExportUrl( state ), | ||
} ), | ||
{ | ||
recordMediaExportClick: () => recordTracksEvent( 'calypso_export_media_download_button_click' ), | ||
} | ||
)( localize( ExportMediaCard ) ); |
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
51 changes: 51 additions & 0 deletions
51
client/state/data-layer/wpcom/sites/exports/media/index.js
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,51 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { translate } from 'i18n-calypso'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { http } from 'state/data-layer/wpcom-http/actions'; | ||
import { dispatchRequestEx } from 'state/data-layer/wpcom-http/utils'; | ||
import { registerHandlers } from 'state/data-layer/handler-registry'; | ||
import { errorNotice } from 'state/notices/actions'; | ||
import { setMediaExportData } from 'state/site-settings/exporter/actions'; | ||
import { EXPORT_MEDIA_REQUEST } from 'state/action-types'; | ||
|
||
export const fetch = action => | ||
http( | ||
{ | ||
method: 'GET', | ||
path: `/sites/${ action.siteId }/exports/media`, | ||
apiNamespace: 'rest/v1.1', | ||
query: { | ||
http_envelope: 1, | ||
}, | ||
}, | ||
action | ||
); | ||
|
||
export const onSuccess = ( action, { mediaExportUrl } ) => setMediaExportData( mediaExportUrl ); | ||
|
||
export const onError = () => | ||
errorNotice( | ||
translate( "We couldn't export your media library at the moment. Please try again later." ) | ||
); | ||
|
||
export const fromApi = response => ( { | ||
mediaExportUrl: response.media_export_url, | ||
} ); | ||
|
||
registerHandlers( 'state/data-layer/wpcom/sites/exports/media/index.js', { | ||
[ EXPORT_MEDIA_REQUEST ]: [ | ||
dispatchRequestEx( { | ||
fetch, | ||
onSuccess, | ||
onError, | ||
fromApi, | ||
} ), | ||
], | ||
} ); |
60 changes: 60 additions & 0 deletions
60
client/state/data-layer/wpcom/sites/exports/media/test/index.js
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,60 @@ | ||
/** @format */ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { http } from 'state/data-layer/wpcom-http/actions'; | ||
import { NOTICE_CREATE } from 'state/action-types'; | ||
import { setMediaExportData } from 'state/site-settings/exporter/actions'; | ||
import { fetch, onSuccess, onError, fromApi } from '../'; | ||
|
||
describe( 'fetch()', () => { | ||
test( 'should dispatch the expected http action.', () => { | ||
const action = { | ||
siteId: 123, | ||
}; | ||
expect( fetch( action ) ).toEqual( | ||
http( | ||
{ | ||
method: 'GET', | ||
path: `/sites/${ action.siteId }/exports/media`, | ||
apiNamespace: 'rest/v1.1', | ||
query: { | ||
http_envelope: 1, | ||
}, | ||
}, | ||
action | ||
) | ||
); | ||
} ); | ||
} ); | ||
|
||
describe( 'onSuccess()', () => { | ||
test( 'should dispatch the action for storing the received data on success.', () => { | ||
const action = { | ||
siteId: 123, | ||
}; | ||
const data = { | ||
mediaExportUrl: 'aaa', | ||
}; | ||
expect( onSuccess( action, data ) ).toEqual( setMediaExportData( data.mediaExportUrl ) ); | ||
} ); | ||
} ); | ||
|
||
describe( 'onError()', () => { | ||
test( 'should dispatch an notice action on error.', () => { | ||
expect( onError().type ).toEqual( NOTICE_CREATE ); | ||
} ); | ||
} ); | ||
|
||
describe( 'fromApi()', () => { | ||
test( 'should convert the encapsulated data as expected.', () => { | ||
expect( | ||
fromApi( { | ||
media_export_url: 'aaa', | ||
} ) | ||
).toEqual( { | ||
mediaExportUrl: 'aaa', | ||
} ); | ||
} ); | ||
} ); |
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,8 @@ | ||
/** @format */ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { get } from 'lodash'; | ||
|
||
export default state => get( state, 'siteSettings.exporter.mediaExportUrl', null ); |
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,25 @@ | ||
/** @format */ | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import getMediaExportUrl from 'state/selectors/get-media-export-url'; | ||
|
||
describe( 'getMediaExportUrl()', () => { | ||
test( 'should return the stored media export url field.', () => { | ||
const mediaExportUrl = 'https://examples.com/profit'; | ||
expect( | ||
getMediaExportUrl( { | ||
siteSettings: { | ||
exporter: { | ||
mediaExportUrl, | ||
}, | ||
}, | ||
} ) | ||
).toEqual( mediaExportUrl ); | ||
} ); | ||
|
||
test( 'should default to null.', () => { | ||
expect( getMediaExportUrl( {} ) ).toBeNull(); | ||
} ); | ||
} ); |
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
Oops, something went wrong.