Skip to content

Commit e075c8f

Browse files
authored
Merge branch 'main' into postgrest-scroll
2 parents a123849 + d107a5b commit e075c8f

File tree

6 files changed

+102
-6
lines changed

6 files changed

+102
-6
lines changed

packages/data-sheet/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format
44
is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
55
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [unreleased] - 2025-07-10
8+
9+
- PostgREST sheet has full table search ability
10+
711
## [2.1.1] - 2025-06-25
812

913
- Fix issue with exports and Parcel

packages/data-sheet/src/postgrest-table/data-loaders.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useAsyncEffect } from "@macrostrat/ui-components";
44
import { debounce } from "underscore";
5-
import { useCallback, useMemo, useReducer, useRef } from "react";
5+
import { useCallback, useMemo, useReducer, useRef, useEffect } from "react";
66
import update, { Spec } from "immutability-helper";
77

88
interface ChunkIndex {
@@ -36,7 +36,8 @@ type LazyLoaderAction<T> =
3636
| { type: "loaded"; data: T[]; offset: number; totalSize: number }
3737
| { type: "error"; error: Error }
3838
| { type: "set-visible"; region: RowRegion }
39-
| { type: "update-data"; changes: Spec<T[]> };
39+
| { type: "update-data"; changes: Spec<T[]> }
40+
| { type: "reset" };
4041

4142
function adjustArraySize<T>(arr: T[], newSize: number) {
4243
if (newSize == null || arr.length === newSize) {
@@ -84,6 +85,15 @@ function lazyLoadingReducer<T>(
8485
data,
8586
loading: false,
8687
};
88+
89+
case "reset":
90+
return {
91+
data: [],
92+
loading: false,
93+
error: null,
94+
visibleRegion: { rowIndexStart: 0, rowIndexEnd: 0 },
95+
initialized: false,
96+
};
8797
case "error":
8898
return {
8999
...state,
@@ -138,6 +148,7 @@ interface QueryConfig {
138148
offset?: number;
139149
order?: PostgrestOrder<any>;
140150
after?: any;
151+
fullTextSearch?: string;
141152
filter?: (
142153
query: PostgrestFilterBuilder<any, any, any>,
143154
) => PostgrestFilterBuilder<any, any, any>;
@@ -150,6 +161,8 @@ function buildQuery<T>(
150161
const { columns = "*", count } = config;
151162
const opts = { count };
152163

164+
console.log("config", config);
165+
153166
let cols: string;
154167
if (Array.isArray(columns)) {
155168
cols = columns.join(", ");
@@ -162,6 +175,7 @@ function buildQuery<T>(
162175
if (config.filter) {
163176
query = config.filter(query);
164177
}
178+
console.log("query", query.url.search);
165179

166180
if (config.order != null) {
167181
const { key: orderKey, ...rest } = config.order;

packages/data-sheet/src/postgrest-table/index.ts

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import styles from "./main.module.sass";
44
import { DataSheet, getRowsToDelete } from "../core"; //getRowsToDelete
55
import { LithologyTag, Tag, TagSize } from "@macrostrat/data-components";
66
import { PostgrestOrder, usePostgRESTLazyLoader } from "./data-loaders";
7-
import { Spinner } from "@blueprintjs/core";
7+
import { Spinner, InputGroup } from "@blueprintjs/core";
88

99
export * from "./data-loaders";
10-
import { useCallback } from "react";
10+
import { useCallback, useState, useRef } from "react";
1111
import {
1212
ErrorBoundary,
1313
ToasterContext,
14+
useAPIResult,
1415
useToaster,
1516
} from "@macrostrat/ui-components";
1617
import { Spec } from "immutability-helper";
@@ -40,6 +41,8 @@ interface PostgRESTTableViewProps<T extends object>
4041
columns?: string;
4142
editable?: boolean;
4243
identityKey?: string;
44+
enableFullTableSearch?: boolean;
45+
dataSheetActions?: any;
4346
filter(
4447
query: PostgrestFilterBuilder<T, any, any>,
4548
): PostgrestFilterBuilder<T, any, any>;
@@ -61,10 +64,32 @@ function _PostgRESTTableView<T>({
6164
order,
6265
columns,
6366
editable = false,
64-
filter,
67+
filter = undefined,
68+
enableFullTableSearch = false,
69+
dataSheetActions,
6570
identityKey = "id",
6671
...rest
6772
}: PostgRESTTableViewProps<T>) {
73+
const [input, setInput] = useState("");
74+
75+
if (enableFullTableSearch) {
76+
const columnList = columns ?? getColumnList(endpoint, table);
77+
78+
filter = (query) => {
79+
const urlParams = new URLSearchParams(query.url.search);
80+
urlParams.delete("or");
81+
query.url.search = urlParams.toString() ? `?${urlParams.toString()}` : "";
82+
83+
if (input.length > 2 && enableFullTableSearch) {
84+
const conditions = columnList?.map((col) => `${col}.ilike.*${input}*`);
85+
86+
return query.or(conditions.join(","));
87+
}
88+
89+
return query;
90+
};
91+
}
92+
6893
const { data, onScroll, dispatch, client } = usePostgRESTLazyLoader(
6994
endpoint,
7095
table,
@@ -99,6 +124,9 @@ function _PostgRESTTableView<T>({
99124
return h("div.data-sheet-outer", [
100125
h(DataSheet, {
101126
...rest,
127+
dataSheetActions: enableFullTableSearch
128+
? h(SearchAction, { input, setInput, dispatch })
129+
: dataSheetActions,
102130
data,
103131
columnSpecOptions: columnOptions ?? {},
104132
editable,
@@ -231,3 +259,33 @@ export function ExpandedLithologies({ value, onChange }) {
231259
]),
232260
]);
233261
}
262+
263+
export function SearchAction({ input, setInput, dispatch }) {
264+
return h(InputGroup, {
265+
type: "search",
266+
placeholder: "Search table...",
267+
value: input,
268+
onChange(event) {
269+
const search = event.target.value;
270+
if (search.length > 2 || (input.length === 3 && search.length < 3)) {
271+
dispatch({ type: "reset" });
272+
}
273+
setInput(search.toLowerCase());
274+
},
275+
});
276+
}
277+
278+
function getColumnList(endpoint: string, table: string) {
279+
const url = `${endpoint}/${table}?select=*&limit=1`;
280+
const res = useAPIResult(url);
281+
282+
if (!res || !Array.isArray(res) || res.length === 0) return [];
283+
284+
const sampleRow = res[0];
285+
286+
return Object.entries(sampleRow)
287+
.filter(([_, value]) => {
288+
return typeof value === "string";
289+
})
290+
.map(([key]) => key);
291+
}

packages/data-sheet/stories/postgrest-sheet.stories.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export const Simple = {
9797
args: {},
9898
};
9999

100+
export const FullTableSearch = {
101+
args: {
102+
enableFullTableSearch: true,
103+
},
104+
};
105+
100106
export const ReorderableColumns = {
101107
args: {
102108
columnOptions: defaultColumnOptions,

packages/feedback-components/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. The format
44
is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
55
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.1.2] - 2025-07-10
8+
9+
- Increased the default line spacing in the paragraph text (made it configurable
10+
via a CSS variable)
11+
- Added a toggle in the graph view to show labels for all nodes, and made nodes
12+
slightly bigger
13+
- Unified selection interactions
14+
- Updated tags in the "select list" on the right to have styling for
15+
selected/unselected states consistent with the rest of the interface
16+
- Added "assistant panel" style entity types selector
17+
- Added a border to selected tags in the paragraph area, similar to the list
18+
view
19+
- Snapped tag selections to word boundaries
20+
721
## [1.1.1] - 2025-07-01
822

923
- new text component, following same clicking rules as tree

packages/feedback-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@macrostrat/feedback-components",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "",
55
"source": "src/index.ts",
66
"type": "module",

0 commit comments

Comments
 (0)