fix(Gridler): 🐛 improve state management and cleanup

* Update `askAPIRowNumber` to return `null` or `number` for better type safety.
* Refactor conditionals to ensure proper handling of row indices.
* Clean up console logs for improved readability and performance.
* Ensure consistent formatting across the codebase.
This commit is contained in:
Hein
2026-02-09 14:41:49 +02:00
parent 31e46e6bd2
commit 6cb50978d0
5 changed files with 41 additions and 38 deletions

View File

@@ -28,7 +28,7 @@ export const Computer = React.memo(() => {
selectFirstRowOnMount,
setState,
setStateFN,
values
values,
} = useGridlerStore((s) => ({
_glideref: s._glideref,
_gridSelectionRows: s._gridSelectionRows,
@@ -45,7 +45,7 @@ export const Computer = React.memo(() => {
scrollToRowKey: s.scrollToRowKey,
searchStr: s.searchStr,
selectedRowKey: s.selectedRowKey,
selectFirstRowOnMount:s.selectFirstRowOnMount,
selectFirstRowOnMount: s.selectFirstRowOnMount,
setState: s.setState,
setStateFN: s.setStateFN,
uniqueid: s.uniqueid,
@@ -100,9 +100,12 @@ export const Computer = React.memo(() => {
break;
}
}
if (!(rowIndex >= 0)) {
if (rowIndex >= 0) {
rowIndexes.push(rowIndex);
} else {
const idx = await getRowIndexByKey(key);
if (idx) {
if (idx !== null) {
rowIndexes.push(idx);
}
}
@@ -115,7 +118,9 @@ export const Computer = React.memo(() => {
searchSelection().then((rowIndexes) => {
let rows = CompactSelection.empty();
rowIndexes.forEach((r) => {
rows = rows.add(r);
if (r !== undefined) {
rows = rows.add(r);
}
});
setStateFN('_gridSelectionRows', () => {
@@ -276,14 +281,12 @@ export const Computer = React.memo(() => {
const ready = getState('ready');
if (ready && selectFirstRowOnMount) {
const scrollToRowKey = getState('scrollToRowKey');
if (scrollToRowKey && scrollToRowKey >= 0) {
return;
}
const keyField = getState('keyField') ?? 'id';
const page_data = getState('_page_data');
@@ -299,7 +302,6 @@ export const Computer = React.memo(() => {
) {
const values = [firstBuffer, ...(currentValues as Array<Record<string, unknown>>)];
const onChange = getState('onChange');
//console.log('Selecting first row:', firstRow, firstBuffer, values);
if (onChange) {
@@ -348,9 +350,10 @@ export const Computer = React.memo(() => {
const key = selectedRowKey ?? scrollToRowKey;
if (key && ref && ready) {
//console.log('Computer:Scrolling to key:', key);
getRowIndexByKey?.(key).then((r) => {
if (r !== undefined) {
//console.log('Scrolling to selected row:', r, selectedRowKey, scrollToRowKey);
console.log('Scrolling to selected row:', r, selectedRowKey, scrollToRowKey);
if (selectedRowKey) {
const onChange = getState('onChange');