Skip to content

issue-2158/Refactored redux store utility functions #2482

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

Merged
merged 8 commits into from
Mar 15, 2025

Conversation

KraftKatten
Copy link
Collaborator

@KraftKatten KraftKatten commented Jan 19, 2025

Description

This PR is a start of refactoring Redux store utility functions. It creates utility methods such as create, load, loaded, update, updated and deleted for the remoteData data type. So far, the refactoring applies only to the following features:

  • AreaAssignment
  • Areas
  • JoinForms
  • Tags

Next step is to get this code reviewed and approved, and then I'll continue refactoring for other features as well.

Screenshots

Only code changes.

Changes

  • Adds utility methods for common Redux store operations
  • Refactors AreaAssignment, Areas, JoinForms and Tags
  • Adds tests

Notes to reviewer

Related issues

The issue won't be completely resolved by this PR.

Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

Awesome work! I have reviewed the code, and I have tried the preview build to verify that all CRUDL of relevant features work as expected. I think it does!

I only have one question below.

Comment on lines 16 to 35
export function remoteItemCreatedWithData<DataType extends RemoteData>(
list: RemoteList<DataType>,
data: DataType
): RemoteItem<DataType> {
return updateOrCreateItemWithData(list, data);
}

export function remoteItemUpdated<DataType extends RemoteData>(
list: RemoteList<DataType>,
updatedData: DataType
): RemoteItem<DataType> {
return updateOrCreateItemWithData(list, updatedData);
}

export function remoteItemLoaded<DataType extends RemoteData>(
list: RemoteList<DataType>,
updatedData: DataType
): RemoteItem<DataType> {
return updateOrCreateItemWithData(list, updatedData);
}
Copy link
Member

Choose a reason for hiding this comment

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

I'm sure we've discussed this and I just can't remember, but what is the reason for having these functions that are essentially aliases for updateOrCreateItemWithData()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's to be consistent with the naming. For example, for tags. When we are in the tagCreated, tagUpdated, tagLoaded methods, the developer can use remoteItemCreated, remoteItemUpdated, remoteItemLoaded.

If I had to pick one, I think I'd go with remoteItemUpdated. Would you prefer just having that one? @richardolsson

Copy link
Member

Choose a reason for hiding this comment

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

I understand! How about using updateOrCreateItemWithData() directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed to remoteItemUpdated

Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

The time has come to push the button.

@richardolsson richardolsson merged commit 1f33a7c into main Mar 15, 2025
5 checks passed
@richardolsson richardolsson deleted the issue-2158/store-utility-method branch March 15, 2025 14:53
@richardolsson
Copy link
Member

Related to #2158

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

Successfully merging this pull request may close these issues.

2 participants