fix(Computer): 🐛 improve row selection logic and cleanup
* Refactor row selection to handle first row more efficiently. * Remove unnecessary checks and console logs for cleaner code. * Update dependencies for better performance.
This commit is contained in:
@@ -282,7 +282,6 @@ export const Computer = React.memo(() => {
|
||||
|
||||
if (ready && selectFirstRowOnMount) {
|
||||
const scrollToRowKey = getState('scrollToRowKey');
|
||||
|
||||
if (scrollToRowKey && scrollToRowKey >= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -294,20 +293,18 @@ export const Computer = React.memo(() => {
|
||||
const firstRow = firstBuffer?.[keyField] ?? -1;
|
||||
const currentValues = getState('values') ?? [];
|
||||
|
||||
if (
|
||||
!(values && values.length > 0) &&
|
||||
firstRow &&
|
||||
firstRow > 0 &&
|
||||
(currentValues.length ?? 0) === 0
|
||||
) {
|
||||
const values = [firstBuffer, ...(currentValues as Array<Record<string, unknown>>)];
|
||||
if (!firstBuffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstRow && firstRow > 0 && (currentValues.length ?? 0) === 0) {
|
||||
const newValues = [firstBuffer];
|
||||
|
||||
const onChange = getState('onChange');
|
||||
//console.log('Selecting first row:', firstRow, firstBuffer, values);
|
||||
if (onChange) {
|
||||
onChange(values);
|
||||
onChange(newValues);
|
||||
} else {
|
||||
setState('values', values);
|
||||
setState('values', newValues);
|
||||
}
|
||||
|
||||
setState('scrollToRowKey', firstRow);
|
||||
@@ -320,7 +317,7 @@ export const Computer = React.memo(() => {
|
||||
return () => {
|
||||
_events?.removeEventListener('loadPage', loadPage);
|
||||
};
|
||||
}, [ready, selectFirstRowOnMount]);
|
||||
}, [ready, selectFirstRowOnMount, values]);
|
||||
|
||||
/// logic to apply the selected row.
|
||||
// useEffect(() => {
|
||||
@@ -353,8 +350,6 @@ export const Computer = React.memo(() => {
|
||||
//console.log('Computer:Scrolling to key:', key);
|
||||
getRowIndexByKey?.(key).then((r) => {
|
||||
if (r !== undefined) {
|
||||
console.log('Scrolling to selected row:', r, selectedRowKey, scrollToRowKey);
|
||||
|
||||
if (selectedRowKey) {
|
||||
const onChange = getState('onChange');
|
||||
const selected = [{ [getState('keyField') ?? 'id']: selectedRowKey }];
|
||||
@@ -382,15 +377,6 @@ export const Computer = React.memo(() => {
|
||||
}
|
||||
}, [scrollToRowKey, selectedRowKey]);
|
||||
|
||||
// console.log('Gridler:Debug:Computer', {
|
||||
// colFilters,
|
||||
// colOrder,
|
||||
// colSize,
|
||||
// colSort,
|
||||
// columns,
|
||||
// uniqueid
|
||||
// });
|
||||
|
||||
return <></>;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user