Skip to content

Commit 68f46e0

Browse files
authored
Revert "fix: json getKeyValues (useful for autocomplete) (#1186)" (#1190)
This reverts commit d60d920. Commit breaks dashboards with: <img width="1179" height="779" alt="image" src="https://github.com/user-attachments/assets/bcb05f7a-6787-4a39-859f-92e6f6ffbe9e" />
1 parent 83b9c8a commit 68f46e0

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

.changeset/early-items-design.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 1 addition & 6 deletions
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, useJsonColumns } from '../useMetadata';
7+
import { useAllFields, useGetKeyValues } from '../useMetadata';
88

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

2322
const luceneFormatter = new LuceneLanguageFormatter();
@@ -61,10 +60,6 @@ describe('useAutoCompleteOptions', () => {
6160
(useGetKeyValues as jest.Mock).mockReturnValue({
6261
data: null,
6362
});
64-
65-
(useJsonColumns as jest.Mock).mockReturnValue({
66-
data: null,
67-
});
6863
});
6964

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

packages/app/src/hooks/useAutoCompleteOptions.tsx

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

1312
export interface ILanguageFormatter {
1413
formatFieldValue: (f: Field) => string;
@@ -72,21 +71,16 @@ export function useAutoCompleteOptions(
7271
setSearchField(null);
7372
}
7473
}, [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-
);
8474
const searchKeys = useMemo(
8575
() =>
86-
searchField && jsonColumns
87-
? [mergePath(searchField.path, jsonColumns)]
76+
searchField
77+
? [
78+
searchField.path.length > 1
79+
? `${searchField.path[0]}['${searchField.path[1]}']`
80+
: searchField.path[0],
81+
]
8882
: [],
89-
[searchField, jsonColumns],
83+
[searchField],
9084
);
9185

9286
// hooks to get key values

packages/app/src/hooks/useMetadata.tsx

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

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

packages/common-utils/src/metadata.ts

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

0 commit comments

Comments
 (0)