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

Fix bug reoder on table in view groups mode #8894

Merged
merged 4 commits into from
Dec 6, 2024
Merged

Conversation

charlesBochet
Copy link
Member

@charlesBochet charlesBochet commented Dec 5, 2024

Fixes #8403

Added comments on the PR to explain changes

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Error: Error in underlying LLM call. Please try again.

💡 (4/5) You can add custom instructions or style guidelines for the bot here!

5 file(s) reviewed, 7 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -76,24 +76,32 @@ export const RecordTableBodyRecordGroupDragDropContextProvider = ({
return;
}

const computeResult = computeNewRowPosition(result, tableAllRecordIds);
const desinationRecordGroupRecordIds = getSnapshotValue(
Copy link
Contributor

Choose a reason for hiding this comment

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

syntax: 'desinationRecordGroupRecordIds' is misspelled

Comment on lines +53 to 55
if (!isDefined(destinationRecordGroupId)) {
throw new Error('Record group id is not defined');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Throwing an error here might be too aggressive - consider gracefully handling the case where drag operation is cancelled

return;
}

console.log(result.destination.index);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Remove debug console.log statement

: null;

if (destinationIndex === 0) {
const newPosition = recordDestination?.position - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: recordDestination could be null, leading to undefined position and NaN result

Comment on lines 70 to 73
const newPosition =
(recordBeforeDestination?.position +
recordAfterDestination?.position) /
2;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Both records could be null or have undefined positions, causing NaN. Need null checks before calculation


const recordBeforeDestinationId =
recordIds[recordBeforeDestinationIndex];
console.log(recordBeforeDestinationId);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Remove debug console.log statement

: destinationIndex;

const recordAfterDestinationId = recordIds[recordAfterDestinationIndex];
console.log(recordAfterDestinationId);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Remove debug console.log statement

@@ -15,7 +15,8 @@ export const RecordTableNoRecordGroupRows = () => {
<RecordTableRow
key={recordId}
recordId={recordId}
rowIndex={rowIndex}
rowIndexForFocus={rowIndex}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm introducing two rowIndexes:

  • one is used to handle focus, the other to give an index for drag

Right now the index used in focus / cell opening is handled at table level so it's a global index, the index use drag is at group level. I think long term we want to have the index for focus / cell opening at group level too and handle the jump between groups properly

I prefer introducing these two naming ForFocus and ForDrag because it's clear when to use which one in underlying components. Alternatively I could have introduced rowIndexInGroup and rowIndexInTable but this will make underlying components know about recordGroups and make if conditions which I think we should avoid to reduce complexity

@@ -1,90 +0,0 @@
import { DropResult } from '@hello-pangea/dnd';
Copy link
Member Author

Choose a reason for hiding this comment

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

removing this hook as we should leave recordBoard, recordTable, recordTableWithGroups implement their way of selecting the right records + we already have getDraggedRecordPosition helper

position: computeResult.newPosition,
const recordBeforeDestinationId =
allRecordIds[
isSourceIndexBeforeDestinationIndex
Copy link
Member Author

Choose a reason for hiding this comment

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

this is subtle: if the previous record is before or after, we need to shift the records before and after by 1


const recordGroupId = result.destination?.droppableId;
if (!isDefined(result.destination)) {
Copy link
Member Author

Choose a reason for hiding this comment

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

same logic but in case of viewGroups

@charlesBochet charlesBochet merged commit ab8ad46 into main Dec 6, 2024
19 checks passed
@charlesBochet charlesBochet deleted the bug-reorder branch December 6, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Table with record groups can handle record re-order
1 participant