Make dataset resource reactive so that entity count is updated #913
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.
We use
dataset.entities
to show the entity count. On the entity Data page, that allows us to show the entity count in the download button even before the OData response has been received. I don't think we showdataset.entities
outside the Data page, but we could in the future.odataEntities
is a resource local to the Data page, butdataset
is available on all dataset pages.The OData count is more likely to be up-to-date than
dataset.entities
: the dataset is requested before the OData and may have been requested some time ago. If the two counts differ, thendataset.entities
is updated to match the OData count:central-frontend/src/components/entity/list.vue
Lines 99 to 103 in 294323e
We do something similar with
form.submissions
and the OData count on the Submissions page, as well as withformDraft.get().submissions
and the OData count on the Draft Testing page.However, while looking into getodk/central#560, it seems clear that this mechanism isn't fully working. Backend can return an incorrect count for
dataset.entities
(getodk/central-backend#1062), yet even then,dataset.entities
doesn't seem to be updated with the correct OData count.Actually, it turns out that
dataset.entities
is updated, but that update isn't reflected in the DOM, becausedataset
isn't reactive. For performance reasons, resources have to opt into reactivity. I madedataset
reactive, and after that, the count started being updated in the DOM.What has been done to verify that this works as intended?
I tried it locally and wrote a new test.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
Anytime something is made reactive, it could theoretically have performance implications. However, I can't think of anywhere where that would be an issue for
dataset
. I also madedataset
shallow reactive rather than deeply reactive, which should help with performance.Before submitting this PR, please make sure you have:
npm run test
andnpm run lint
and confirmed all checks still pass OR confirm CircleCI build passes