diff --git a/web/pages/DeploymentPage.tsx b/web/pages/DeploymentPage.tsx index 5d952e6..27d1afa 100644 --- a/web/pages/DeploymentPage.tsx +++ b/web/pages/DeploymentPage.tsx @@ -35,7 +35,7 @@ import { SortMenu, toggleSort, } from '../components/Filtre.tsx' -import { computed, effect, Signal } from '@preact/signals' +import { computed, effect, Signal, untracked } from '@preact/signals' import { api, type ApiOutput } from '../lib/api.ts' import { QueryHistory } from '../components/QueryHistory.tsx' @@ -62,6 +62,7 @@ const toastSignal = new Signal< >( null, ) + function toast(message: string, type: 'info' | 'error' = 'info') { toastSignal.value = { message, type } setTimeout(() => (toastSignal.value = null), 3000) @@ -85,39 +86,32 @@ effect(() => { dep && schema.fetch({ url: dep }) }) +const activeTab = computed(() => { + const tab = url.params.tab as (keyof typeof TabViews) + return tab in TabViews ? tab : 'tables' +}) + effect(() => { - url.params.tab // clear expanded when params.tab change - navigate({ params: { expanded: null }, replace: true }) + activeTab.value // clear expanded when params.tab change + untracked(() => navigate({ params: { expanded: null }, replace: true })) }) +async function sha(message: string) { + const data = new TextEncoder().encode(message) + const buff = await crypto.subtle.digest('SHA-1', data) + return new Uint8Array(buff).toHex() +} + const queryHash = new Signal('') effect(() => { const query = (url.params.q || '').trim() if (query) { - hashQuery(query).then((hash) => { - queryHash.value = hash - }) + sha(query).then((hash) => queryHash.value = hash) } else { queryHash.value = '' } }) -function sha(message: string) { - const data = new TextEncoder().encode(message) - return crypto.subtle.digest('SHA-1', data) -} - -function hashQuery(query: string) { - const hash = sha(query).then((hashBuffer) => { - const hashArray = Array.from(new Uint8Array(hashBuffer)) - const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join( - '', - ) - return hashHex - }) - return hash -} - const onSave = () => { const query = (url.params.q || '').trim() if (query) { @@ -814,17 +808,15 @@ const TabButton = ( ) -function TabNavigation({ - activeTab = 'tables', -}: { activeTab?: 'tables' | 'queries' | 'logs' | 'metrics' }) { +function TabNavigation() { // Get column names from the currently selected table for tables tab + const tab = activeTab.value const selectedTableName = url.params.table || schema.data?.tables?.[0]?.table const selectedTable = schema.data?.tables?.find((t) => t.table === selectedTableName ) const tableColumnNames = selectedTable?.columns.map((c) => c.name) || [] - - const filterKeyOptions = activeTab === 'tables' ? tableColumnNames : [ + const filterKeyOptions = tab === 'tables' ? tableColumnNames : [ 'timestamp', 'trace_id', 'span_id', @@ -850,7 +842,7 @@ function TabNavigation({
- {(activeTab === 'tables' || activeTab === 'logs') && ( + {(tab === 'tables' || tab === 'logs') && ( )} - {activeTab !== 'logs' && ( + {tab !== 'logs' && ( runQuery(url.params.q || '') : undefined} class='btn btn-primary btn-sm' > - {activeTab === 'queries' + {tab === 'queries' ? : } )} - {activeTab !== 'queries' && activeTab !== 'metrics' && ( + {tab !== 'queries' && tab !== 'metrics' && ( <> - - + + )} - {activeTab === 'queries' && ( + {tab === 'queries' && ( <>