forked from maybe-finance/maybe
-
Notifications
You must be signed in to change notification settings - Fork 112
Enhanced Import Amount Type Selection #179
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
Open
hendriksen-mark
wants to merge
4
commits into
we-promise:main
Choose a base branch
from
hendriksen-mark:import
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dbe68ab
Add amount_type_identifier_value to import configuration
hendriksen-mark 241f75b
Improve import amount type handling and UI logic
hendriksen-mark b2d7ee4
Add validation for custom column import identifier
hendriksen-mark e427053
Update import.rb
hendriksen-mark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ export default class extends Controller { | |
| "signedAmountFieldset", | ||
| "customColumnFieldset", | ||
| "amountTypeValue", | ||
| "amountTypeInflowValue", | ||
| "amountTypeStrategySelect", | ||
| ]; | ||
|
|
||
|
|
@@ -20,6 +21,10 @@ export default class extends Controller { | |
| this.amountTypeColumnKeyValue | ||
| ) { | ||
| this.#showAmountTypeValueTargets(this.amountTypeColumnKeyValue); | ||
| const identifierValueSelect = this.amountTypeValueTarget.querySelector("select"); | ||
| if (identifierValueSelect && identifierValueSelect.value) { | ||
| this.#showAmountTypeInflowValueTargets(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -31,6 +36,10 @@ export default class extends Controller { | |
|
|
||
| if (this.amountTypeColumnKeyValue) { | ||
| this.#showAmountTypeValueTargets(this.amountTypeColumnKeyValue); | ||
| const identifierValueSelect = this.amountTypeValueTarget.querySelector("select"); | ||
| if (identifierValueSelect && identifierValueSelect.value) { | ||
| this.#showAmountTypeInflowValueTargets(); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
|
|
@@ -45,6 +54,10 @@ export default class extends Controller { | |
| this.#showAmountTypeValueTargets(amountTypeColumnKey); | ||
| } | ||
|
|
||
| handleAmountTypeIdentifierChange(event) { | ||
| this.#showAmountTypeInflowValueTargets(); | ||
| } | ||
|
|
||
| #showAmountTypeValueTargets(amountTypeColumnKey) { | ||
| const selectableValues = this.#uniqueValuesForColumn(amountTypeColumnKey); | ||
|
|
||
|
|
@@ -72,6 +85,29 @@ export default class extends Controller { | |
| select.appendChild(fragment); | ||
| } | ||
|
|
||
| #showAmountTypeInflowValueTargets(amountTypeColumnKey) { | ||
| // This should be called when amount_type_identifier_value changes | ||
| // We need to update the displayed identifier value in the UI text | ||
| const identifierValueSelect = this.amountTypeValueTarget.querySelector("select"); | ||
| const selectedValue = identifierValueSelect.value; | ||
|
|
||
| if (!selectedValue) { | ||
| this.amountTypeInflowValueTarget.classList.add("hidden"); | ||
| this.amountTypeInflowValueTarget.classList.remove("flex"); | ||
| return; | ||
| } | ||
|
|
||
| // Show the inflow value dropdown | ||
| this.amountTypeInflowValueTarget.classList.remove("hidden"); | ||
| this.amountTypeInflowValueTarget.classList.add("flex"); | ||
|
|
||
| // Update the displayed identifier value in the text | ||
| const identifierSpan = this.amountTypeInflowValueTarget.querySelector("span.font-medium"); | ||
| if (identifierSpan) { | ||
| identifierSpan.textContent = selectedValue; | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
||
| #uniqueValuesForColumn(column) { | ||
| const colIdx = this.csvValue[0].indexOf(column); | ||
| const values = this.csvValue.slice(1).map((row) => row[colIdx]); | ||
|
|
@@ -101,6 +137,12 @@ export default class extends Controller { | |
| this.customColumnFieldsetTarget.classList.add("hidden"); | ||
| this.signedAmountFieldsetTarget.classList.remove("hidden"); | ||
|
|
||
| // Hide the inflow value targets when using signed amount strategy | ||
| this.amountTypeValueTarget.classList.add("hidden"); | ||
| this.amountTypeValueTarget.classList.remove("flex"); | ||
| this.amountTypeInflowValueTarget.classList.add("hidden"); | ||
| this.amountTypeInflowValueTarget.classList.remove("flex"); | ||
|
|
||
| // Remove required from custom column fields | ||
| this.customColumnFieldsetTarget | ||
| .querySelectorAll("select, input") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20251002120000_add_amount_type_identifier_value_to_imports.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddAmountTypeIdentifierValueToImports < ActiveRecord::Migration[7.2] | ||
| def change | ||
| add_column :imports, :amount_type_identifier_value, :string | ||
| end | ||
| end | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.