-
Notifications
You must be signed in to change notification settings - Fork 228
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
feat: Add autocomplete of metrics attributes #623
base: warren/metrics-mvp
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ import { useDebouncedValue } from '@mantine/hooks'; | |
import { SQLInlineEditorControlled } from '@/components/SQLInlineEditor'; | ||
import WhereLanguageControlled from '@/components/WhereLanguageControlled'; | ||
import SearchInputV2 from '@/SearchInputV2'; | ||
import { formatAttributeClause } from '@/utils'; | ||
|
||
import { DBSqlRowTable } from './DBRowTable'; | ||
|
||
|
@@ -118,17 +119,6 @@ export default function ContextSubpanel({ | |
return isSql ? `${original} AND ${addition}` : `${original} ${addition}`; | ||
} | ||
|
||
// Helper function to format resource attribute clause | ||
function formatResourceAttributeClause( | ||
field: string, | ||
value: string, | ||
isSql: boolean, | ||
): string { | ||
return isSql | ||
? `ResourceAttributes['${field}'] = '${value}'` | ||
: `ResourceAttributes.${field}:"${value}"`; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just moving this function into utils so it can be used in other places as well. |
||
// Main function to generate WHERE clause based on context | ||
function getWhereClause(contextBy: ContextBy): string { | ||
const isSql = originalLanguage === 'sql'; | ||
|
@@ -142,7 +132,8 @@ export default function ContextSubpanel({ | |
return combineWhereClauses(originalWhere, debouncedWhere.trim(), isSql); | ||
} | ||
|
||
const attributeClause = formatResourceAttributeClause( | ||
const attributeClause = formatAttributeClause( | ||
'ResourceAttributes', | ||
mapping.field, | ||
mapping.value, | ||
isSql, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ type SQLInlineEditorProps = { | |
disableKeywordAutocomplete?: boolean; | ||
connectionId: string | undefined; | ||
enableHotkey?: boolean; | ||
additionalSuggestions?: string[]; | ||
}; | ||
|
||
const styleTheme = EditorView.baseTheme({ | ||
|
@@ -132,6 +133,7 @@ export default function SQLInlineEditor({ | |
disableKeywordAutocomplete, | ||
connectionId, | ||
enableHotkey, | ||
additionalSuggestions = [], | ||
}: SQLInlineEditorProps) { | ||
const { data: fields } = useAllFields( | ||
{ | ||
|
@@ -156,30 +158,30 @@ export default function SQLInlineEditor({ | |
|
||
const updateAutocompleteColumns = useCallback( | ||
(viewRef: EditorView) => { | ||
const keywords = | ||
filteredFields?.map(column => { | ||
const keywords = [ | ||
...(filteredFields?.map(column => { | ||
if (column.path.length > 1) { | ||
return `${column.path[0]}['${column.path[1]}']`; | ||
} | ||
return column.path[0]; | ||
}) ?? []; | ||
}) ?? []), | ||
...additionalSuggestions, | ||
]; | ||
|
||
viewRef.dispatch({ | ||
effects: compartmentRef.current.reconfigure( | ||
sql({ | ||
defaultTable: table ?? '', | ||
// schema, // FIXME: maybe we want to use schema. need to figure out the identifier issue | ||
dialect: SQLDialect.define({ | ||
keywords: | ||
keywords.join(' ') + | ||
(disableKeywordAutocomplete ? '' : AUTOCOMPLETE_LIST_STRING), | ||
// identifierQuotes: '`', | ||
}), | ||
}), | ||
), | ||
}); | ||
}, | ||
[filteredFields, table], | ||
[filteredFields, table, additionalSuggestions], | ||
); | ||
|
||
useEffect(() => { | ||
|
@@ -275,31 +277,6 @@ export default function SQLInlineEditor({ | |
onCreateEditor={view => { | ||
updateAutocompleteColumns(view); | ||
}} | ||
// onUpdate={update => { | ||
// // console.log( | ||
// // 'update', | ||
// // update, | ||
// // update.view.hasFocus, | ||
// // update.focusChanged, | ||
// // ref.current, | ||
// // ); | ||
// // Always open completion window as much as possible | ||
// console.log( | ||
// 'update', | ||
// update, | ||
// update.focusChanged, | ||
// update.view.hasFocus, | ||
// ref.current?.view?.hasFocus, | ||
// ); | ||
// if ( | ||
// update.focusChanged && | ||
// update.view.hasFocus && | ||
// ref.current?.view | ||
// ) { | ||
// console.log('startCompletion'); | ||
// startCompletion(ref.current?.view); | ||
// } | ||
// }} | ||
basicSetup={{ | ||
lineNumbers: false, | ||
foldGutter: false, | ||
|
@@ -326,6 +303,7 @@ export function SQLInlineEditorControlled({ | |
placeholder, | ||
filterField, | ||
connectionId, | ||
additionalSuggestions, | ||
...props | ||
}: Omit<SQLInlineEditorProps, 'value' | 'onChange'> & UseControllerProps<any>) { | ||
const { field } = useController(props); | ||
|
@@ -339,6 +317,7 @@ export function SQLInlineEditorControlled({ | |
table={table} | ||
value={field.value || props.defaultValue} | ||
connectionId={connectionId} | ||
additionalSuggestions={additionalSuggestions} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds the ability to arbitrarily add suggestions to autocomplete that aren't already based on a source. I didn't see a way to do this, but correct me if I'm wrong! |
||
{...props} | ||
/> | ||
); | ||
|
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.
I think this works for now, though I wonder if the v1 pattern of having a separate metrics tag filter input would be cleaner? We can leave it as a follow up.
https://github.com/hyperdxio/hyperdx/blob/main/packages/app/src/MetricTagFilterInput.tsx
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.
I like that idea. Will add a ticket to follow up on this and the other suggestions. Thanks!
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.
New ticket created: HDX-1410