Skip to content

Commit bf2288f

Browse files
authored
Merge pull request #1018 from alexstotsky/open-exported-file-in-os-manager
(feature) Open exported report in the file manager
2 parents f8664da + 27d5a80 commit bf2288f

9 files changed

Lines changed: 87 additions & 5 deletions

File tree

src/components/ExportSuccessDialog/ExportSuccessDialog.container.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { connect } from 'react-redux'
33
import { withRouter } from 'react-router-dom'
44
import { withTranslation } from 'react-i18next'
55

6+
import { openExportFolder } from 'state/query/actions'
67
import { getLocalExportPath, getRemoteUrn } from 'state/query/selectors'
78
import { toggleExportSuccessDialog } from 'state/ui/actions'
89
import { getIsExportSuccessDialogOpen } from 'state/ui/selectors'
@@ -16,6 +17,7 @@ const mapStateToProps = state => ({
1617
})
1718

1819
const mapDispatchToProps = {
20+
openExportFolder,
1921
toggleDialog: toggleExportSuccessDialog,
2022
}
2123

src/components/ExportSuccessDialog/ExportSuccessDialog.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const ExportSuccessDialog = ({
1717
remoteUrn,
1818
toggleDialog,
1919
localExportPath,
20+
openExportFolder,
2021
}) => {
2122
if (!isOpen) {
2223
return null
@@ -37,7 +38,7 @@ const ExportSuccessDialog = ({
3738
{t('download.remoteStorage')}
3839
</a>
3940
) : (
40-
<span>
41+
<span onClick={openExportFolder}>
4142
{localExportPath}
4243
</span>
4344
)
@@ -73,6 +74,7 @@ ExportSuccessDialog.propTypes = {
7374
t: PropTypes.func.isRequired,
7475
isOpen: PropTypes.bool.isRequired,
7576
toggleDialog: PropTypes.func.isRequired,
77+
openExportFolder: PropTypes.func.isRequired,
7678
}
7779
ExportSuccessDialog.defaultProps = {
7880
remoteUrn: null,

src/components/ExportSuccessDialog/_ExportSuccessDialog.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
text-align: center;
1111

1212
span {
13+
cursor: pointer;
1314
color: var(--thColor);
15+
text-decoration: underline;
1416
}
1517
}
1618

src/state/query/actions.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,26 @@ export function setIsPdfRequired(isPdfRequired) {
6767
}
6868
}
6969

70+
export function openExportFolder() {
71+
return {
72+
type: types.OPEN_EXPORT_FOLDER,
73+
}
74+
}
75+
76+
export function setIsSingleExport(isSingleExport) {
77+
return {
78+
type: types.SET_IS_SINGLE_EXPORT,
79+
payload: isSingleExport,
80+
}
81+
}
82+
83+
export function setFirstExportPath(path) {
84+
return {
85+
type: types.SET_FIRST_EXPORT_PATH,
86+
payload: path,
87+
}
88+
}
89+
7090
export default {
7191
exportReport,
7292
setRemoteUrn,
@@ -75,4 +95,7 @@ export default {
7595
setIsPdfRequired,
7696
setIsReportExporting,
7797
setLocalExportPath,
98+
openExportFolder,
99+
setIsSingleExport,
100+
setFirstExportPath,
78101
}

src/state/query/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export default {
4545
SET_IS_PDF_REQUIRED: 'BITFINEX/EXPORT/IS_PDF_REQUIRED',
4646
PREPARE_EXPORT: 'BITFINEX/EXPORT/PREPARE',
4747
SET_EXPORT_EMAIL: 'BITFINEX/EMAIL/EXPORT',
48+
OPEN_EXPORT_FOLDER: 'BITFINEX/EXPORT_FOLDER/OPEN',
49+
SET_IS_SINGLE_EXPORT: 'BITFINEX/EXPORT/IS_SINGLE_EXPORT',
50+
SET_FIRST_EXPORT_PATH: 'BITFINEX/EXPORT/FIRST_EXPORT_PATH',
4851
FILTER_ID: 'id',
4952
FILTER_PAIR: 'pair',
5053
FILTER_SYMBOL: 'symbol',

src/state/query/reducer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const initialState = {
88
remoteUrn: null,
99
isReportExporting: false,
1010
isPDFRequired: false,
11+
isSingleExport: true,
12+
firstExportPath: null,
1113
}
1214

1315
export function queryReducer(state = initialState, action) {
@@ -38,6 +40,16 @@ export function queryReducer(state = initialState, action) {
3840
...state,
3941
isPDFRequired: payload,
4042
}
43+
case types.SET_IS_SINGLE_EXPORT:
44+
return {
45+
...state,
46+
isSingleExport: payload,
47+
}
48+
case types.SET_FIRST_EXPORT_PATH:
49+
return {
50+
...state,
51+
firstExportPath: payload,
52+
}
4153
case authTypes.LOGOUT:
4254
return initialState
4355
default:

src/state/query/saga.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import _assign from 'lodash/assign'
99
import _isArray from 'lodash/isArray'
1010
import _includes from 'lodash/includes'
1111

12+
import { logger } from 'utils/logger'
1213
import { LANGUAGES } from 'locales/i18n'
1314
import { makeFetchCall } from 'state/utils'
1415
import { formatRawSymbols, mapRequestSymbols, mapRequestPairs } from 'state/symbols/utils'
@@ -61,15 +62,21 @@ import config from 'config'
6162

6263
import actions from './actions'
6364
import types from './constants'
64-
import { getExportEmail, getIsPdfExportRequired } from './selectors'
65+
import {
66+
getExportEmail,
67+
getIsSingleExport,
68+
getLocalExportPath,
69+
getFirstExportPath,
70+
getIsPdfExportRequired,
71+
} from './selectors'
6572
import {
6673
getQueryLimit,
6774
NO_TIME_FRAME_TARGETS,
6875
NO_QUERY_LIMIT_TARGETS,
6976
} from './utils'
7077

7178

72-
const { showFrameworkMode } = config
79+
const { isElectronApp, showFrameworkMode } = config
7380
const {
7481
MENU_ACCOUNT_BALANCE,
7582
MENU_AFFILIATES_EARNINGS,
@@ -467,7 +474,22 @@ function* prepareExport() {
467474
}
468475
}
469476

477+
function* openExportFolder() {
478+
if (isElectronApp) {
479+
const filePath = yield select(getFirstExportPath)
480+
const folderPath = yield select(getLocalExportPath)
481+
const isSingleExport = yield select(getIsSingleExport)
482+
const fullPath = isSingleExport ? filePath : folderPath
483+
try {
484+
yield call(window.bfxReportElectronApi.showItemInFolder, { fullPath })
485+
} catch (error) {
486+
yield call(logger.error, error)
487+
}
488+
}
489+
}
490+
470491
export default function* exportSaga() {
471492
yield takeLatest(types.PREPARE_EXPORT, prepareExport)
472493
yield takeLatest(types.EXPORT_REPORT, exportReport)
494+
yield takeLatest(types.OPEN_EXPORT_FOLDER, openExportFolder)
473495
}

src/state/query/selectors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ export const getExportEmail = state => getQuery(state).exportEmail
55
export const getLocalExportPath = state => getQuery(state).localExportPath
66
export const getIsReportExporting = state => getQuery(state)?.isReportExporting ?? false
77
export const getIsPdfExportRequired = state => getQuery(state)?.isPDFRequired ?? false
8+
export const getIsSingleExport = state => getQuery(state)?.isSingleExport ?? true
9+
export const getFirstExportPath = state => getQuery(state)?.firstExportPath ?? null
810

911
export default {
1012
getQuery,
@@ -13,4 +15,6 @@ export default {
1315
getIsReportExporting,
1416
getLocalExportPath,
1517
getIsPdfExportRequired,
18+
getIsSingleExport,
19+
getFirstExportPath,
1620
}

src/state/ws/saga.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import { call, put, takeLatest } from 'redux-saga/effects'
2+
import _get from 'lodash/get'
3+
import _size from 'lodash/size'
4+
import _first from 'lodash/first'
25

36
import { initSync } from 'state/sync/saga'
47
import { authExpired } from 'state/auth/actions'
58
import { updateSyncStatus } from 'state/sync/actions'
6-
import { setIsReportExporting } from 'state/query/actions'
9+
import {
10+
setIsSingleExport,
11+
setFirstExportPath,
12+
setIsReportExporting,
13+
} from 'state/query/actions'
714
import { updateStatus, updateWarningStatus } from 'state/status/actions'
815
import {
916
toggleExportDialog,
@@ -35,7 +42,12 @@ function* handleTokenAuthRequired() {
3542
yield put(authExpired())
3643
}
3744

38-
function* handleReportGenerationCompleted() {
45+
function* handleReportGenerationCompleted({ payload }) {
46+
const files = payload?.result?.reportFilesMetadata
47+
const isSingleExport = _size(files) === 1
48+
const firstFilePath = _get(_first(files), 'filePath')
49+
yield put(setIsSingleExport(isSingleExport))
50+
yield put(setFirstExportPath(firstFilePath))
3951
yield put(setIsReportExporting(false))
4052
yield put(toggleExportDialog())
4153
yield put(toggleExportSuccessDialog())

0 commit comments

Comments
 (0)