docs(changeset): Search String and Better GoAPI functionality

This commit is contained in:
Hein
2025-10-29 16:26:38 +02:00
parent b977308e54
commit 57c72e656f
6 changed files with 83 additions and 19 deletions

View File

@@ -4,7 +4,11 @@ import React, { useCallback, useEffect } from 'react';
import type { APIOptions } from '../../utils/types';
import type { GridlerColumn } from '../Column';
import { GoAPIHeaders, type GoAPIOperation } from '../../utils/golang-restapi-v2';
import {
type FetchAPIOperation,
GoAPIHeaders,
type GoAPIOperation,
} from '../../utils/golang-restapi-v2';
import { useGridlerStore } from '../GridlerStore';
export interface GlidlerAPIAdaptorForGoLangv2Props<T = unknown> extends APIOptions {
@@ -30,38 +34,63 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
const colSort = getState('colSort');
const pageSize = getState('pageSize');
const colFilters = getState('colFilters');
const searchStr = getState('searchStr');
const _active_requests = getState('_active_requests');
setState('loadingData', true);
try {
//console.log('APIAdaptorGoLangv2', { _active_requests, index, pageSize, props });
if (props && props.url) {
const head = new Headers();
head.set('x-limit', String(pageSize ?? 50));
head.set('x-offset', String((pageSize ?? 50) * index));
head.set('Authorization', `Token ${props.authtoken}`);
const ops: FetchAPIOperation[] = [
{ type: 'limit', value: String(pageSize ?? 50) },
{ type: 'offset', value: String((pageSize ?? 50) * index) },
];
if (colSort?.length && colSort.length > 0) {
head.set(
'x-sort',
colSort
ops.push({
type: 'sort',
value: colSort
?.map((sort: any) => `${sort.id} ${sort.direction}`)
.reduce((acc: any, val: any) => `${acc},${val}`)
);
.reduce((acc: any, val: any) => `${acc},${val}`),
});
}
if (colFilters?.length && colFilters.length > 0) {
colFilters
?.filter((f) => f.value?.length > 0)
colFilters
?.filter((f) => f.value?.length > 0)
?.forEach((filter: any) => {
if (filter.value && filter.value !== '') {
ops.push({
name: `${filter.id}`,
op: filter.operator,
type: 'searchop',
value: filter.value,
});
}
});
if (searchStr && searchStr !== '') {
columns
?.filter((f) => !f.disableFilter && !f.disableSearch)
?.forEach((filter: any) => {
if (filter.value && filter.value !== '') {
head.set(`x-searchop-${filter.operator}-${filter.id}`, `${filter.value}`);
}
ops.push({
name: `${filter.id}`,
op: filter.operator,
type: 'searchor',
value: searchStr,
});
});
}
if (props.filter && props.filter !== '') {
head.set('x-custom-sql-w-buildin-filter', props.filter);
ops.push({
name: 'sql_filter',
type: 'custom-sql-w',
value: props.filter,
});
}
if (props.options && props.options.length > 0) {
const optionHeaders = GoAPIHeaders(props.options);
for (const oh in optionHeaders) {
@@ -80,8 +109,18 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
col_ids?.push(props.hotfields.join(','));
}
if (ops && ops.length > 0) {
const optionHeaders = GoAPIHeaders(ops);
for (const oh in GoAPIHeaders(ops)) {
head.set(oh, optionHeaders[oh]);
}
}
if (col_ids && col_ids.length > 0) {
head.set(`x-select-fields`, col_ids.join(','));
ops.push({
type: 'select-fields',
value: col_ids.join(','),
});
}
const currentRequestIndex = _active_requests?.findIndex((f) => f.page === index) ?? -1;
@@ -90,6 +129,7 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
r.controller?.abort?.();
}
});
if (
_active_requests &&
currentRequestIndex >= 0 &&