-
Notifications
You must be signed in to change notification settings - Fork 282
fix: autocomplete for lucene column values #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
60b8734
fix: autocomplete for lucene key+vals working
knudtty b1ba610
test: added testing for useAutoCompleteOptions
knudtty 3d9f864
test: add tests for useGetKeyValues
knudtty c2469b2
docs: add changeset
knudtty 127da23
fix: consistent styles
knudtty 18a4e83
Merge remote-tracking branch 'origin/v2' into aaron/key-value-autocom…
knudtty 47b9b36
fix: lint issues
knudtty 7f06fa2
Merge branch 'v2' into aaron/key-value-autocomplete
kodiakhq[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@hyperdx/common-utils": patch | ||
"@hyperdx/app": patch | ||
--- | ||
|
||
fix: autocomplete for key-values complete for v2 lucene |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
210 changes: 210 additions & 0 deletions
210
packages/app/src/hooks/__tests__/useAutoCompleteOptions.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,210 @@ | ||
import { JSDataType } from '@hyperdx/common-utils/dist/clickhouse'; | ||
import { Field } from '@hyperdx/common-utils/dist/metadata'; | ||
import { renderHook } from '@testing-library/react'; | ||
|
||
import { LuceneLanguageFormatter } from '../../SearchInputV2'; | ||
import { useAutoCompleteOptions } from '../useAutoCompleteOptions'; | ||
import { useAllFields, useGetKeyValues } from '../useMetadata'; | ||
|
||
if (!globalThis.structuredClone) { | ||
globalThis.structuredClone = (obj: any) => { | ||
return JSON.parse(JSON.stringify(obj)); | ||
}; | ||
} | ||
|
||
// Mock dependencies | ||
jest.mock('../useMetadata', () => ({ | ||
...jest.requireActual('../useMetadata.tsx'), | ||
useAllFields: jest.fn(), | ||
useGetKeyValues: jest.fn(), | ||
})); | ||
|
||
const luceneFormatter = new LuceneLanguageFormatter(); | ||
|
||
const mockFields: Field[] = [ | ||
{ | ||
path: ['ResourceAttributes'], | ||
jsType: JSDataType.Map, | ||
type: 'map', | ||
}, | ||
{ | ||
path: ['ResourceAttributes', 'service.name'], | ||
jsType: JSDataType.String, | ||
type: 'string', | ||
}, | ||
{ | ||
path: ['TraceAttributes', 'trace.id'], | ||
jsType: JSDataType.String, | ||
type: 'string', | ||
}, | ||
]; | ||
|
||
const mockTableConnections = [ | ||
{ | ||
databaseName: 'test_db', | ||
tableName: 'traces', | ||
connectionId: 'conn1', | ||
}, | ||
]; | ||
|
||
describe('useAutoCompleteOptions', () => { | ||
beforeEach(() => { | ||
// Reset mocks before each test | ||
jest.clearAllMocks(); | ||
|
||
// Setup default mock implementations | ||
(useAllFields as jest.Mock).mockReturnValue({ | ||
data: mockFields, | ||
}); | ||
|
||
(useGetKeyValues as jest.Mock).mockReturnValue({ | ||
data: null, | ||
}); | ||
}); | ||
|
||
it('should return field options with correct lucene formatting', () => { | ||
const { result } = renderHook(() => | ||
useAutoCompleteOptions(luceneFormatter, 'ResourceAttributes', { | ||
tableConnections: mockTableConnections, | ||
}), | ||
); | ||
|
||
expect(result.current).toEqual([ | ||
{ | ||
value: 'ResourceAttributes', | ||
label: 'ResourceAttributes (map)', | ||
}, | ||
{ | ||
value: 'ResourceAttributes.service.name', | ||
label: 'ResourceAttributes.service.name (string)', | ||
}, | ||
{ | ||
value: 'TraceAttributes.trace.id', | ||
label: 'TraceAttributes.trace.id (string)', | ||
}, | ||
]); | ||
}); | ||
|
||
it('should return key value options with correct lucene formatting', () => { | ||
const mockKeyValues = [ | ||
{ | ||
key: 'ResourceAttributes.service.name', | ||
value: ['frontend', 'backend'], | ||
}, | ||
]; | ||
|
||
(useGetKeyValues as jest.Mock).mockReturnValue({ | ||
data: mockKeyValues, | ||
}); | ||
|
||
const { result } = renderHook(() => | ||
useAutoCompleteOptions( | ||
luceneFormatter, | ||
'ResourceAttributes.service.name', | ||
{ | ||
tableConnections: mockTableConnections, | ||
}, | ||
), | ||
); | ||
|
||
expect(result.current).toEqual([ | ||
{ | ||
value: 'ResourceAttributes', | ||
label: 'ResourceAttributes (map)', | ||
}, | ||
{ | ||
value: 'ResourceAttributes.service.name', | ||
label: 'ResourceAttributes.service.name (string)', | ||
}, | ||
{ | ||
value: 'TraceAttributes.trace.id', | ||
label: 'TraceAttributes.trace.id (string)', | ||
}, | ||
{ | ||
value: 'ResourceAttributes.service.name:"frontend"', | ||
label: 'ResourceAttributes.service.name:"frontend"', | ||
}, | ||
{ | ||
value: 'ResourceAttributes.service.name:"backend"', | ||
label: 'ResourceAttributes.service.name:"backend"', | ||
}, | ||
]); | ||
}); | ||
|
||
// TODO: Does this test case need to be removed after HDX-1548? | ||
it('should handle nested key value options', () => { | ||
const mockKeyValues = [ | ||
{ | ||
key: 'ResourceAttributes', | ||
value: [ | ||
{ | ||
'service.name': 'frontend', | ||
'deployment.environment': 'production', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
(useGetKeyValues as jest.Mock).mockReturnValue({ | ||
data: mockKeyValues, | ||
}); | ||
|
||
const { result } = renderHook(() => | ||
useAutoCompleteOptions(luceneFormatter, 'ResourceAttributes', { | ||
tableConnections: mockTableConnections, | ||
}), | ||
); | ||
|
||
//console.log(result.current); | ||
expect(result.current).toEqual([ | ||
{ | ||
value: 'ResourceAttributes', | ||
label: 'ResourceAttributes (map)', | ||
}, | ||
{ | ||
value: 'ResourceAttributes.service.name', | ||
label: 'ResourceAttributes.service.name (string)', | ||
}, | ||
{ | ||
value: 'TraceAttributes.trace.id', | ||
label: 'TraceAttributes.trace.id (string)', | ||
}, | ||
{ | ||
value: 'ResourceAttributes.service.name:"frontend"', | ||
label: 'ResourceAttributes.service.name:"frontend"', | ||
}, | ||
{ | ||
value: 'ResourceAttributes.deployment.environment:"production"', | ||
label: 'ResourceAttributes.deployment.environment:"production"', | ||
}, | ||
]); | ||
}); | ||
|
||
it('should handle additional suggestions', () => { | ||
const { result } = renderHook(() => | ||
useAutoCompleteOptions(luceneFormatter, 'ResourceAttributes', { | ||
tableConnections: mockTableConnections, | ||
additionalSuggestions: ['custom.field'], | ||
}), | ||
); | ||
|
||
expect(result.current).toEqual([ | ||
{ | ||
value: 'ResourceAttributes', | ||
label: 'ResourceAttributes (map)', | ||
}, | ||
{ | ||
value: 'ResourceAttributes.service.name', | ||
label: 'ResourceAttributes.service.name (string)', | ||
}, | ||
{ | ||
value: 'TraceAttributes.trace.id', | ||
label: 'TraceAttributes.trace.id (string)', | ||
}, | ||
{ | ||
value: 'custom.field', | ||
label: 'custom.field', | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to fix it for now but I'm curious what happened if the key has '.' in it