From ce161d45d6c269c2b6e2db273e1d85b65f1862a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Oliveira?= Date: Thu, 26 Aug 2021 13:23:52 +0100 Subject: [PATCH] refactor: reuse tx to csv gql query and overall function simplification --- .../src/components/LogsDownloaderPopper.js | 52 +++++++++---------- .../src/pages/Transactions/Transactions.js | 17 ++---- 2 files changed, 30 insertions(+), 39 deletions(-) diff --git a/new-lamassu-admin/src/components/LogsDownloaderPopper.js b/new-lamassu-admin/src/components/LogsDownloaderPopper.js index d0fc8f2b..9d64082f 100644 --- a/new-lamassu-admin/src/components/LogsDownloaderPopper.js +++ b/new-lamassu-admin/src/components/LogsDownloaderPopper.js @@ -134,26 +134,22 @@ const SIMPLIFIED = 'simplified' const LogsDownloaderPopover = ({ name, - queries, + query, args, title, getLogs, timezone, - getSimplifiedLogs + simplified }) => { const [selectedRadio, setSelectedRadio] = useState(ALL) const [selectedAdvancedRadio, setSelectedAdvancedRadio] = useState(ADVANCED) const [range, setRange] = useState({ from: null, until: null }) const [anchorEl, setAnchorEl] = useState(null) - const [fetchLogs] = useLazyQuery(queries[0], { + const [fetchLogs] = useLazyQuery(query, { onCompleted: data => createLogsFile(getLogs(data), range) }) - const [fetchSimplifiedLogs] = useLazyQuery(queries[1], { - onCompleted: data => createLogsFile(getSimplifiedLogs(data), range) - }) - const classes = useStyles() const dateRangePickerClasses = { @@ -170,7 +166,6 @@ const LogsDownloaderPopover = ({ const handleAdvancedRadioButtons = evt => { const selectedAdvancedRadio = R.path(['target', 'value'])(evt) setSelectedAdvancedRadio(selectedAdvancedRadio) - if (selectedAdvancedRadio === ALL) setRange({ from: null, until: null }) } const handleRangeChange = useCallback( @@ -181,12 +176,11 @@ const LogsDownloaderPopover = ({ ) const downloadLogs = (range, args) => { - const fetch = - selectedAdvancedRadio === SIMPLIFIED ? fetchSimplifiedLogs : fetchLogs if (selectedRadio === ALL) { - fetch({ + fetchLogs({ variables: { - ...args + ...args, + simplified: selectedAdvancedRadio === SIMPLIFIED } }) } @@ -196,11 +190,12 @@ const LogsDownloaderPopover = ({ if (moment(range.from).isSame(range.until, 'day')) range.until = moment() if (selectedRadio === RANGE) { - fetch({ + fetchLogs({ variables: { ...args, from: range.from, - until: range.until + until: range.until, + simplified: selectedAdvancedRadio === SIMPLIFIED } }) } @@ -235,7 +230,10 @@ const LogsDownloaderPopover = ({ const radioButtonOptions = [ { display: 'All logs', code: ALL }, - { display: 'Date range', code: RANGE }, + { display: 'Date range', code: RANGE } + ] + + const advancedRadioButtonOptions = [ { display: 'Advanced logs', code: ADVANCED }, { display: 'Simplified logs', code: SIMPLIFIED } ] @@ -259,7 +257,7 @@ const LogsDownloaderPopover = ({ )} -
- -
+ {simplified && ( +
+ +
+ )}
downloadLogs(range, args)}> Download diff --git a/new-lamassu-admin/src/pages/Transactions/Transactions.js b/new-lamassu-admin/src/pages/Transactions/Transactions.js index fc62fedb..a9b576bb 100644 --- a/new-lamassu-admin/src/pages/Transactions/Transactions.js +++ b/new-lamassu-admin/src/pages/Transactions/Transactions.js @@ -33,12 +33,14 @@ const GET_DATA = gql` const GET_TRANSACTIONS_CSV = gql` query transactions( + $simplified: Boolean $limit: Int $from: Date $until: Date $timezone: String ) { transactionsCsv( + simplified: $simplified limit: $limit from: $from until: $until @@ -56,12 +58,6 @@ const GET_TRANSACTION_FILTERS = gql` } ` -const GET_SIMPLIFIED_TRANSACTIONS_CSV = gql` - query transactions($limit: Int, $from: Date, $until: Date) { - simplifiedTransactionsCsv(limit: $limit, from: $from, until: $until) - } -` - const GET_TRANSACTIONS = gql` query transactions( $limit: Int @@ -282,14 +278,9 @@ const Transactions = () => { R.path(['transactionsCsv'])(logs)} - getSimplifiedLogs={logs => - R.path(['simplifiedTransactionsCsv'])(logs) - } + simplified />
)}