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

@@ -36,7 +36,7 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
const searchStr = getState('searchStr');
const searchFields = getState('searchFields');
const _active_requests = getState('_active_requests');
const keyField = getState('keyField');
const keyField = getState('keyField');
setState('loadingData', true);
try {
//console.log('APIAdaptorGoLangv2', { _active_requests, index, pageSize, props });
@@ -83,7 +83,7 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
)
?.forEach((filter: any) => {
ops.push({
name: `${filter.id ?? ""}`,
name: `${filter.id ?? ''}`,
op: 'contains',
type: 'searchor',
value: searchStr,
@@ -202,11 +202,13 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
]
);
const askAPIRowNumber: (key: string) => Promise<number> = useCallback(
const askAPIRowNumber: (key: string) => Promise<null | number> = useCallback(
async (key: string) => {
const colFilters = getState('colFilters');
//console.log('APIAdaptorGoLangv2', { _active_requests, index, pageSize, props });
if (!key) {
return null;
}
//console.log('APIAdaptorGoLangv2', { key, props });
if (props && props.url) {
const head = new Headers();
const ops: FetchAPIOperation[] = [
@@ -250,7 +252,7 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
const controller = new AbortController();
const res = await fetch(`${props.url}?x-fetch-rownumber=${key}}`, {
const res = await fetch(`${props.url}?x-fetch-rownumber=${key}`, {
headers: head,
method: 'GET',
signal: controller?.signal,
@@ -273,12 +275,12 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
setState('useAPIQuery', useAPIQuery);
setState('askAPIRowNumber', askAPIRowNumber);
const isValuesInPages = getState('isValuesInPages');
const _refresh = getState('_refresh');
if (!isValuesInPages) {
setState('values', []);
setState('values', []);
}
//Reset the loaded pages to new rules
_refresh?.().then(() => {
const onChange = getState('onChange');
@@ -293,8 +295,6 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
return <></>;
}
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
export const GlidlerAPIAdaptorForGoLangv2 = React.memo(_GlidlerAPIAdaptorForGoLangv2);