Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(goal-display): Implement Sum Goal Display on Master Category #2986

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/extension/features/budget/display-target-goal-amount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,37 @@ export class DisplayTargetGoalAmount extends Feature {

invoke() {
this.addToolkitEmberHook('budget-table-row', 'didRender', this.addTargetGoalAmount);
this.addToolkitEmberHook('budget-table-row', 'didRender', this._addSums);
}

destroy() {
$('.tk-target-goal-amount').remove();
}

_addSums() {
$('.tk-goal-sum-amount').remove();

let masterCategories = $('.budget-table-row.is-master-category');
[...masterCategories].forEach((element) => {
var categorySum = 0;
let category = getEmberView(element.id);

if (category) {
category.subCategories.forEach((subcategory) => {
if (subcategory.goalTargetAmount) {
categorySum += subcategory.goalTargetAmount;
}
});
}

var span = document.createElement('span');
span.classList.add('tk-goal-sum-amount');
span.innerText = `${formatCurrency(categorySum)}`;

$(element).children('.tk-budget-table-cell-goal').append(span);
});
}

addTargetGoalAmount(element) {
if (!ensureGoalColumn(element)) {
return;
Expand Down
22 changes: 22 additions & 0 deletions src/extension/features/budget/filter-categories/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ export class FilterCategories extends Feature {
return;
}

if (/^goal$/g.test(text)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sneaking this in i see 👀 haha

$('.budget-table-container .is-sub-category').each((_, el) => {
let element = getEmberView(el.id);
if (element.goalTargetAmount === 0) {
$(`#${element.elementId}`).addClass('tk-categories-filter-hidden');
}
});

return;
}

if (/^-goal$/g.test(text)) {
$('.budget-table-container .is-sub-category').each((_, el) => {
let element = getEmberView(el.id);
if (element.goalTargetAmount !== 0) {
$(`#${element.elementId}`).addClass('tk-categories-filter-hidden');
}
});

return;
}

$('.budget-table-container .is-master-category').addClass('tk-categories-filter-hidden');

$('.budget-table-container .is-sub-category').each((_, el) => {
Expand Down
1 change: 1 addition & 0 deletions src/types/ynab/data/master-category.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface YNABMasterCategory {
entityId: string;
sortableIndex: number;
subCategories: Array<YNABSubCategory>;
}
1 change: 1 addition & 0 deletions src/types/ynab/data/sub-category.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ interface YNABSubCategory {
entityId?: string;
masterCategoryId?: string;
sortableIndex: number;
goalTargetAmount?: number;
}