Compare commits
No commits in common. "bd47e9d0ab0ab456c959a7174fa6fab980606884" and "b977308e547d7432a0fd0cac813b97826e3ef028" have entirely different histories.
bd47e9d0ab
...
b977308e54
@ -1,11 +1,5 @@
|
|||||||
# @warkypublic/zustandsyncstore
|
# @warkypublic/zustandsyncstore
|
||||||
|
|
||||||
## 0.0.12
|
|
||||||
|
|
||||||
### Patch Changes
|
|
||||||
|
|
||||||
- 57c72e6: Search String and Better GoAPI functionality
|
|
||||||
|
|
||||||
## 0.0.11
|
## 0.0.11
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@warkypublic/oranguru",
|
"name": "@warkypublic/oranguru",
|
||||||
"author": "Warky Devs",
|
"author": "Warky Devs",
|
||||||
"version": "0.0.12",
|
"version": "0.0.11",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@ -23,7 +23,6 @@ export interface GridlerColumn extends Partial<BaseGridColumn> {
|
|||||||
disableFilter?: boolean;
|
disableFilter?: boolean;
|
||||||
disableMove?: boolean;
|
disableMove?: boolean;
|
||||||
disableResize?: boolean;
|
disableResize?: boolean;
|
||||||
disableSearch?: boolean;
|
|
||||||
disableSort?: boolean;
|
disableSort?: boolean;
|
||||||
getMenuItems?: (
|
getMenuItems?: (
|
||||||
id: string,
|
id: string,
|
||||||
|
|||||||
@ -90,7 +90,6 @@ export interface GridlerProps extends PropsWithChildren {
|
|||||||
|
|
||||||
rowHeight?: number;
|
rowHeight?: number;
|
||||||
scrollToRowKey?: number;
|
scrollToRowKey?: number;
|
||||||
searchStr?: string;
|
|
||||||
sections?: {
|
sections?: {
|
||||||
bottom?: React.ReactNode;
|
bottom?: React.ReactNode;
|
||||||
left?: React.ReactNode;
|
left?: React.ReactNode;
|
||||||
@ -107,8 +106,8 @@ export interface GridlerProps extends PropsWithChildren {
|
|||||||
title?: string;
|
title?: string;
|
||||||
tooltipBarProps?: React.HTMLAttributes<HTMLDivElement>;
|
tooltipBarProps?: React.HTMLAttributes<HTMLDivElement>;
|
||||||
total_rows?: number;
|
total_rows?: number;
|
||||||
|
|
||||||
uniqueid: string;
|
uniqueid: string;
|
||||||
|
|
||||||
values?: Array<Record<string, any>>;
|
values?: Array<Record<string, any>>;
|
||||||
width?: number | string;
|
width?: number | string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,11 +4,7 @@ import React, { useCallback, useEffect } from 'react';
|
|||||||
import type { APIOptions } from '../../utils/types';
|
import type { APIOptions } from '../../utils/types';
|
||||||
import type { GridlerColumn } from '../Column';
|
import type { GridlerColumn } from '../Column';
|
||||||
|
|
||||||
import {
|
import { GoAPIHeaders, type GoAPIOperation } from '../../utils/golang-restapi-v2';
|
||||||
type FetchAPIOperation,
|
|
||||||
GoAPIHeaders,
|
|
||||||
type GoAPIOperation,
|
|
||||||
} from '../../utils/golang-restapi-v2';
|
|
||||||
import { useGridlerStore } from '../GridlerStore';
|
import { useGridlerStore } from '../GridlerStore';
|
||||||
|
|
||||||
export interface GlidlerAPIAdaptorForGoLangv2Props<T = unknown> extends APIOptions {
|
export interface GlidlerAPIAdaptorForGoLangv2Props<T = unknown> extends APIOptions {
|
||||||
@ -34,63 +30,38 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
|
|||||||
const colSort = getState('colSort');
|
const colSort = getState('colSort');
|
||||||
const pageSize = getState('pageSize');
|
const pageSize = getState('pageSize');
|
||||||
const colFilters = getState('colFilters');
|
const colFilters = getState('colFilters');
|
||||||
const searchStr = getState('searchStr');
|
|
||||||
const _active_requests = getState('_active_requests');
|
const _active_requests = getState('_active_requests');
|
||||||
setState('loadingData', true);
|
setState('loadingData', true);
|
||||||
try {
|
try {
|
||||||
//console.log('APIAdaptorGoLangv2', { _active_requests, index, pageSize, props });
|
//console.log('APIAdaptorGoLangv2', { _active_requests, index, pageSize, props });
|
||||||
if (props && props.url) {
|
if (props && props.url) {
|
||||||
const head = new Headers();
|
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}`);
|
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) {
|
if (colSort?.length && colSort.length > 0) {
|
||||||
ops.push({
|
head.set(
|
||||||
type: 'sort',
|
'x-sort',
|
||||||
value: colSort
|
colSort
|
||||||
?.map((sort: any) => `${sort.id} ${sort.direction}`)
|
?.map((sort: any) => `${sort.id} ${sort.direction}`)
|
||||||
.reduce((acc: any, val: any) => `${acc},${val}`),
|
.reduce((acc: any, val: any) => `${acc},${val}`)
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
colFilters
|
if (colFilters?.length && colFilters.length > 0) {
|
||||||
?.filter((f) => f.value?.length > 0)
|
colFilters
|
||||||
?.forEach((filter: any) => {
|
?.filter((f) => f.value?.length > 0)
|
||||||
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) => {
|
?.forEach((filter: any) => {
|
||||||
ops.push({
|
if (filter.value && filter.value !== '') {
|
||||||
name: `${filter.id}`,
|
head.set(`x-searchop-${filter.operator}-${filter.id}`, `${filter.value}`);
|
||||||
op: filter.operator,
|
}
|
||||||
type: 'searchor',
|
|
||||||
value: searchStr,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.filter && props.filter !== '') {
|
if (props.filter && props.filter !== '') {
|
||||||
ops.push({
|
head.set('x-custom-sql-w-buildin-filter', props.filter);
|
||||||
name: 'sql_filter',
|
|
||||||
type: 'custom-sql-w',
|
|
||||||
value: props.filter,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.options && props.options.length > 0) {
|
if (props.options && props.options.length > 0) {
|
||||||
const optionHeaders = GoAPIHeaders(props.options);
|
const optionHeaders = GoAPIHeaders(props.options);
|
||||||
for (const oh in optionHeaders) {
|
for (const oh in optionHeaders) {
|
||||||
@ -109,18 +80,8 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
|
|||||||
col_ids?.push(props.hotfields.join(','));
|
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) {
|
if (col_ids && col_ids.length > 0) {
|
||||||
ops.push({
|
head.set(`x-select-fields`, col_ids.join(','));
|
||||||
type: 'select-fields',
|
|
||||||
value: col_ids.join(','),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentRequestIndex = _active_requests?.findIndex((f) => f.page === index) ?? -1;
|
const currentRequestIndex = _active_requests?.findIndex((f) => f.page === index) ?? -1;
|
||||||
@ -129,7 +90,6 @@ function _GlidlerAPIAdaptorForGoLangv2<T = unknown>(props: GlidlerAPIAdaptorForG
|
|||||||
r.controller?.abort?.();
|
r.controller?.abort?.();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
_active_requests &&
|
_active_requests &&
|
||||||
currentRequestIndex >= 0 &&
|
currentRequestIndex >= 0 &&
|
||||||
|
|||||||
@ -16,30 +16,23 @@ export interface GlidlerLocalDataAdaptorProps<T = unknown> {
|
|||||||
cols: GridlerColumns | undefined,
|
cols: GridlerColumns | undefined,
|
||||||
data: Array<T>
|
data: Array<T>
|
||||||
) => Array<T>;
|
) => Array<T>;
|
||||||
onSearch?: (
|
|
||||||
searchField: string | undefined,
|
|
||||||
cols: GridlerColumns | undefined,
|
|
||||||
data: Array<T>
|
|
||||||
) => Array<T>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
|
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
|
||||||
function _GlidlerLocalDataAdaptor<T = unknown>(props: GlidlerLocalDataAdaptorProps<T>) {
|
function _GlidlerLocalDataAdaptor<T = unknown>(props: GlidlerLocalDataAdaptorProps<T>) {
|
||||||
const [setState, getState, mounted] = useGridlerStore((s) => [s.setState, s.getState, s.mounted]);
|
const [setState, getState, mounted] = useGridlerStore((s) => [s.setState, s.getState, s.mounted]);
|
||||||
|
|
||||||
const { colFilters, colSort, columns, searchStr } = useGridlerStore((s) => ({
|
const { colFilters, colSort, columns } = useGridlerStore((s) => ({
|
||||||
colFilters: s.colFilters,
|
colFilters: s.colFilters,
|
||||||
colOrder: s.colOrder,
|
colOrder: s.colOrder,
|
||||||
colSize: s.colSize,
|
colSize: s.colSize,
|
||||||
colSort: s.colSort,
|
colSort: s.colSort,
|
||||||
columns: s.columns,
|
columns: s.columns,
|
||||||
searchStr: s.searchStr,
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const refChanged = React.useRef({
|
const refChanged = React.useRef({
|
||||||
colFilters: colFilters,
|
colFilters: colFilters,
|
||||||
colSort: colSort,
|
colSort: colSort,
|
||||||
searchStr: searchStr,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const useAPIQuery: (index: number) => Promise<any> = async (index: number) => {
|
const useAPIQuery: (index: number) => Promise<any> = async (index: number) => {
|
||||||
@ -77,16 +70,6 @@ function _GlidlerLocalDataAdaptor<T = unknown>(props: GlidlerLocalDataAdaptorPro
|
|||||||
}
|
}
|
||||||
}, [colFilters, props.onColumnFilter]);
|
}, [colFilters, props.onColumnFilter]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (props.onSearch && searchStr !== refChanged?.current?.searchStr) {
|
|
||||||
const filteredData = props.onSearch(searchStr, columns, props.data as Array<T>);
|
|
||||||
setState('total_rows', filteredData.length);
|
|
||||||
setState('data', filteredData);
|
|
||||||
refChanged.current.colFilters = colFilters;
|
|
||||||
getState('refreshCells')?.();
|
|
||||||
}
|
|
||||||
}, [searchStr, props.onSearch]);
|
|
||||||
|
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
export const GlidlerLocalDataAdaptor = React.memo(_GlidlerLocalDataAdaptor);
|
export const GlidlerLocalDataAdaptor = React.memo(_GlidlerLocalDataAdaptor);
|
||||||
|
|||||||
@ -2,7 +2,7 @@ export {GlidlerAPIAdaptorForGoLangv2 } from './components/adaptors/GlidlerAPIAda
|
|||||||
export {GlidlerFormAdaptor } from './components/adaptors/GlidlerFormAdaptor'
|
export {GlidlerFormAdaptor } from './components/adaptors/GlidlerFormAdaptor'
|
||||||
export {GlidlerLocalDataAdaptor } from './components/adaptors/GlidlerLocalDataAdaptor'
|
export {GlidlerLocalDataAdaptor } from './components/adaptors/GlidlerLocalDataAdaptor'
|
||||||
export * from './components/Column'
|
export * from './components/Column'
|
||||||
export {type GridlerProps,type GridlerState, useGridlerStore } from './components/GridlerStore'
|
export {type GridlerProps, useGridlerStore } from './components/GridlerStore'
|
||||||
export { GridlerRightMenuIcon } from './components/RightMenuIcon'
|
export { GridlerRightMenuIcon } from './components/RightMenuIcon'
|
||||||
export {Gridler} from './Gridler'
|
export {Gridler} from './Gridler'
|
||||||
export * from './utils'
|
export * from './utils'
|
||||||
Loading…
Reference in New Issue
Block a user