docs(changeset): Fixed search and allow row selection for only rows with keys

This commit is contained in:
Hein
2025-10-30 10:42:07 +02:00
parent 0943ffc483
commit b4058f1ef3
5 changed files with 42 additions and 17 deletions

View File

@@ -1,5 +1,5 @@
import { CompactSelection } from '@glideapps/glide-data-grid';
import { useDebouncedValue } from '@mantine/hooks';
import { useDebouncedCallback } from '@mantine/hooks';
import React, { useEffect, useRef } from 'react';
import { useGridlerStore } from './GridlerStore';
@@ -7,6 +7,7 @@ import { useGridlerStore } from './GridlerStore';
//The computer component does not need to be recalculated on every render, so we use React.memo to prevent unnecessary re-renders.
export const Computer = React.memo(() => {
const refFirstRun = useRef(0);
const refLastSearch = useRef('');
const refLastFilters = useRef<unknown>(null);
const {
_glideref,
@@ -49,9 +50,22 @@ export const Computer = React.memo(() => {
values: s.values,
}));
const debouncedSearchStr = useDebouncedValue(searchStr, 400, {
leading: true,
});
const debouncedDoSearch = useDebouncedCallback(
(searchStr: string) => {
loadPage(0, 'all').then(() => {
getState('refreshCells')?.();
getState('_events')?.dispatchEvent?.(
new CustomEvent('onSearched', {
detail: { search: searchStr },
})
);
});
},
{
delay: 300,
leading: false,
}
);
useEffect(() => {
const searchSelection = async () => {
@@ -169,19 +183,15 @@ export const Computer = React.memo(() => {
}, [columns]);
useEffect(() => {
if (debouncedSearchStr === undefined || debouncedSearchStr === null) {
if (searchStr === undefined || searchStr === null) {
refLastSearch.current = '';
return;
}
loadPage(0, 'all').then(() => {
getState('refreshCells')?.();
getState('_events')?.dispatchEvent?.(
new CustomEvent('onSearched', {
detail: { search: debouncedSearchStr },
})
);
});
}, [debouncedSearchStr]);
if (refLastSearch.current !== searchStr) {
debouncedDoSearch(searchStr);
refLastSearch.current = searchStr;
}
}, [searchStr]);
useEffect(() => {
if (!colSort) {