From 89dc139556685c0a1b9fb8c83cd1240729ec8772 Mon Sep 17 00:00:00 2001 From: Matiss Janis Aboltins Date: Tue, 10 Jan 2023 01:34:00 +0000 Subject: [PATCH] chore: remove unsed vars & cleanups (#437) --- .../src/components/LoggedInUser.js | 3 +- packages/loot-core/src/server/aql/compiler.js | 9 +-- .../__snapshots__/spreadsheet.test.js.snap | 5 ++ .../src/server/spreadsheet/spreadsheet.js | 2 +- .../server/spreadsheet/spreadsheet.test.js | 70 +++++++++---------- .../src/svg/AnimatedLoading.mobile.js | 49 ------------- .../src/svg/AnimatedLoading.web.js | 27 ------- 7 files changed, 44 insertions(+), 121 deletions(-) create mode 100644 packages/loot-core/src/server/spreadsheet/__snapshots__/spreadsheet.test.js.snap delete mode 100644 packages/loot-design/src/svg/AnimatedLoading.mobile.js delete mode 100644 packages/loot-design/src/svg/AnimatedLoading.web.js diff --git a/packages/desktop-client/src/components/LoggedInUser.js b/packages/desktop-client/src/components/LoggedInUser.js index d3bae724a6e..9e8bdb09ac9 100644 --- a/packages/desktop-client/src/components/LoggedInUser.js +++ b/packages/desktop-client/src/components/LoggedInUser.js @@ -1,6 +1,6 @@ import React, { useState, useEffect } from 'react'; import { connect } from 'react-redux'; -import { useHistory, withRouter } from 'react-router'; +import { withRouter } from 'react-router'; import * as actions from 'loot-core/src/client/actions'; import { @@ -29,7 +29,6 @@ function LoggedInUser({ let [loading, setLoading] = useState(true); let [menuOpen, setMenuOpen] = useState(false); const serverUrl = useServerURL(); - const history = useHistory(); useEffect(() => { getUserData().then(() => setLoading(false)); diff --git a/packages/loot-core/src/server/aql/compiler.js b/packages/loot-core/src/server/aql/compiler.js index 9491fd8be6c..65e3a444e10 100644 --- a/packages/loot-core/src/server/aql/compiler.js +++ b/packages/loot-core/src/server/aql/compiler.js @@ -560,7 +560,6 @@ const compileFunction = saveStack('function', (state, func) => { } case '$lower': { validateArgLength(args, 1); - // eslint-disable-next-line no-unused-vars let [arg1] = valArray(state, args, ['string']); return typed(`LOWER(${arg1})`, 'string'); } @@ -568,19 +567,17 @@ const compileFunction = saveStack('function', (state, func) => { // integer/float functions case '$neg': { validateArgLength(args, 1); - // eslint-disable-next-line no-unused-vars - let [arg1] = valArray(state, args, ['float']); + valArray(state, args, ['float']); return typed(`(-${val(state, args[0])})`, args[0].type); } case '$abs': { validateArgLength(args, 1); - // eslint-disable-next-line no-unused-vars - let [arg1] = valArray(state, args, ['float']); + valArray(state, args, ['float']); return typed(`ABS(${val(state, args[0])})`, args[0].type); } case '$idiv': { validateArgLength(args, 2); - let [arg1, arg2] = valArray(state, args, ['integer', 'integer']); + valArray(state, args, ['integer', 'integer']); return typed( `(${val(state, args[0])} / ${val(state, args[1])})`, args[0].type diff --git a/packages/loot-core/src/server/spreadsheet/__snapshots__/spreadsheet.test.js.snap b/packages/loot-core/src/server/spreadsheet/__snapshots__/spreadsheet.test.js.snap new file mode 100644 index 00000000000..91479bf3167 --- /dev/null +++ b/packages/loot-core/src/server/spreadsheet/__snapshots__/spreadsheet.test.js.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Spreadsheet querying deep join works 1`] = `"=from transactions where acct.offbudget = 0 and (description.transfer_acct.offbudget = null or description.transfer_acct.offbudget = 1) select { acct.offbudget, description.transfer_acct.offbudget as foo, amount }"`; + +exports[`Spreadsheet querying transactions works 1`] = `"=from transactions select { amount, category }"`; diff --git a/packages/loot-core/src/server/spreadsheet/spreadsheet.js b/packages/loot-core/src/server/spreadsheet/spreadsheet.js index 459be7b0d5c..c2762f2d90a 100644 --- a/packages/loot-core/src/server/spreadsheet/spreadsheet.js +++ b/packages/loot-core/src/server/spreadsheet/spreadsheet.js @@ -183,7 +183,7 @@ export default class Spreadsheet { this.events.emit('change', { names: this.computeQueue }); // Cache the updated cells - if (this.saveCache) { + if (typeof this.saveCache === 'function') { this.saveCache(this.computeQueue); } this.markCacheSafe(); diff --git a/packages/loot-core/src/server/spreadsheet/spreadsheet.test.js b/packages/loot-core/src/server/spreadsheet/spreadsheet.test.js index e1bb3fa029c..61a20a44006 100644 --- a/packages/loot-core/src/server/spreadsheet/spreadsheet.test.js +++ b/packages/loot-core/src/server/spreadsheet/spreadsheet.test.js @@ -8,8 +8,6 @@ function wait(n) { return new Promise(resolve => setTimeout(resolve, n)); } -// TODO: re-enable and fix these tests -// eslint-disable-next-line no-unused-vars async function insertTransactions(payeeId = null) { await db.insertAccount({ id: '1', name: 'checking', offbudget: 0 }); await db.insertAccount({ id: '2', name: 'checking', offbudget: 1 }); @@ -20,7 +18,7 @@ async function insertTransactions(payeeId = null) { await db.insertTransaction( generateTransaction({ amount: -3200, - acct: '1', + account: '1', category: 'cat1', date: '2017-01-08', description: payeeId @@ -29,7 +27,7 @@ async function insertTransactions(payeeId = null) { await db.insertTransaction( generateTransaction({ amount: -2800, - acct: '1', + account: '1', category: 'cat2', date: '2017-01-10', description: payeeId @@ -38,7 +36,7 @@ async function insertTransactions(payeeId = null) { await db.insertTransaction( generateTransaction({ amount: -9832, - acct: '1', + account: '1', category: 'cat2', date: '2017-01-15', description: payeeId @@ -109,40 +107,40 @@ describe('Spreadsheet', () => { // }); // }); - // test('querying transactions works', async () => { - // const spreadsheet = new Spreadsheet(db); - // await insertTransactions(); - - // spreadsheet.startTransaction(); - // spreadsheet.set('g!foo', `=from transactions select { amount, category }`); - // spreadsheet.endTransaction(); - - // return new Promise(resolve => { - // spreadsheet.onFinish(() => { - // expect(spreadsheet.getValue('g!foo')).toMatchSnapshot(); - // resolve(); - // }); - // }); - // }); + test('querying transactions works', async () => { + const spreadsheet = new Spreadsheet(db); + await insertTransactions(); - // test('querying deep join works', async () => { - // const spreadsheet = new Spreadsheet(db); - // let payeeId1 = await db.insertPayee({ name: '', transfer_acct: '1' }); - // let payeeId2 = await db.insertPayee({ name: '', transfer_acct: '2' }); - // await insertTransactions(payeeId2); + spreadsheet.startTransaction(); + spreadsheet.set('g!foo', `=from transactions select { amount, category }`); + spreadsheet.endTransaction(); - // spreadsheet.set( - // 'g!foo', - // '=from transactions where acct.offbudget = 0 and (description.transfer_acct.offbudget = null or description.transfer_acct.offbudget = 1) select { acct.offbudget, description.transfer_acct.offbudget as foo, amount }' - // ); + return new Promise(resolve => { + spreadsheet.onFinish(() => { + expect(spreadsheet.getValue('g!foo')).toMatchSnapshot(); + resolve(); + }); + }); + }); - // return new Promise(resolve => { - // spreadsheet.onFinish(() => { - // expect(spreadsheet.getValue('g!foo')).toMatchSnapshot(); - // resolve(); - // }); - // }); - // }); + test('querying deep join works', async () => { + const spreadsheet = new Spreadsheet(db); + await db.insertPayee({ name: '', transfer_acct: '1' }); + let payeeId2 = await db.insertPayee({ name: '', transfer_acct: '2' }); + await insertTransactions(payeeId2); + + spreadsheet.set( + 'g!foo', + '=from transactions where acct.offbudget = 0 and (description.transfer_acct.offbudget = null or description.transfer_acct.offbudget = 1) select { acct.offbudget, description.transfer_acct.offbudget as foo, amount }' + ); + + return new Promise(resolve => { + spreadsheet.onFinish(() => { + expect(spreadsheet.getValue('g!foo')).toMatchSnapshot(); + resolve(); + }); + }); + }); test('async cells work', done => { const spreadsheet = new Spreadsheet(); diff --git a/packages/loot-design/src/svg/AnimatedLoading.mobile.js b/packages/loot-design/src/svg/AnimatedLoading.mobile.js deleted file mode 100644 index ef5906a21ab..00000000000 --- a/packages/loot-design/src/svg/AnimatedLoading.mobile.js +++ /dev/null @@ -1,49 +0,0 @@ -import React from 'react'; -import { Animated, Easing } from 'react-native'; - -import Loading from './Loading'; - -class AnimatedLoading extends React.Component { - constructor() { - super(); - this.rotation = new Animated.Value(-0.25); - } - - componentDidMount() { - this.animate(); - } - - animate() { - this.rotation.setValue(-0.15); - Animated.timing(this.rotation, { - toValue: 1.85, - duration: 1600, - easing: Easing.bezier(0.17, 0.67, 0.83, 0.67), - useNativeDriver: true - }).start(() => this.animate()); - } - - render() { - const { color, width, height } = this.props; - - return ( - - - - ); - } -} - -export default AnimatedLoading; diff --git a/packages/loot-design/src/svg/AnimatedLoading.web.js b/packages/loot-design/src/svg/AnimatedLoading.web.js deleted file mode 100644 index 2f5398a4ac7..00000000000 --- a/packages/loot-design/src/svg/AnimatedLoading.web.js +++ /dev/null @@ -1,27 +0,0 @@ -import React from 'react'; - -import { css } from 'glamor'; - -import Loading from './Loading'; - -const rotation = css.keyframes({ - '0%': { transform: 'rotate(-90deg)' }, - '100%': { transform: 'rotate(666deg)' } -}); - -function AnimatedLoading({ width, height, style, color }) { - return ( - - - - ); -} - -export default AnimatedLoading;