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

add support for bulk deletion of rows #1291

Merged
merged 8 commits into from
Sep 8, 2023
Merged

Conversation

il3ven
Copy link
Contributor

@il3ven il3ven commented Jun 11, 2023

This PR adds support for bulk deletion of rows by implementing a checkbox next to each row. The implementation is based on the example provided by react-table.

Needs more attention

  • Selecting a few rows should put the header checkbox in an indeterminate state. For some reason it is not working. I don't see any problem with my code/logic.
  • Sometimes, after deleting rows the <LoadedRowStatus /> component doesn't update the total number of rows. I request someone with more experience of the codebase to look into it.
  • The state for managing selected rows is set by react-table. They set the ids of selected rows into the state. The id is equal to _rowy_ref.path and the atom delete function accepts a path. In case the id is not equal to _rowy_ref.path the implementation will fail. I think it is not a point of worry because id should always be equal to _rowy_ref.path. Please correct me if I am wrong.

Note: Check the review comments for context about the decisions I have made.

/claim #809
Closes #809

2023-06-12.025948.mp4

@vercel
Copy link

vercel bot commented Jun 11, 2023

@il3ven is attempting to deploy a commit to the Rowy Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jun 11, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rowy-os ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 23, 2023 6:37pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
rowy-typedoc ⬜️ Ignored (Inspect) Visit Preview Aug 23, 2023 6:37pm

src/components/Table/Table.tsx Show resolved Hide resolved
src/components/Table/TableBody.tsx Outdated Show resolved Hide resolved
src/components/Table/TableHeader.tsx Outdated Show resolved Hide resolved
@iamanishroy
Copy link
Member

Hey @il3ven, we also have a field type called Array-subtable. Although the view appears as a table, the internal workings are a bit different. The entire array subtable refers to a single field in a document, which is an array of maps. This is an edge case that is not handled here.

Screen.Recording.2023-06-21.at.12.59.32.PM.mov

@harinij
Copy link
Member

harinij commented Jun 26, 2023

@il3ven tested this and it works well overall. There is just one slight issue, when you freeze any column then causes a UI issue as seen in the video below.

Screen.Recording.2023-06-26.at.2.43.14.pm.mov

@il3ven
Copy link
Contributor Author

il3ven commented Jun 27, 2023

I'll try to fix all these issue by Friday. Sorry for the delay, really busy with other stuff.

@il3ven
Copy link
Contributor Author

il3ven commented Jul 5, 2023

I have pushed three commits addressing the comments.

eef15ac

This commit fixes the freeze issue reported by @harinij.

8d81c36

I found a new bug. The reordering of rows was not working as expected. Fixed it.

dc972d7

This commit addresses the comment by @iamanishroy. The solution for now is to disable row selection for array sub table.

Before explaining the reason for disabling row selection let me explain the cause for the reported bug.

Cause for the array sub table bug

We have the following logic for generating row ID.

const getRowId = (row: TableRow) => row._rowy_ref.path || row._rowy_ref.id;

All rows in case of array sub table have the same _rowy_ref.path and hence the same row ID. Therefore, causing the bug.

Giving unique row ID in case of array sub table

We can have the following logic to make row IDs unique.

const getRowId = (row: TableRow) =>
  row._rowy_ref.path + row._rowy_ref.arrayTableData?.index
    ? `.${row._rowy_ref.arrayTableData?.index}`
    : "";

This fixes the bug shown in the video above. However, there is another bug that is the bulk delete functionality doesn't work. I have explained it below.

Why can't we bulk delete rows in case of array sub table?

Suppose we have three items in our array that is [a, b, c] and user has selected row index 1 and 2 to be deleted. The current delete function accepts only one index. Therefore, we'll have to delete sequentially. In code, it will look like following.

const [ _deleteRowDb ] = useAtom(_deleteRowDbAtom)

// This works as expected. The new array in DB is [a, c].
_deleteRowDb(path, {index: 1})  

// This does not work. As there is no item at index 2.
_deleteRowDb(path, {index: 2})  

The above explanation is simplified for the purpose of this explanation.

Solutions for bulk delete in case of array sub table

The best solution would be to ditch array sub table. The sub table should be a collection. We'll also be able to reuse existing code.

The other solution can be to assign unique IDs to each item in the array. The ID can be autogenerated. Instead of deleting item by index we can center our logic to delete item by ID.

Due to the above problem in deletion of rows. I feel it is best to disable row selection for now and implement a fix in a separate PR.

@harinij
Copy link
Member

harinij commented Jul 18, 2023

Hi @il3ven thanks for the detailed explanation and updates. It appears that this PR has build errors, screenshot below - that would need further attention.
Screenshot 2023-07-18 at 4 36 03 pm

@il3ven
Copy link
Contributor Author

il3ven commented Jul 19, 2023

@harinij fixed the build error.

Row selection has been disabled because bulk delete functionality
cannot work for array sub table according to the current implementation.

Bulk delete problem:

Suppose we have an array with values `[a, b, c]`. Suppose, the indexes
to be removed are [1, 2]. The UI asks firebase function to remove index
1. After 1, the UI asks index 2 to be deleted but index 2 doesn't exist.
After deletion of index 1, the array is `[a, c]`.
`enableRowSelection` was introduced in the last commit.

As of this commit row selection is enabled for TablePage and
SubTablePage.
If there are 1000 rows and we have rendered 100 then select all will
only select 100. In this case, technically all rows in react-table are
selected but we should not show the checked state. It leads to bad UX.
Indermediate would be better.

Also, split the additions of row selection column into a new useMemo. This
ensures that if a row is selected we are only re-calculating the row
selection column and not all.
Due to wrong CSS we were not able to see the icon.
@il3ven
Copy link
Contributor Author

il3ven commented Aug 23, 2023

@shamsmosowi I have fixed two issues. Kindly review and merge.

  • Show indeterminate state on selecting all rows if there are more rows in DB but they haven't been loaded
  • Indeterminate state not working. This was due to a problem in the icon's CSS.
Recording.2023-08-24.010646.mp4

@shamsmosowi shamsmosowi merged commit 6cedeb4 into rowyio:develop Sep 8, 2023
1 of 2 checks passed
@il3ven il3ven deleted the issue-809 branch November 6, 2023 14:30
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.

None yet

4 participants