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: new flow of add-edit expense page #3453

Open
wants to merge 2 commits into
base: feat_split_expense
Choose a base branch
from

Conversation

Sishhhh
Copy link
Contributor

@Sishhhh Sishhhh commented Jan 29, 2025

Clickup

https://app.clickup.com/t/86cxubdrz

New flow of add-edit expense page

UI :
Screenshot 2025-01-29 at 11 15 16 AM
Changes: 
- Removed all the 3 dimensions
- Added one single option for split
- Removed the splitType and its use cases
- sending the required input data to show inside the split expense page

Summary by CodeRabbit

  • Refactor
    • Simplified expense splitting functionality by consolidating split handling methods.
    • Updated openSplitExpenseModal method to utilize a streamlined configuration approach.
    • Removed separate split handler methods in favor of a unified splitExpenseHandler.

Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

The expense splitting functionality in the AddEditExpensePage has undergone a significant refactor! The method openSplitExpenseModal has simplified its signature by dropping the splitType parameter. Instead, a new splitConfig object is created within the method, centralizing the configuration for splitting expenses. The previously separate methods for handling categories, projects, and cost centers have been merged into a single splitExpenseHandler, streamlining the logic and enhancing clarity in navigation for expense splitting.

Changes

File Changes
src/app/fyle/add-edit-expense/add-edit-expense.page.ts - Removed splitType parameter from openSplitExpenseModal
- Added splitConfig object construction
- Consolidated split handling methods into splitExpenseHandler
- Simplified navigation logic for expense splitting
src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts - Updated openSplitExpenseModal method signature
- Adjusted test cases to reflect new splitConfig object
- Renamed split handling methods to splitExpenseHandler

Suggested labels

size/M

Suggested reviewers

  • Chethan-Fyle
  • arjunaj5

Possibly related PRs

Poem

Expenses split with style so bright,
Rajinikanth's code takes flight!
Methods dance, parameters sway,
Complexity vanishes today!
Coding magic, superstar's might! 🌟💥

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the size/M Medium PR label Jan 29, 2025
@Sishhhh Sishhhh marked this pull request as draft January 29, 2025 07:06
@github-actions github-actions bot added size/L Large PR and removed size/M Medium PR labels Jan 29, 2025
@Sishhhh Sishhhh marked this pull request as ready for review January 29, 2025 08:06
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f790c8c and eb80252.

