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

fix: removes ability to have duplicate account names on front-end #2776

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Tigatok
Copy link
Contributor

@Tigatok Tigatok commented May 18, 2024

ref: #316

@trafico-bot trafico-bot bot added the 🔍 Ready for Review Pull Request is not reviewed yet label May 18, 2024
@github-actions github-actions bot changed the title fix: removes ability to have duplicate account names on front-end [WIP] fix: removes ability to have duplicate account names on front-end May 18, 2024
Copy link

netlify bot commented May 18, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 6831a0c
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/66493486a014600008f85c66
😎 Deploy Preview https://deploy-preview-2776.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@trafico-bot trafico-bot bot added 🚧 WIP Still work-in-progress, please don't review and don't merge and removed 🔍 Ready for Review Pull Request is not reviewed yet labels May 18, 2024
Copy link
Contributor

github-actions bot commented May 18, 2024

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
9 4.72 MB → 4.72 MB (+1.45 kB) +0.03%
Changeset
File Δ Size
src/components/modals/CreateLocalAccountModal.tsx 📈 +694 B (+11.34%) 5.97 kB → 6.65 kB
src/components/accounts/Header.jsx 📈 +512 B (+3.34%) 14.98 kB → 15.48 kB
src/components/accounts/Account.jsx 📈 +276 B (+0.60%) 44.58 kB → 44.85 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/wide.js 261.78 kB → 262.55 kB (+788 B) +0.29%
static/js/index.js 3 MB → 3 MB (+694 B) +0.02%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/narrow.js 59.97 kB 0%
static/js/usePreviewTransactions.js 790 B 0%
static/js/AppliedFilters.js 20.54 kB 0%
static/js/ReportRouter.js 1.23 MB 0%

Copy link
Contributor

github-actions bot commented May 18, 2024

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.2 MB 0%

Changeset

No files were changed

View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.2 MB 0%

@Tigatok Tigatok changed the title [WIP] fix: removes ability to have duplicate account names on front-end fix: removes ability to have duplicate account names on front-end May 18, 2024
@trafico-bot trafico-bot bot added 🔍 Ready for Review Pull Request is not reviewed yet and removed 🚧 WIP Still work-in-progress, please don't review and don't merge labels May 18, 2024
Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! Overall looks very good and solves 50% of the problem. The other 50% is: we should also catch this issue when an account is renamed.

@@ -49,7 +55,12 @@ export function CreateLocalAccountModal({
event.preventDefault();

const nameError = !name;
setNameError(nameError);
setNameError({ error: nameError, message: 'Name is required' });
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏we can put this in a conditional and return early if the error is encountered. Saves us a tiny amount of compute.

Suggested change
setNameError({ error: nameError, message: 'Name is required' });
if (!name) {
setNameError({ error: true, message: 'Name is required' });
return;
}

const [nameError, setNameError] = useState(false);
const [nameError, setNameError] = useState({
error: false,
message: 'Name is required',
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏initially there should be no error

Suggested change
message: 'Name is required',
message: '',

@@ -75,15 +86,17 @@ export function CreateLocalAccountModal({
const name = event.target.value.trim();
setName(name);
if (name && nameError) {
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏since we now have multiple types of errors: I think we can reset to the "no error" state if there previously was an error instead of using the name var

Suggested change
if (name && nameError) {
if (nameError.error) {

setNameError(nameError);
setNameError({ error: nameError, message: 'Name is required' });

if (accounts.some(account => account.name === name)) {
Copy link
Member

Choose a reason for hiding this comment

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

💭 thought: ‏I wonder if we should make this case insensitive. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd leave that up to the user. I'd say more control is better than less control, but that is just my opinion. LMK if we should change. Can always be done later.

@Tigatok
Copy link
Contributor Author

Tigatok commented May 18, 2024

I changed a couple things, added the editing name error functionality as well to check for duplicated and add an error if found.
I also found/fixed a bug with the error state when using setState by using the local error value on the create account form. LMK if you want me to change anything else.

Screen.Recording.2024-05-18.at.4.07.59.PM.mov

@youngcw youngcw linked an issue May 20, 2024 that may be closed by this pull request
Copy link
Member

@MatissJanis MatissJanis left a comment

Choose a reason for hiding this comment

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

Overall looks really good! Just two small comments. Let me know your thoughts.

Comment on lines +75 to +79
if (nameError.error) {
setNameError(nameError);
} else {
setNameError({ error: false, message: '' });
}
Copy link
Member

Choose a reason for hiding this comment

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

💬 suggestion: ‏could simplify this further

Suggested change
if (nameError.error) {
setNameError(nameError);
} else {
setNameError({ error: false, message: '' });
}
setNameError(nameError);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can take a look at that, I think when I tried that maybe it needed to get un-set, if not, I'm not sure why I didn't do that in the first place haha

return { error: true, message: `Name: “${name}” already exists.` };
}

return { error: false, message: '' };
Copy link
Member

Choose a reason for hiding this comment

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

🥜 nitpick: ‏what if we always returned a string in this util? Then we could re-use it in both this modal and the account page. Slightly less duplication of logic.

@joel-jeremy
Copy link
Contributor

What do you guys think about putting the error message on the right of the input to avoid shifting the position of the transactions table?

@Tigatok
Copy link
Contributor Author

Tigatok commented May 21, 2024

@joel-jeremy I did think of the position to the right, but I'm not too sure how that would work mobile-y. Maybe could look into a popup of some sort?

@MatissJanis
Copy link
Member

Good idea. A tooltip at the bottom with the error would fit nicely there IMO.

(if you use the tooltip component, then please use common/Tooltip)

Here's what we do for split transaction "errors". Not exactly a tooltip, but close-enough.
Screenshot 2024-05-22 at 17 37 36

@youngcw youngcw added this to the v24.6.0 milestone May 22, 2024
@psybers
Copy link
Contributor

psybers commented May 25, 2024

Does this affect setting up bank sync? Here is a scenario (based on real world):

I have 10 accounts that SimpleFIN lists with identical names (ugg...). I want to import two of them from the dialog, so I select 'Create new account' next to both.

Currently, this would create two identically named accounts in Actual. If I want to then disambiguate them, I could rename one/both. Or, as in my case, maybe I don't really care and leave them the same because there will not be transfers to/from them.

@youngcw youngcw removed this from the v24.6.0 milestone May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 Ready for Review Pull Request is not reviewed yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Duplicate Account names should not be possible.
5 participants