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

intacct c1 import settings fix #962

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,20 @@ export type IntacctDependentImportFields = {

export class ImportSettings {
static constructPayload(importSettingsForm: FormGroup, existingDependentFieldSettings: DependentFieldSetting | null): ImportSettingPost{
const expenseFieldArray = importSettingsForm.value.expenseFields;
const expenseFieldArray = importSettingsForm.get('expenseFields')?.getRawValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle potential undefined expenseFieldArray to prevent runtime errors

If importSettingsForm.get('expenseFields') returns undefined, then expenseFieldArray will be undefined, and calling expenseFieldArray.filter(...) will result in a runtime error. Consider providing a default empty array to prevent potential issues.

Apply this diff to handle potential undefined expenseFieldArray:

-const expenseFieldArray = importSettingsForm.get('expenseFields')?.getRawValue();
+const expenseFieldArray = importSettingsForm.get('expenseFields')?.getRawValue() || [];
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const expenseFieldArray = importSettingsForm.get('expenseFields')?.getRawValue();
const expenseFieldArray = importSettingsForm.get('expenseFields')?.getRawValue() || [];


// First filter out objects where import_to_fyle is false
const filteredExpenseFieldArray = expenseFieldArray.filter((field: MappingSetting) => field.destination_field && field.source_field);

// Then map over the filtered array
const mappingSettings = filteredExpenseFieldArray.filter((field: MappingSetting) => field.source_field !== 'CATEGORY').map((field: MappingSetting) => {
return {
source_field: field.source_field.toUpperCase(),
destination_field: field.destination_field,
import_to_fyle: field.import_to_fyle,
is_custom: (field.source_field.toUpperCase() === 'PROJECT' || field.source_field.toUpperCase() === 'COST_CENTER') ? false : true,
source_placeholder: field.source_placeholder
};
return {
source_field: field.source_field.toUpperCase(),
destination_field: field.destination_field,
import_to_fyle: field.import_to_fyle,
is_custom: (field.source_field.toUpperCase() === 'PROJECT' || field.source_field.toUpperCase() === 'COST_CENTER') ? false : true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify is_custom assignment by removing unnecessary ternary operator

The ternary operator is unnecessary here. You can directly assign the negation of the condition to is_custom for cleaner code.

Apply this diff to simplify the assignment:

-is_custom: (field.source_field.toUpperCase() === 'PROJECT' || field.source_field.toUpperCase() === 'COST_CENTER') ? false : true,
+is_custom: !(
+  field.source_field.toUpperCase() === 'PROJECT' ||
+  field.source_field.toUpperCase() === 'COST_CENTER'
+),

Alternatively, for better readability, consider using includes:

-is_custom: (field.source_field.toUpperCase() === 'PROJECT' || field.source_field.toUpperCase() === 'COST_CENTER') ? false : true,
+is_custom: !['PROJECT', 'COST_CENTER'].includes(field.source_field.toUpperCase()),
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
is_custom: (field.source_field.toUpperCase() === 'PROJECT' || field.source_field.toUpperCase() === 'COST_CENTER') ? false : true,
is_custom: !(
field.source_field.toUpperCase() === 'PROJECT' ||
field.source_field.toUpperCase() === 'COST_CENTER'
),
Tools
Biome

[error] 71-71: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

source_placeholder: field.source_placeholder
};
});

let dependentFieldSetting = null;
Expand Down
Loading