📒 Files selected for processing (1)
  • src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts (10 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (12.x)
🔇 Additional comments (1)
src/app/fyle/add-edit-expense/add-edit-expense-1.spec.ts (1)

Line range hint 1182-1214: Superstar level consolidation of split handlers!

The refactoring of multiple split handlers into a single splitExpenseHandler simplifies the code. The test coverage looks comprehensive, checking:

  • Valid form submission
  • Form validation errors
  • Pending transaction restrictions

Comment on lines +683 to +699
const splitConfig = {
category: {
is_visible: !!expenseFieldObjData.org_category_id,
value: component.getFormValues().category,
is_mandatory: expenseFieldObjData.org_category_id?.is_mandatory || false,
},
project: {
is_visible: !!expenseFieldObjData.project_id,
value: component.getFormValues().project,
is_mandatory: expenseFieldObjData.project_id?.is_mandatory || false,
},
costCenter: {
is_visible: !!expenseFieldObjData.cost_center_id,
value: component.getFormValues().costCenter,
is_mandatory: expenseFieldObjData.cost_center_id?.is_mandatory || false,
},
};
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Mind-blowing refactor, but let's make the splitConfig more robust!

The splitConfig object structure looks good, but we can make it even better by extracting it into a reusable interface.

interface SplitFieldConfig {
  is_visible: boolean;
  value: any;
  is_mandatory: boolean;
}

interface SplitConfig {
  category: SplitFieldConfig;
  project: SplitFieldConfig;
  costCenter: SplitFieldConfig;
}

Comment on lines +1217 to 1252
it('should get all action sheet options', (done) => {
orgSettingsService.get.and.returnValue(
of({
...orgSettingsData,
expense_settings: { ...orgSettingsData.expense_settings, split_expense_settings: { enabled: true } },
})
);
component.activeCategories$ = of(sortedCategory);
component.costCenters$ = of(expectedCCdata);
projectsService.getAllActive.and.returnValue(of(projectsV1Data));
component.filteredCategories$ = of(categorieListRes);
component.txnFields$ = of(expenseFieldObjData);
component.isCccExpense = 'tx3qHxFNgRcZ';
component.canDismissCCCE = true;
component.isCorporateCreditCardEnabled = true;
component.canRemoveCardExpense = true;
component.isExpenseMatchedForDebitCCCE = true;
spyOn(component, 'splitExpCategoryHandler');
spyOn(component, 'splitExpProjectHandler');
spyOn(component, 'splitExpCostCenterHandler');
spyOn(component, 'splitExpenseHandler');
spyOn(component, 'markPersonalHandler');
spyOn(component, 'markDismissHandler');
spyOn(component, 'removeCCCHandler');
launchDarklyService.getVariation.and.returnValue(of(true));
fixture.detectChanges();

let actionSheetOptions;

component.getActionSheetOptions().subscribe((res) => {
actionSheetOptions = res;
expect(res.length).toEqual(5);
expect(res.length).toEqual(4);
expect(orgSettingsService.get).toHaveBeenCalledTimes(1);
expect(projectsService.getAllActive).toHaveBeenCalledTimes(1);
expect(launchDarklyService.getVariation).toHaveBeenCalledOnceWith(
'show_project_mapped_categories_in_split_expense',
false
);
});

actionSheetOptions[0].handler();
expect(component.splitExpCategoryHandler).toHaveBeenCalledTimes(1);
expect(component.splitExpenseHandler).toHaveBeenCalledTimes(1);
actionSheetOptions[1].handler();
expect(component.splitExpProjectHandler).toHaveBeenCalledTimes(1);
actionSheetOptions[2].handler();
expect(component.markPersonalHandler).toHaveBeenCalledTimes(1);
actionSheetOptions[3].handler();
actionSheetOptions[2].handler();
expect(component.markDismissHandler).toHaveBeenCalledTimes(1);
actionSheetOptions[4].handler();
actionSheetOptions[3].handler();
expect(component.removeCCCHandler).toHaveBeenCalledTimes(1);
expect(component.splitExpCostCenterHandler).not.toHaveBeenCalled();
done();
});
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Action sheet options test needs more power!

While the test covers the basic scenarios, we should add test cases for:

  1. Error handling when orgSettings call fails
  2. Edge cases when some action handlers throw errors

Add these test cases:

it('should handle orgSettings error gracefully', (done) => {
  orgSettingsService.get.and.returnValue(throwError(() => new Error('Network error')));
  
  component.getActionSheetOptions().subscribe({
    error: (err) => {
      expect(err.message).toBe('Network error');
      done();
    }
  });
});

it('should handle action handler errors', (done) => {
  orgSettingsService.get.and.returnValue(of({
    ...orgSettingsData,
    expense_settings: { split_expense_settings: { enabled: true } }
  }));
  
  spyOn(component, 'splitExpenseHandler').and.throwError('Handler error');
  
  component.getActionSheetOptions().subscribe((res) => {
    expect(() => res[0].handler()).toThrow('Handler error');
    done();
  });
});

Copy link

Unit Test Coverage % values
Statements 96.12% ( 19699 / 20493 )
Branches 91.21% ( 10831 / 11874 )
Functions 94.41% ( 5864 / 6211 )
Lines 96.18% ( 18816 / 19563 )

Copy link
Contributor

@arjunaj5 arjunaj5 left a comment

Choose a reason for hiding this comment

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

approved with a question

projects: projects$,
txnFields: this.txnFields$.pipe(take(1)),
filteredCategories: this.filteredCategories$.pipe(take(1)),
showProjectMappedCategoriesInSplitExpense: this.launchDarklyService.getVariation(
Copy link
Contributor

Choose a reason for hiding this comment

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

will this LD flag be checked in the split expense screen?

@@ -709,16 +726,33 @@ export function TestCases1(getTestBed) {
component.fg.controls.report.setValue(expectedReportsPaginated[0]);
spyOn(component, 'generateEtxnFromFg').and.returnValue(of(unflattenedExpData));
fixture.detectChanges();
const splitConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

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

can't u define this at common place?

Copy link
Contributor

@hlkavya0213 hlkavya0213 left a comment

Choose a reason for hiding this comment

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

minor comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Large PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants