Remove snapshot filters from Entities and Submissions list#1459
Remove snapshot filters from Entities and Submissions list#1459sadiqkhoja merged 6 commits intogetodk:masterfrom
Conversation
3a23949 to
f485773
Compare
…Submissions list
f485773 to
969065d
Compare
|
Met with @lognaturel and @nicoleorlowski, agreed upon following changes:
Separate issue for:
|
60cf462 to
c7b7474
Compare
* removed page dropdown which was shown when number of pages were less than 10 * update count and range in the pagination control when a row is deleted * refresh the data after bulk delete
c7b7474 to
937a6e4
Compare
matthew-white
left a comment
There was a problem hiding this comment.
Still taking a look, but I thought I'd leave a few questions/comments so far.
src/components/entity/list.vue
Outdated
| this.dataset.entities -= uuids.length; | ||
|
|
||
|
|
||
| this.bulkDeletedEntities = [...this.selectedEntities]; |
There was a problem hiding this comment.
For this.bulkDeletedEntities, I think we could now just store the entity UUIDs. That seems to be the only piece of data that's needed anymore. Just thinking to reduce the amount of entity data in memory.
src/components/entity/list.vue
Outdated
| this.bulkDeletedEntities = [...this.selectedEntities]; | ||
| this.odataEntities.value = this.odataEntities.value.filter(e => !this.selectedEntities.has(e)); | ||
| this.alert.success(this.$tcn('alert.bulkDelete', this.selectedEntities.size)) | ||
| .cta(this.$t('action.undo'), () => this.requestBulkRestore(uuids)); |
There was a problem hiding this comment.
This is maybe outside the scope of this PR, but this.requestBulkRestore() doesn't seem to take an argument.
There was a problem hiding this comment.
I understand a lot of the code removal here, but not 100% why this line was removed. Is it because the watcher on alert.state does this already?
src/components/pagination.vue
Outdated
| {{ text }} | ||
| </option> | ||
| </select> | ||
| <template v-if="empty">0</template> |
There was a problem hiding this comment.
| <template v-if="empty">0</template> | |
| <template v-if="empty">{{ $n(0, 'default') }}</template> |
Wondering whether an Arabic locale would display a different numeral for 0?
There was a problem hiding this comment.
Introduce a new key to handle 0 case. We need to say Row 0 of N, here default pluralization scheme fails; we can't say "Rows 0"
| type: Number, | ||
| required: true | ||
| }, | ||
| removed: { |
There was a problem hiding this comment.
It helped me once I understood that this is the number removed specifically from the current page. How about adding a code comment along those lines?
| .beforeEachResponse((_, { url }) => { | ||
| const filters = new URL(url, window.location.origin).searchParams.get('$filter').split(' and '); | ||
|
|
||
| const start = filters[2].split(' ge ')[1]; | ||
| start.should.equal('1970-01-01T00:00:00.000Z'); | ||
| DateTime.fromISO(start).zoneName.should.equal(Settings.defaultZoneName); | ||
|
|
||
| const end = filters[3].split(' le ')[1]; | ||
| end.should.equal('1970-01-02T23:59:59.999Z'); | ||
| DateTime.fromISO(end).zoneName.should.equal(Settings.defaultZoneName); | ||
| }) |
There was a problem hiding this comment.
I feel like these are still useful assertions and aren't just about the snapshot filter. Maybe the indices on filters here just need to be changed for the test to pass? Similar to the changes for entity/filters.spec.js.
src/components/pagination.vue
Outdated
| type: Array, | ||
| required: true | ||
| }, | ||
| empty: Boolean, |
There was a problem hiding this comment.
Can this be derived from count, removed, page, and size? Something like count.value === 0 || props.page > lastPage.value? If it can't be, I think a code comment explaining the case that it's capturing would be helpful.
There was a problem hiding this comment.
let's compute empty using count, removed, sizeOfCurrentPage
There was a problem hiding this comment.
also add a unit test
| return result; | ||
| }); | ||
|
|
||
| const sizeOfCurrentPage = computed(() => { |
There was a problem hiding this comment.
Should this use props.empty somehow? Something like:
if (props.empty) return 0;There was a problem hiding this comment.
I have removed props.empty. I was thinking to if (props.count === 0) return 0; but we don't show the pagination component if the count is 0
src/components/pagination.vue
Outdated
| {{ text }} | ||
| </option> | ||
| </select> | ||
| <template v-if="empty">0</template> |
There was a problem hiding this comment.
Is there a test of the case where props.empty is true? I did a quick search for "Row 0", but I didn't find any matches. I might have missed the relevant tests though.
There was a problem hiding this comment.
I see that there isn't any pagination.spec.js. Instead, the component is tested implicitly via tests of SubmissionList and EntityList. I was probably the one who decided not to add a pagination.spec.js, but with the introduction of new props, part of me is wondering whether it'd improve testing or make the component's contract clearer to add such a file. I'm not necessarily advocating for that, but I'm wondering what you think of that idea.
There was a problem hiding this comment.
From the PR description:
Since I am no longer maintaining state of deleted records, a generic message
There are no Entities/Submissions to showwill be displayed if all rows are deleted by the user. Previously we used to showAll Entities/Submissions on the page have been deleted.
Mostly this makes sense to me, but I'm wondering about the case where the table is filtered. In that case, it won't say, "There are no Entities to show.", it'll say "There are no matching Entities." That feels a little less accurate/clear to me. I guess you could argue that "matching" includes the page number, but I wanted to ask about it.
Also, I know that removedEntities is now just a number, but a set, but the only way it was used here before was removedEntities.size. Could the number be used in lieu of removedEntities.size? I know they're not exactly the same, since the number now just refers to the current page. For that reason, the first if no longer works, but doesn't the second if still work?
There was a problem hiding this comment.
Agree. Also add a test that message is correct if table is filtered and all rows are deleted.
| if (confirm != null) this.confirmDelete = confirm; | ||
|
|
||
| this.odata.removedSubmissions.add(instanceId); | ||
| this.odata.removedSubmissions += 1; |
There was a problem hiding this comment.
I feel like there's a slight race condition here, though it probably doesn't matter.
- Delete a submission, checking "Delete immediately before confirmation".
- Delete a second submission.
- While the delete request is in progress, navigate to another page.
- If the new page data is received before the success response from the delete, then
removedSubmissionswill be incremented for the current page when it shouldn't be.
There was a problem hiding this comment.
My initial thought is that nothing needs to change, since removedSubmissions isn't used in any critical way. Mostly I just wanted to mention it as food for thought.
src/components/pagination.vue
Outdated
| {{ text }} | ||
| </option> | ||
| </select> | ||
| <template v-if="empty">0</template> |
There was a problem hiding this comment.
Introduce a new key to handle 0 case. We need to say Row 0 of N, here default pluralization scheme fails; we can't say "Rows 0"
src/components/pagination.vue
Outdated
| @@ -35,13 +35,7 @@ except according to the terms contained in the LICENSE file. | |||
| <i18n-t tag="div" keypath="rows" :plural="sizeOfCurrentPage" | |||
There was a problem hiding this comment.
this can be replaced with computed ref. We no longer need i18n-t as select element is removed.
src/components/pagination.vue
Outdated
| type: Array, | ||
| required: true | ||
| }, | ||
| empty: Boolean, |
There was a problem hiding this comment.
let's compute empty using count, removed, sizeOfCurrentPage
src/components/pagination.vue
Outdated
| type: Array, | ||
| required: true | ||
| }, | ||
| empty: Boolean, |
There was a problem hiding this comment.
also add a unit test
There was a problem hiding this comment.
Create corresponding spec for unit testing this component.
There was a problem hiding this comment.
Agree. Also add a test that message is correct if table is filtered and all rows are deleted.
matthew-white
left a comment
There was a problem hiding this comment.
I still need to review pagination.spec.js, but that's mostly it. It's looking great! I'm dropping a few comments now, but I'm planning to finish review tomorrow.
There was a problem hiding this comment.
Similar to EntityList, how about adding this if back?
There was a problem hiding this comment.
Not sure why this is being shown without any diff context. I'm talking about the second if removed from emptyMessage.
test/data/entities.js
Outdated
| extendedEntities.delete = (index) => { | ||
| const entity = entities.get(index); | ||
| if (entity == null) throw new Error('entity not found'); | ||
| entities.update(index, { deletedAt: new Date() }); |
There was a problem hiding this comment.
| entities.update(index, { deletedAt: new Date() }); | |
| entities.update(index, { deletedAt: new Date().toISOString() }); |
Since it's supposed to match the API response, I think it should be a string, not a Date.
src/components/pagination.vue
Outdated
| <i18n-t tag="div" keypath="rows" :plural="sizeOfCurrentPage" | ||
| class="form-group"> | ||
| <div class="form-group">{{ pageRange }}</div> | ||
| <!-- <i18n-t tag="div" keypath="rows" :plural="sizeOfCurrentPage" |
There was a problem hiding this comment.
I see that this is commented out, but it'd be great to remove the <i18n-t> block entirely if possible.
matthew-white
left a comment
There was a problem hiding this comment.
Looks great! 💯 I love the new tests in pagination.spec.js.
src/components/pagination.vue
Outdated
| --> | ||
| <template> | ||
| <div class="pagination"> | ||
| <div v-if="count > 0" class="pagination"> |
There was a problem hiding this comment.
Within the template, is count kind of ambiguous? It's not clear to me whether it will be evaluated as the prop or as the computed ref. It might not be a bad idea to rename or alias the computed ref so that there's no ambiguity.
src/components/pagination.vue
Outdated
There was a problem hiding this comment.
I think these .form-control styles can be removed now that the <select> element has been removed.
src/components/entity/list.vue
Outdated
|
|
||
|
|
||
| this.bulkDeletedEntities = [...this.selectedEntities]; | ||
| this.bulkDeletedEntities = [...this.selectedEntities].map(e => e.__id); |
There was a problem hiding this comment.
| this.bulkDeletedEntities = [...this.selectedEntities].map(e => e.__id); | |
| this.bulkDeletedEntities = uuids; |
I think uuids can be reused so we don't need to .map() again.
src/components/entity/list.vue
Outdated
|
|
||
| this.bulkDeletedEntities = [...this.selectedEntities]; | ||
| this.bulkDeletedEntities = [...this.selectedEntities].map(e => e.__id); | ||
| this.odataEntities.value = this.odataEntities.value.filter(e => !this.selectedEntities.has(e)); |
There was a problem hiding this comment.
Do we need this line anymore? Since we're calling this.refresh(), I'm thinking that this.odataEntities will be cleared. For comparison, onSuccess in requestBulkRestore() no longer modifies this.odataEntities.value.
* Fixes getodk/central#1557: Remove snapshot filters from Entities and Submissions list * Simplified pagination control * removed page dropdown which was shown when number of pages were less than 10 * update count and range in the pagination control when a row is deleted * refresh the data after bulk delete * PR Feedbacks
Closes getodk/central#1557
Changes:
Rows 0 of N, N being the total number of records.deletedSubmissionsanddeletedEntitiesvariable from the corresponding resource. The result of that is that when user deletes a row, then navigates to another page and then returns to the original page, they would see 250 (or whatever page size) records. Previously we used to show 250 - deleted records on the original page.There are no Entities/Submissions to showwill be displayed if all rows are deleted by the user. Previously we used to showAll Entities/Submissions on the page have been deleted.Known issues / questions
What has been done to verify that this works as intended?
All tests are passing.
Why is this the best possible solution? Were any other approaches considered?
It's mostly removal of code.
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?
All functionality around filters, pagination, search, delete and bulk delete should be tested on Submissions and Entity list page.
Does this change require updates to user documentation? If so, please file an issue here and include the link below.
No
Before submitting this PR, please make sure you have:
npm run testandnpm run lintand confirmed all checks still pass OR confirm CircleCI build passes