diff --git a/frontend/src/container/OptionsMenu/constants.ts b/frontend/src/container/OptionsMenu/constants.ts index b1e5463686..2db02f85b8 100644 --- a/frontend/src/container/OptionsMenu/constants.ts +++ b/frontend/src/container/OptionsMenu/constants.ts @@ -1,3 +1,5 @@ +import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse'; + import { OptionsQuery } from './types'; export const URL_OPTIONS = 'options'; @@ -7,3 +9,46 @@ export const defaultOptionsQuery: OptionsQuery = { maxLines: 2, format: 'list', }; + +export const defaultTraceSelectedColumns = [ + { + key: 'serviceName', + dataType: DataTypes.String, + type: 'tag', + isColumn: true, + isJSON: false, + id: 'serviceName--string--tag--true', + }, + { + key: 'name', + dataType: DataTypes.String, + type: 'tag', + isColumn: true, + isJSON: false, + id: 'name--string--tag--true', + }, + { + key: 'durationNano', + dataType: DataTypes.Float64, + type: 'tag', + isColumn: true, + isJSON: false, + id: 'durationNano--float64--tag--true', + }, + { + key: 'httpMethod', + dataType: DataTypes.String, + type: 'tag', + isColumn: true, + isJSON: false, + id: 'httpMethod--string--tag--true', + }, + { + key: 'responseStatusCode', + dataType: DataTypes.String, + type: 'tag', + isColumn: true, + isJSON: false, + id: 'responseStatusCode--string--tag--true', + }, +]; diff --git a/frontend/src/container/OptionsMenu/useOptionsMenu.ts b/frontend/src/container/OptionsMenu/useOptionsMenu.ts index be2ae00b37..97fbbbb006 100644 --- a/frontend/src/container/OptionsMenu/useOptionsMenu.ts +++ b/frontend/src/container/OptionsMenu/useOptionsMenu.ts @@ -16,7 +16,11 @@ import { } from 'types/api/queryBuilder/queryAutocompleteResponse'; import { DataSource } from 'types/common/queryBuilder'; -import { defaultOptionsQuery, URL_OPTIONS } from './constants'; +import { + defaultOptionsQuery, + defaultTraceSelectedColumns, + URL_OPTIONS, +} from './constants'; import { InitialOptions, OptionsMenuConfig, OptionsQuery } from './types'; import { getOptionsFromKeys } from './utils'; @@ -124,20 +128,29 @@ const useOptionsMenu = ({ { queryKey: [debouncedSearchText, isFocused], enabled: isFocused }, ); - const searchedAttributeKeys = useMemo( - () => searchedAttributesData?.payload?.attributeKeys || [], - [searchedAttributesData?.payload?.attributeKeys], - ); + const searchedAttributeKeys = useMemo(() => { + if (searchedAttributesData?.payload?.attributeKeys?.length) { + return searchedAttributesData.payload.attributeKeys; + } + if (dataSource === DataSource.TRACES) { + return defaultTraceSelectedColumns; + } + + return []; + }, [dataSource, searchedAttributesData?.payload?.attributeKeys]); const initialOptionsQuery: OptionsQuery = useMemo( () => ({ ...defaultOptionsQuery, ...initialOptions, + // eslint-disable-next-line no-nested-ternary selectColumns: initialOptions?.selectColumns ? initialSelectedColumns + : dataSource === DataSource.TRACES + ? defaultTraceSelectedColumns : defaultOptionsQuery.selectColumns, }), - [initialOptions, initialSelectedColumns], + [dataSource, initialOptions, initialSelectedColumns], ); const selectedColumnKeys = useMemo(