Logs: update activeField comments
This commit is contained in:
@@ -38,41 +38,33 @@ export const ActiveFields = ({ activeFields, clear, fields, reorder, suggestedFi
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the field names from the active array (what's actually rendered)
|
||||
// The indices in result are based on the active array, not activeFields
|
||||
// Get the field names from the active array and use that instead of the index
|
||||
// This is needed because in the table and logs view some fields are not rendered, so the index is not the same as the index in the activeFields array
|
||||
const sourceFieldName = active[result.source.index]?.name;
|
||||
if (!sourceFieldName) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new array with the reordered fields
|
||||
const newActiveFields = [...activeFields];
|
||||
|
||||
// Find the actual index of the source field in activeFields
|
||||
const sourceIndexInActiveFields = newActiveFields.indexOf(sourceFieldName);
|
||||
if (sourceIndexInActiveFields === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the source field from its current position
|
||||
const [movedField] = newActiveFields.splice(sourceIndexInActiveFields, 1);
|
||||
|
||||
// Find where to insert it based on the destination in the active array
|
||||
const destFieldName = active[result.destination.index]?.name;
|
||||
if (destFieldName) {
|
||||
// Find the destination field in activeFields
|
||||
const destIndexInActiveFields = newActiveFields.indexOf(destFieldName);
|
||||
if (destIndexInActiveFields !== -1) {
|
||||
// If dragging down, insert after; if dragging up, insert before
|
||||
const insertIndex =
|
||||
result.source.index < result.destination.index ? destIndexInActiveFields + 1 : destIndexInActiveFields;
|
||||
newActiveFields.splice(insertIndex, 0, movedField);
|
||||
} else {
|
||||
// Destination field not found in activeFields (shouldn't happen), append
|
||||
newActiveFields.push(movedField);
|
||||
}
|
||||
} else {
|
||||
// No destination field, append
|
||||
newActiveFields.push(movedField);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user