feat: show distinct attribute keys in cmd-k Attributes tab
Add GET /search/attributes/keys endpoint that queries distinct attribute key names from ClickHouse using JSONExtractKeys. Attribute keys appear in the cmd-k Attributes tab alongside attribute value matches from exchange results. - SearchIndex.distinctAttributeKeys() interface method - ClickHouseSearchIndex implementation using arrayJoin(JSONExtractKeys) - SearchController /attributes/keys endpoint - useAttributeKeys() React Query hook - buildSearchData includes attribute keys as 'attribute' category items Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,22 @@ export function useExecutionStats(
|
||||
});
|
||||
}
|
||||
|
||||
export function useAttributeKeys() {
|
||||
return useQuery({
|
||||
queryKey: ['search', 'attribute-keys'],
|
||||
queryFn: async () => {
|
||||
const token = (await import('../../auth/auth-store')).useAuthStore.getState().accessToken;
|
||||
const { config } = await import('../../config');
|
||||
const res = await fetch(`${config.apiBaseUrl}/search/attributes/keys`, {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
if (!res.ok) throw new Error('Failed to load attribute keys');
|
||||
return res.json() as Promise<string[]>;
|
||||
},
|
||||
staleTime: 60_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function useSearchExecutions(filters: SearchRequest, live = false) {
|
||||
const liveQuery = useLiveQuery(5_000);
|
||||
return useQuery({
|
||||
|
||||
@@ -3,7 +3,7 @@ import { AppShell, Sidebar, TopBar, CommandPalette, CommandPaletteProvider, Glob
|
||||
import type { SidebarApp, SearchResult } from '@cameleer/design-system';
|
||||
import { useRouteCatalog } from '../api/queries/catalog';
|
||||
import { useAgents } from '../api/queries/agents';
|
||||
import { useSearchExecutions } from '../api/queries/executions';
|
||||
import { useSearchExecutions, useAttributeKeys } from '../api/queries/executions';
|
||||
import { useAuthStore } from '../auth/auth-store';
|
||||
import { useState, useMemo, useCallback, useEffect, useRef } from 'react';
|
||||
import { ContentTabs } from './ContentTabs';
|
||||
@@ -21,6 +21,7 @@ function healthToColor(health: string): string {
|
||||
function buildSearchData(
|
||||
catalog: any[] | undefined,
|
||||
agents: any[] | undefined,
|
||||
attrKeys: string[] | undefined,
|
||||
): SearchResult[] {
|
||||
if (!catalog) return [];
|
||||
const results: SearchResult[] = [];
|
||||
@@ -61,6 +62,17 @@ function buildSearchData(
|
||||
}
|
||||
}
|
||||
|
||||
if (attrKeys) {
|
||||
for (const key of attrKeys) {
|
||||
results.push({
|
||||
id: `attr-key-${key}`,
|
||||
category: 'attribute',
|
||||
title: key,
|
||||
meta: 'attribute key',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -94,6 +106,7 @@ function LayoutContent() {
|
||||
const { timeRange } = useGlobalFilters();
|
||||
const { data: catalog } = useRouteCatalog(timeRange.start.toISOString(), timeRange.end.toISOString());
|
||||
const { data: agents } = useAgents();
|
||||
const { data: attributeKeys } = useAttributeKeys();
|
||||
const { username, logout } = useAuthStore();
|
||||
const { open: paletteOpen, setOpen: setPaletteOpen } = useCommandPalette();
|
||||
const { scope, setTab } = useScope();
|
||||
@@ -141,8 +154,8 @@ function LayoutContent() {
|
||||
}, [catalog]);
|
||||
|
||||
const catalogData = useMemo(
|
||||
() => buildSearchData(catalog, agents as any[]),
|
||||
[catalog, agents],
|
||||
() => buildSearchData(catalog, agents as any[], attributeKeys),
|
||||
[catalog, agents, attributeKeys],
|
||||
);
|
||||
|
||||
// Stable reference for catalog data — only changes when catalog/agents actually change,
|
||||
|
||||
Reference in New Issue
Block a user