Skip to content

Commit bd05e24

Browse files
Rishichandra Wawhalvijayprasanna13abhi40308
authored andcommitted
console: data sidebar table search
PR-URL: hasura/graphql-engine-mono#3826 Co-authored-by: Vijay Prasanna <[email protected]> Co-authored-by: Abhijeet Khangarot <[email protected]> GitOrigin-RevId: a7de40686c9d3f1551e84aeec376ff143935a97a
1 parent 073b9c3 commit bd05e24

File tree

4 files changed

+90
-22
lines changed

4 files changed

+90
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function:
106106
- server: fix regression where remote relationships would get exposed over Relay, which is unsupported
107107
- server: add support for customising the GraphQL schema descriptions of table columns in metadata
108108
- console: fixed an issue where editing both a column's name and its GraphQL field name at the same time caused an error
109+
- console: enable searching tables within a schema
109110
- cli: fix inherited roles metadata not being updated when dropping all roles (#7872)
110111
- cli: add support for customization field in sources metadata (#8292)
111112

console/cypress/integration/actions/spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ export const createActionTransform = () => {
352352
// give correct body
353353
clearRequestUrl();
354354
typeIntoRequestUrl('/{{$body.action.name}}');
355+
cy.wait(AWAIT_SHORT);
355356
typeIntoRequestQueryParams([
356357
{ key: 'id', value: '5' },
357358
{ key: 'name', value: '{{$body.action.name}}' },

console/src/components/Services/Data/DataSubSidebar.js

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ const DataSubSidebar = props => {
304304
currentSchema={currentSchema}
305305
pathname={pathname}
306306
databaseLoading={databaseLoading}
307+
schemaLoading={schemaLoading}
307308
preLoadState={preLoadState}
308309
/>
309310
</div>

console/src/components/Services/Data/TreeView.tsx

+87-22
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ const activeStyle = {
2525
color: '#fd9540',
2626
};
2727

28+
const filterItemsBySearch = (searchQuery: string, itemList: SourceItem[]) => {
29+
const caseSensitiveResults: SourceItem[] = [];
30+
const caseAgnosticResults: SourceItem[] = [];
31+
itemList.forEach(item => {
32+
if (item.name.search(searchQuery) > -1) {
33+
caseSensitiveResults.push(item);
34+
} else if (item.name.toLowerCase().search(searchQuery.toLowerCase()) > -1) {
35+
caseAgnosticResults.push(item);
36+
}
37+
});
38+
39+
return [
40+
...caseSensitiveResults.sort((item1, item2) => {
41+
return item1.name.search(searchQuery) > item2.name.search(searchQuery)
42+
? 1
43+
: -1;
44+
}),
45+
...caseAgnosticResults.sort((item1, item2) => {
46+
return item1.name.toLowerCase().search(searchQuery.toLowerCase()) >
47+
item2.name.toLowerCase().search(searchQuery.toLowerCase())
48+
? 1
49+
: -1;
50+
}),
51+
];
52+
};
53+
2854
type LeafItemsViewProps = {
2955
item: SourceItem;
3056
currentSource: string;
@@ -130,6 +156,7 @@ type SchemaItemsViewProps = {
130156
setActiveSchema: (value: string) => void;
131157
pathname: string;
132158
databaseLoading: boolean;
159+
schemaLoading: boolean;
133160
};
134161
const SchemaItemsView: React.FC<SchemaItemsViewProps> = ({
135162
item,
@@ -138,14 +165,28 @@ const SchemaItemsView: React.FC<SchemaItemsViewProps> = ({
138165
setActiveSchema,
139166
pathname,
140167
databaseLoading,
168+
schemaLoading,
141169
}) => {
142170
const [isOpen, setIsOpen] = useState(false);
171+
172+
const [search, setSearch] = React.useState('');
173+
const onSearchChange = React.useCallback(
174+
(e: React.ChangeEvent<HTMLInputElement>) => {
175+
setSearch(e.target.value);
176+
},
177+
[search]
178+
);
179+
143180
const showActiveStyle =
144181
pathname === `/data/${currentSource}/schema/${item.name}`;
145182
useEffect(() => {
146183
setIsOpen(isActive);
147184
}, [isActive]);
148185

186+
const itemSearchResults = search
187+
? filterItemsBySearch(search, item.children || [])
188+
: item.children;
189+
149190
return (
150191
<>
151192
<div
@@ -169,32 +210,50 @@ const SchemaItemsView: React.FC<SchemaItemsViewProps> = ({
169210
{item.name}
170211
</span>
171212
</div>
172-
<ul className={styles.reducedChildPadding}>
173-
{isOpen && item.children ? (
174-
!databaseLoading ? (
175-
item.children.map((child, key) => (
176-
<li key={key}>
177-
<LeafItemsView
178-
item={child}
179-
currentSource={currentSource}
180-
currentSchema={item.name}
181-
key={key}
182-
pathname={pathname}
213+
{isOpen && itemSearchResults ? (
214+
!(databaseLoading || schemaLoading) ? (
215+
item.children?.length ? (
216+
<>
217+
<div className="my-1 px-sm">
218+
<input
219+
type="text"
220+
onChange={onSearchChange}
221+
className="form-control"
222+
placeholder={`Search tables in ${item.name}....`}
223+
data-test="search-tables"
183224
/>
184-
</li>
185-
))
225+
</div>
226+
<ul className={styles.reducedChildPadding}>
227+
{itemSearchResults.map((child, key) => (
228+
<li key={key}>
229+
<LeafItemsView
230+
item={child}
231+
currentSource={currentSource}
232+
currentSchema={item.name}
233+
key={key}
234+
pathname={pathname}
235+
/>
236+
</li>
237+
))}
238+
</ul>
239+
</>
186240
) : (
187-
<li>
188-
<span
189-
className={`${styles.sidebarTablePadding} ${styles.padd_bottom_small}`}
190-
>
191-
<i className="fa fa-table" />
192-
<span className={styles.loaderBar} />
193-
</span>
241+
<li
242+
className="font-normal px-sm"
243+
data-test="table-sidebar-no-tables"
244+
>
245+
<i>No tables or views in this schema</i>
194246
</li>
195247
)
196-
) : null}
197-
</ul>
248+
) : (
249+
<span
250+
className={`${styles.sidebarTablePadding} ${styles.padd_bottom_small}`}
251+
>
252+
<i className="fa fa-table" />
253+
<span className={styles.loaderBar} />
254+
</span>
255+
)
256+
) : null}
198257
</>
199258
);
200259
};
@@ -207,6 +266,7 @@ type DatabaseItemsViewProps = {
207266
currentSchema: string;
208267
pathname: string;
209268
databaseLoading: boolean;
269+
schemaLoading: boolean;
210270
};
211271
const DatabaseItemsView: React.FC<DatabaseItemsViewProps> = ({
212272
item,
@@ -216,6 +276,7 @@ const DatabaseItemsView: React.FC<DatabaseItemsViewProps> = ({
216276
currentSchema,
217277
pathname,
218278
databaseLoading,
279+
schemaLoading,
219280
}) => {
220281
const [isOpen, setIsOpen] = useState(false);
221282
const showActiveStyle = [
@@ -265,6 +326,7 @@ const DatabaseItemsView: React.FC<DatabaseItemsViewProps> = ({
265326
key={key}
266327
pathname={pathname}
267328
databaseLoading={databaseLoading}
329+
schemaLoading={schemaLoading}
268330
/>
269331
</li>
270332
))
@@ -291,6 +353,7 @@ type TreeViewProps = {
291353
currentSchema: string;
292354
pathname: string;
293355
databaseLoading: boolean;
356+
schemaLoading: boolean;
294357
preLoadState: boolean;
295358
};
296359
const TreeView: React.FC<TreeViewProps> = ({
@@ -301,6 +364,7 @@ const TreeView: React.FC<TreeViewProps> = ({
301364
currentSchema,
302365
pathname,
303366
databaseLoading,
367+
schemaLoading,
304368
preLoadState,
305369
}) => {
306370
const handleSelectDataSource = (dataSource: string) => {
@@ -348,6 +412,7 @@ const TreeView: React.FC<TreeViewProps> = ({
348412
currentSchema={currentSchema}
349413
pathname={pathname}
350414
databaseLoading={databaseLoading}
415+
schemaLoading={schemaLoading}
351416
/>
352417
))}
353418
</div>

0 commit comments

Comments
 (0)