From 908918c43d60a3c906656fc92b7bb2527cdbe788 Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Mon, 16 Sep 2024 21:10:27 +0200 Subject: [PATCH 1/9] fix: Bad params being sent upon categories creation --- src/common/utils/remove-keys.ts | 9 +++++++++ src/pages/settings/subpages/categories/index.vue | 14 +++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 src/common/utils/remove-keys.ts diff --git a/src/common/utils/remove-keys.ts b/src/common/utils/remove-keys.ts new file mode 100644 index 00000000..47c990f4 --- /dev/null +++ b/src/common/utils/remove-keys.ts @@ -0,0 +1,9 @@ +export function removeNullishValues(obj: T): Partial { + return Object.entries(obj).reduce((acc, [key, value]) => { + if (value === null || value === undefined) { + return acc; + } + acc[key as keyof T] = value; + return acc; + }, {} as Partial); +} diff --git a/src/pages/settings/subpages/categories/index.vue b/src/pages/settings/subpages/categories/index.vue index 56f60673..7a2ba235 100644 --- a/src/pages/settings/subpages/categories/index.vue +++ b/src/pages/settings/subpages/categories/index.vue @@ -102,6 +102,7 @@ import InputField from "@/components/fields/input-field.vue"; import UiButton from "@/components/common/ui-button.vue"; import { type FormattedCategory } from "@/common/types"; import { ApiErrorResponseError } from "@/js/errors"; +import { removeNullishValues } from "@/common/utils/remove-keys"; defineOptions({ name: "settings-categories", @@ -153,18 +154,17 @@ const applyChanges = async () => { name: form.name, }); } else if (isCreating.value) { - let params: Parameters[0] = { - name: form.name, - imageUrl: "", - color: "", - }; + type InputParams = Parameters[0]; + + let params: InputParams = { name: form.name }; + if (selectedCategory.value) { - params = { + params = removeNullishValues({ ...params, imageUrl: selectedCategory.value.imageUrl, color: selectedCategory.value.color, parentId: selectedCategory.value.id, - }; + }) as InputParams; } await createCategory(params); } From ab1e36044f8294e6fd6e40104f4ce18040457be3 Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Mon, 16 Sep 2024 21:11:44 +0200 Subject: [PATCH 2/9] chore: Increate categories dropdown height --- src/components/fields/category-select-field.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/fields/category-select-field.vue b/src/components/fields/category-select-field.vue index f221cd77..7e8e18e0 100644 --- a/src/components/fields/category-select-field.vue +++ b/src/components/fields/category-select-field.vue @@ -348,7 +348,7 @@ onBeforeUnmount(() => { } .category-select-field__dropdown-values { overflow: auto; - max-height: 250px; + max-height: 350px; } .category-select-field__dropdown-item { display: flex; From a781ae0273ff546d2613513e739dace4292f6828 Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Mon, 16 Sep 2024 21:12:47 +0200 Subject: [PATCH 3/9] fix: Account creation btn color --- .../modify-record/components/account-field.vue | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/components/modals/modify-record/components/account-field.vue b/src/components/modals/modify-record/components/account-field.vue index 7bba72dc..0afe1c2c 100644 --- a/src/components/modals/modify-record/components/account-field.vue +++ b/src/components/modals/modify-record/components/account-field.vue @@ -45,7 +45,10 @@ @@ -101,14 +104,3 @@ const updateFormAccount = (account: AccountModel) => { emit("update:account", account); }; - - From 2179afe07e2e73b92e43512f1486b4d6b7a73a6e Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Mon, 16 Sep 2024 21:22:31 +0200 Subject: [PATCH 4/9] fix: "Expenses Structure" prev month % diff calculation --- src/components/widgets/expenses-structure.vue | 4 +- .../calculate-percentage-difference.spec.ts | 42 ++++++++++++------- .../math/calculate-percentage-difference.ts | 9 ++-- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/components/widgets/expenses-structure.vue b/src/components/widgets/expenses-structure.vue index bbcd66ee..8c607b90 100644 --- a/src/components/widgets/expenses-structure.vue +++ b/src/components/widgets/expenses-structure.vue @@ -19,8 +19,8 @@
{{ `${expensesDiff}%` }} diff --git a/src/js/helpers/math/calculate-percentage-difference.spec.ts b/src/js/helpers/math/calculate-percentage-difference.spec.ts index 59591ff7..c274260f 100644 --- a/src/js/helpers/math/calculate-percentage-difference.spec.ts +++ b/src/js/helpers/math/calculate-percentage-difference.spec.ts @@ -3,35 +3,45 @@ import { calculatePercentageDifference } from "./calculate-percentage-difference describe("calculatePercentageDifference", () => { test.each([ [0, 0, 0, "returns 0 when both numbers are 0"], - [0, 10, 100, "returns 100 when one number is 0"], - [10, 0, 100, "returns 100 when one number is 0"], - [20, -20, 100, "returns 100 when numbers have opposite signs"], - [-15, 15, 100, "returns 100 when numbers have opposite signs"], + [0, 10, -100, "returns -100 when first number is 0"], + [10, 0, 100, "returns 100 when second number is 0"], + [20, -20, 100, "returns 100 when numbers have opposite signs (positive to negative)"], + [-15, 15, -100, "returns -100 when numbers have opposite signs (negative to positive)"], [100, 90, 10.53, "calculates correct percentage for positive numbers"], + [90, 100, -10.53, "calculates correct negative percentage for positive numbers"], [50, 40, 22.22, "calculates correct percentage for positive numbers"], - [-100, -90, 10.53, "calculates correct percentage for negative numbers"], - [-50, -40, 22.22, "calculates correct percentage for negative numbers"], - [-10, 10, 100, "calculates correct percentage for mixed positive and negative numbers"], - [1, 1000000, 100, "returns 100 for very large differences"], - [-1000000, 1, 100, "returns 100 for very large differences"], - [0.1, 0.2, 66.67, "handles floating point numbers"], - [1.5, 2.5, 50, "handles floating point numbers"], - [NaN, 10, 100, "treats NaN as 0"], + [40, 50, -22.22, "calculates correct negative percentage for positive numbers"], + [-100, -90, -10.53, "calculates correct percentage for negative numbers"], + [-90, -100, 10.53, "calculates correct positive percentage for negative numbers"], + [-50, -40, -22.22, "calculates correct percentage for negative numbers"], + [-40, -50, 22.22, "calculates correct positive percentage for negative numbers"], + [-10, 10, -100, "calculates correct percentage for mixed positive and negative numbers"], + [10, -10, 100, "calculates correct percentage for mixed positive and negative numbers"], + [1, 1000000, -99.9998, "calculates percentage for very large differences"], + [-1000000, 1, -100, "returns -100 for very large negative differences"], + [0.1, 0.2, -66.67, "handles floating point numbers"], + [0.2, 0.1, 66.67, "handles floating point numbers (reverse)"], + [1.5, 2.5, -50, "handles floating point numbers"], + [2.5, 1.5, 50, "handles floating point numbers (reverse)"], + [NaN, 10, -100, "treats NaN as 0"], [10, NaN, 100, "treats NaN as 0"], [NaN, NaN, 0, "treats NaN as 0 (both NaN)"], - [Infinity, 10, 100, "treats Infinity as 0"], + [Infinity, 10, -100, "treats Infinity as 0"], [10, Infinity, 100, "treats Infinity as 0"], [Infinity, Infinity, 0, "treats Infinity as 0 (both Infinity)"], - [-Infinity, 10, 100, "treats -Infinity as 0"], + [-Infinity, 10, -100, "treats -Infinity as 0"], [10, -Infinity, 100, "treats -Infinity as 0"], [-Infinity, -Infinity, 0, "treats -Infinity as 0 (both -Infinity)"], ])("(%f, %f) = %f (%s)", (a, b, expected) => { expect(calculatePercentageDifference(a, b)).toBeCloseTo(expected, 2); }); - test("is symmetric", () => { + test("is not symmetric", () => { const a = 10; const b = 20; - expect(calculatePercentageDifference(a, b)).toBeCloseTo(calculatePercentageDifference(b, a), 5); + expect(calculatePercentageDifference(a, b)).toBeCloseTo( + -calculatePercentageDifference(b, a), + 5, + ); }); }); diff --git a/src/js/helpers/math/calculate-percentage-difference.ts b/src/js/helpers/math/calculate-percentage-difference.ts index b54c08ca..9910e022 100644 --- a/src/js/helpers/math/calculate-percentage-difference.ts +++ b/src/js/helpers/math/calculate-percentage-difference.ts @@ -9,16 +9,17 @@ export function calculatePercentageDifference(_a: number, _b: number): number { // If one number is zero and the other isn't, it's a 100% difference if (a === 0 || b === 0) { - return 100; + return a > b ? 100 : -100; } // If the numbers have opposite signs if ((a > 0 && b < 0) || (a < 0 && b > 0)) { - return 100; + return a > b ? 100 : -100; } - const difference = Math.abs(a - b); + const difference = a - b; const average = (Math.abs(a) + Math.abs(b)) / 2; - return Math.min(100, (difference / average) * 100); + const percent = (difference / average) * 100; + return Math.max(-100, Math.min(100, percent)); } From 4478b2cfbba0062e3ce55b1775d7a2c08921dc52 Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Mon, 16 Sep 2024 22:08:21 +0200 Subject: [PATCH 5/9] feat: Improve dashboard layout on tablets --- src/pages/dashboard/dashboard.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/dashboard/dashboard.vue b/src/pages/dashboard/dashboard.vue index 5477ec1e..752ddde5 100644 --- a/src/pages/dashboard/dashboard.vue +++ b/src/pages/dashboard/dashboard.vue @@ -100,7 +100,7 @@ const selectNextPeriod = () => { grid-template-areas: "balance-trend spending-categories latest-records"; grid-gap: 24px; - @include below(1200) { + @include below(1300) { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-areas: "balance-trend spending-categories" "latest-records latest-records"; } From 8fe73298041f0a83e457b1b65c7abad15b348aba Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Mon, 16 Sep 2024 22:08:30 +0200 Subject: [PATCH 6/9] feat: Add icons to sidebar --- src/components/ui-sidebar.vue | 38 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/components/ui-sidebar.vue b/src/components/ui-sidebar.vue index 01c60b7e..9111a01f 100644 --- a/src/components/ui-sidebar.vue +++ b/src/components/ui-sidebar.vue @@ -9,9 +9,10 @@ + Dashboard @@ -20,9 +21,10 @@ + Accounts @@ -31,9 +33,10 @@ + Records @@ -43,9 +46,10 @@ + Analytics (dev only) @@ -56,9 +60,10 @@ + Crypto (dev only) @@ -67,15 +72,17 @@ + Settings - + + Logout @@ -88,6 +95,15 @@ import { useRouter } from "vue-router"; import { useAuthStore } from "@/stores"; import { isDevEnv } from "@/common/const"; import { ROUTES_NAMES } from "@/routes"; +import { + LayoutDashboardIcon, + CreditCardIcon, + ListIcon, + ChartAreaIcon, + BitcoinIcon, + SettingsIcon, + LogOutIcon, +} from "lucide-vue-next"; import UiButton from "@/components/lib/ui/button/Button.vue"; import { Card, CardContent, CardHeader } from "@/components/lib/ui/card"; @@ -114,6 +130,9 @@ const logOutHandler = () => { .sidebar__content { @apply flex flex-col flex-grow; } +.sidebar__item { + @apply justify-start w-full px-3 gap-2; +} .sidebar__navigation { display: grid; gap: 16px; @@ -142,9 +161,4 @@ const logOutHandler = () => { } } } -.sidebar__logout { - margin-top: auto; - width: 100%; - justify-content: flex-start; -} From feaa6905fe64d1074dde3f16f3cc359f178a1aea Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Mon, 16 Sep 2024 22:18:33 +0200 Subject: [PATCH 7/9] chore: Rename /records to /transactions so it's more clear to users --- src/components/ui-sidebar.vue | 2 +- src/components/widgets/latest-records.vue | 5 ++++- src/routes/constants.ts | 2 +- src/routes/index.ts | 4 ++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/components/ui-sidebar.vue b/src/components/ui-sidebar.vue index 9111a01f..10ce3011 100644 --- a/src/components/ui-sidebar.vue +++ b/src/components/ui-sidebar.vue @@ -29,7 +29,7 @@ - + @@ -76,14 +79,14 @@ size="lg" > - Settings + Settings - Logout + Logout @@ -98,7 +101,7 @@ import { ROUTES_NAMES } from "@/routes"; import { LayoutDashboardIcon, CreditCardIcon, - ListIcon, + LayersIcon, ChartAreaIcon, BitcoinIcon, SettingsIcon, @@ -127,11 +130,12 @@ const logOutHandler = () => { text-align: center; color: var(--abc-text-white-base); } -.sidebar__content { - @apply flex flex-col flex-grow; -} .sidebar__item { @apply justify-start w-full px-3 gap-2; + + span { + @apply hidden md:block; + } } .sidebar__navigation { display: grid; From b41cbd53a3cf4ab950bad7ef4ae5f9ded9d5540a Mon Sep 17 00:00:00 2001 From: Dmytro Svyrydenko Date: Mon, 16 Sep 2024 22:34:33 +0200 Subject: [PATCH 9/9] feat: Improve namings and mobile layout --- src/components/modals/modify-record/index.vue | 2 +- src/components/ui-header.vue | 2 +- src/components/widgets/latest-records.vue | 2 +- src/pages/account/account.vue | 2 +- src/pages/accounts/accounts.vue | 6 +++--- src/pages/dashboard/accounts-list/accounts-list.vue | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/modals/modify-record/index.vue b/src/components/modals/modify-record/index.vue index e82ce4a5..63e06813 100644 --- a/src/components/modals/modify-record/index.vue +++ b/src/components/modals/modify-record/index.vue @@ -378,7 +378,7 @@ useEventListener(document, "keydown", (event) => { />
- {{ isFormCreation ? "Add Record" : "Edit Record" }} + {{ isFormCreation ? "Add Transaction" : "Edit Transaction" }} diff --git a/src/components/ui-header.vue b/src/components/ui-header.vue index 4129f1ff..b605d3f9 100644 --- a/src/components/ui-header.vue +++ b/src/components/ui-header.vue @@ -2,7 +2,7 @@
- New Record + New Transaction
diff --git a/src/components/widgets/latest-records.vue b/src/components/widgets/latest-records.vue index eaca814a..1a7d5699 100644 --- a/src/components/widgets/latest-records.vue +++ b/src/components/widgets/latest-records.vue @@ -1,5 +1,5 @@