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

Expose isSavingEntityRecord and isDeletingEntityRecord when using useEntityRecord #56471

Open
rmorse opened this issue Nov 23, 2023 · 2 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Package] Core data /packages/core-data [Type] Enhancement A suggestion for improvement.

Comments

@rmorse
Copy link
Contributor

rmorse commented Nov 23, 2023

What problem does this address?

Currently useEntityRecord exposes almost all of the actions / info you might need relating to the entity record, such as record, save, edit, isResolving, hasResolved etc, but to find out if a save is in progress (to show loaders for example), we have to make a seperate select call with the same paramaters to find out if its saving.

The navigation menu is doing it here:

const { record: navigationMenu, isResolving } = useEntityRecord(
		'postType',
		postType,
		postId
);


const { isSaving, isDeleting } = useSelect(
		( select ) => {
				const { isSavingEntityRecord, isDeletingEntityRecord } =
						select( coreStore );


				return {
						isSaving: isSavingEntityRecord( 'postType', postType, postId ),
						isDeleting: isDeletingEntityRecord(
								'postType',
								postType,
								postId
						),
				};
		},
		[ postId ]
);

What is your proposed solution?

It would be nice if useEntityRecord also exposed isSavingEntityRecord and isDeletingEntityRecord as something like isSaving and isDeleting.

Assuming useEntityRecord is supposed to be an easy way to access actions and data about an entity record, then it seems these are the last two pieces of information missing.

@rmorse rmorse added the [Type] Enhancement A suggestion for improvement. label Nov 23, 2023
@jordesign jordesign added the [Feature] Block API API that allows to express the block paradigm. label Nov 23, 2023
@gziolo
Copy link
Member

gziolo commented Nov 24, 2023

The save method returns a Promise that should play a similar role as the proposed isSaving. What would be the example when using the Promise isn’t sufficient? I’m trying to better understand current limitations.

The example linked in the description isn't the most representative as it doesn't use save from the entity but some other way to trigger persisting changes on the server.

@rmorse
Copy link
Contributor Author

rmorse commented Dec 4, 2023

I think Adams comment summarises quite well - if we are already storing the meta data in the store (isSaving, isDeleting etc) in the store then it would be nice to expose that via the API (a convenience wrapper as Adam put it) - we might actuallly need/want this info in other components other than where the exact save was carried out and it would save us having to find a way to pass this info around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Package] Core data /packages/core-data [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

3 participants