Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 12 additions & 9 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,15 +72,17 @@ 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 ? [mergePath(searchField.path, jsonColumns ?? [])] : []),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to skip calling mergePath unless we have jsonColumns loaded right? Otherwise we might mistakenly treat JSON columns as non-JSON due to a race condition with loading the JSON column list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's a good call! updated

[searchField],
);

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