Skip to content

Commit 945aeb9

Browse files
authored
Revert "Revert "fix: json getKeyValues (useful for autocomplete) (#1186)" (#1…"
This reverts commit 68f46e0.
1 parent fa25a0c commit 945aeb9

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

.changeset/early-items-design.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
"@hyperdx/app": patch
4+
---
5+
6+
fix: json getKeyValues (useful for autocomplete)

packages/app/src/hooks/__tests__/useAutoCompleteOptions.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { renderHook } from '@testing-library/react';
44

55
import { LuceneLanguageFormatter } from '../../SearchInputV2';
66
import { useAutoCompleteOptions } from '../useAutoCompleteOptions';
7-
import { useAllFields, useGetKeyValues } from '../useMetadata';
7+
import { useAllFields, useGetKeyValues, useJsonColumns } from '../useMetadata';
88

99
if (!globalThis.structuredClone) {
1010
globalThis.structuredClone = (obj: any) => {
@@ -17,6 +17,7 @@ jest.mock('../useMetadata', () => ({
1717
...jest.requireActual('../useMetadata.tsx'),
1818
useAllFields: jest.fn(),
1919
useGetKeyValues: jest.fn(),
20+
useJsonColumns: jest.fn(),
2021
}));
2122

2223
const luceneFormatter = new LuceneLanguageFormatter();
@@ -60,6 +61,10 @@ describe('useAutoCompleteOptions', () => {
6061
(useGetKeyValues as jest.Mock).mockReturnValue({
6162
data: null,
6263
});
64+
65+
(useJsonColumns as jest.Mock).mockReturnValue({
66+
data: null,
67+
});
6368
});
6469

6570
it('should return field options with correct lucene formatting', () => {

packages/app/src/hooks/useAutoCompleteOptions.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import {
66
deduplicate2dArray,
77
useAllFields,
88
useGetKeyValues,
9+
useJsonColumns,
910
} from '@/hooks/useMetadata';
10-
import { toArray } from '@/utils';
11+
import { mergePath, toArray } from '@/utils';
1112

1213
export interface ILanguageFormatter {
1314
formatFieldValue: (f: Field) => string;
@@ -71,16 +72,21 @@ export function useAutoCompleteOptions(
7172
setSearchField(null);
7273
}
7374
}, [searchField, setSearchField, value, formatter]);
75+
const { data: jsonColumns } = useJsonColumns(
76+
Array.isArray(tableConnections)
77+
? tableConnections[0]
78+
: (tableConnections ?? {
79+
tableName: '',
80+
databaseName: '',
81+
connectionId: '',
82+
}),
83+
);
7484
const searchKeys = useMemo(
7585
() =>
76-
searchField
77-
? [
78-
searchField.path.length > 1
79-
? `${searchField.path[0]}['${searchField.path[1]}']`
80-
: searchField.path[0],
81-
]
86+
searchField && jsonColumns
87+
? [mergePath(searchField.path, jsonColumns)]
8288
: [],
83-
[searchField],
89+
[searchField, jsonColumns],
8490
);
8591

8692
// hooks to get key values

packages/app/src/hooks/useMetadata.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ export function useColumns(
4848
}
4949

5050
export function useJsonColumns(
51-
{
52-
databaseName,
53-
tableName,
54-
connectionId,
55-
}: {
56-
databaseName: string;
57-
tableName: string;
58-
connectionId: string;
59-
},
51+
{ databaseName, tableName, connectionId }: TableConnection,
6052
options?: Partial<UseQueryOptions<string[]>>,
6153
) {
6254
return useQuery<string[]>({

packages/common-utils/src/metadata.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,7 @@ export class Metadata {
357357
);
358358
}
359359
keys.push({
360-
key: key
361-
.split('.')
362-
.map(v => `\`${v}\``)
363-
.join('.'),
360+
key: key,
364361
chType: typeArr[0],
365362
});
366363
}

0 commit comments

Comments
 (0)