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) {
|
if (ready && selectFirstRowOnMount) {
|
||||||
const scrollToRowKey = getState('scrollToRowKey');
|
const scrollToRowKey = getState('scrollToRowKey');
|
||||||
|
|
||||||
if (scrollToRowKey && scrollToRowKey >= 0) {
|
if (scrollToRowKey && scrollToRowKey >= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -294,20 +293,18 @@ export const Computer = React.memo(() => {
|
|||||||
const firstRow = firstBuffer?.[keyField] ?? -1;
|
const firstRow = firstBuffer?.[keyField] ?? -1;
|
||||||
const currentValues = getState('values') ?? [];
|
const currentValues = getState('values') ?? [];
|
||||||
|
|
||||||
if (
|
if (!firstBuffer) {
|
||||||
!(values && values.length > 0) &&
|
return;
|
||||||
firstRow &&
|
}
|
||||||
firstRow > 0 &&
|
|
||||||
(currentValues.length ?? 0) === 0
|
if (firstRow && firstRow > 0 && (currentValues.length ?? 0) === 0) {
|
||||||
) {
|
const newValues = [firstBuffer];
|
||||||
const values = [firstBuffer, ...(currentValues as Array<Record<string, unknown>>)];
|
|
||||||
|
|
||||||
const onChange = getState('onChange');
|
const onChange = getState('onChange');
|
||||||
//console.log('Selecting first row:', firstRow, firstBuffer, values);
|
|
||||||
if (onChange) {
|
if (onChange) {
|
||||||
onChange(values);
|
onChange(newValues);
|
||||||
} else {
|
} else {
|
||||||
setState('values', values);
|
setState('values', newValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
setState('scrollToRowKey', firstRow);
|
setState('scrollToRowKey', firstRow);
|
||||||
@@ -320,7 +317,7 @@ export const Computer = React.memo(() => {
|
|||||||
return () => {
|
return () => {
|
||||||
_events?.removeEventListener('loadPage', loadPage);
|
_events?.removeEventListener('loadPage', loadPage);
|
||||||
};
|
};
|
||||||
}, [ready, selectFirstRowOnMount]);
|
}, [ready, selectFirstRowOnMount, values]);
|
||||||
|
|
||||||
/// logic to apply the selected row.
|
/// logic to apply the selected row.
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
@@ -353,8 +350,6 @@ export const Computer = React.memo(() => {
|
|||||||
//console.log('Computer:Scrolling to key:', key);
|
//console.log('Computer:Scrolling to key:', key);
|
||||||
getRowIndexByKey?.(key).then((r) => {
|
getRowIndexByKey?.(key).then((r) => {
|
||||||
if (r !== undefined) {
|
if (r !== undefined) {
|
||||||
console.log('Scrolling to selected row:', r, selectedRowKey, scrollToRowKey);
|
|
||||||
|
|
||||||
if (selectedRowKey) {
|
if (selectedRowKey) {
|
||||||
const onChange = getState('onChange');
|
const onChange = getState('onChange');
|
||||||
const selected = [{ [getState('keyField') ?? 'id']: selectedRowKey }];
|
const selected = [{ [getState('keyField') ?? 'id']: selectedRowKey }];
|
||||||
@@ -382,15 +377,6 @@ export const Computer = React.memo(() => {
|
|||||||
}
|
}
|
||||||
}, [scrollToRowKey, selectedRowKey]);
|
}, [scrollToRowKey, selectedRowKey]);
|
||||||
|
|
||||||
// console.log('Gridler:Debug:Computer', {
|
|
||||||
// colFilters,
|
|
||||||
// colOrder,
|
|
||||||
// colSize,
|
|
||||||
// colSort,
|
|
||||||
// columns,
|
|
||||||
// uniqueid
|
|
||||||
// });
|
|
||||||
|
|
||||||
return <></>;
|
return <></>;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user