Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/early-items-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@hyperdx/common-utils": patch
"@hyperdx/app": patch
---

fix: json getKeyValues (useful for autocomplete)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { renderHook } from '@testing-library/react';

import { LuceneLanguageFormatter } from '../../SearchInputV2';
import { useAutoCompleteOptions } from '../useAutoCompleteOptions';
import { useAllFields, useGetKeyValues } from '../useMetadata';
import { useAllFields, useGetKeyValues, useJsonColumns } from '../useMetadata';

if (!globalThis.structuredClone) {
globalThis.structuredClone = (obj: any) => {
Expand All @@ -17,6 +17,7 @@ jest.mock('../useMetadata', () => ({
...jest.requireActual('../useMetadata.tsx'),
useAllFields: jest.fn(),
useGetKeyValues: jest.fn(),
useJsonColumns: jest.fn(),
}));

const luceneFormatter = new LuceneLanguageFormatter();
Expand Down Expand Up @@ -60,6 +61,10 @@ describe('useAutoCompleteOptions', () => {
(useGetKeyValues as jest.Mock).mockReturnValue({
data: null,
});

(useJsonColumns as jest.Mock).mockReturnValue({
data: null,
});
});

it('should return field options with correct lucene formatting', () => {
Expand Down
22 changes: 14 additions & 8 deletions packages/app/src/hooks/useAutoCompleteOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
deduplicate2dArray,
useAllFields,
useGetKeyValues,
useJsonColumns,
} from '@/hooks/useMetadata';
import { toArray } from '@/utils';
import { mergePath, toArray } from '@/utils';

export interface ILanguageFormatter {
formatFieldValue: (f: Field) => string;
Expand Down Expand Up @@ -71,16 +72,21 @@ export function useAutoCompleteOptions(
setSearchField(null);
}
}, [searchField, setSearchField, value, formatter]);
const { data: jsonColumns } = useJsonColumns(
Array.isArray(tableConnections)
? tableConnections[0]
: (tableConnections ?? {
tableName: '',
databaseName: '',
connectionId: '',
}),
);
const searchKeys = useMemo(
() =>
searchField
? [
searchField.path.length > 1
? `${searchField.path[0]}['${searchField.path[1]}']`
: searchField.path[0],
]
searchField && jsonColumns
? [mergePath(searchField.path, jsonColumns)]
: [],
[searchField],
[searchField, jsonColumns],
);

// hooks to get key values
Expand Down
10 changes: 1 addition & 9 deletions packages/app/src/hooks/useMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,7 @@ export function useColumns(
}

export function useJsonColumns(
{
databaseName,
tableName,
connectionId,
}: {
databaseName: string;
tableName: string;
connectionId: string;
},
{ databaseName, tableName, connectionId }: TableConnection,
options?: Partial<UseQueryOptions<string[]>>,
) {
return useQuery<string[]>({
Expand Down
5 changes: 1 addition & 4 deletions packages/common-utils/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,7 @@ export class Metadata {
);
}
keys.push({
key: key
.split('.')
.map(v => `\`${v}\``)
.join('.'),
key: key,
chType: typeArr[0],
});
}
Expand Down
Loading