From 0106f6c5aaef1e6c41791a2f116714286de2b62f Mon Sep 17 00:00:00 2001 From: Wes Date: Wed, 28 Aug 2024 14:05:31 -0700 Subject: [PATCH] feat: show real version in console nav (#2526) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2488 ![Screenshot 2024-08-28 at 12 14 03 PM](https://github.com/user-attachments/assets/b9fe7e81-5b8d-4fab-98ae-79007b992550) --- frontend/src/api/modules/use-modules.ts | 8 ++--- frontend/src/api/status/use-status.ts | 32 +++++++++++++++++++ frontend/src/api/timeline/use-timeline.ts | 6 ++-- frontend/src/layout/Layout.tsx | 6 +++- frontend/src/layout/navigation/Navigation.tsx | 4 +-- frontend/src/layout/navigation/Version.tsx | 2 +- 6 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 frontend/src/api/status/use-status.ts diff --git a/frontend/src/api/modules/use-modules.ts b/frontend/src/api/modules/use-modules.ts index 5bbbe201f8..d71d1f7f14 100644 --- a/frontend/src/api/modules/use-modules.ts +++ b/frontend/src/api/modules/use-modules.ts @@ -10,15 +10,15 @@ const useModulesKey = 'modules' export const useModules = () => { const client = useClient(ConsoleService) const queryClient = useQueryClient() - const { data: streamingData } = useSchema() + const { data: schemaData } = useSchema() useEffect(() => { - if (streamingData) { + if (schemaData) { queryClient.invalidateQueries({ queryKey: [useModulesKey], }) } - }, [streamingData, queryClient]) + }, [schemaData, queryClient]) const fetchModules = async (signal: AbortSignal) => { try { @@ -40,6 +40,6 @@ export const useModules = () => { return useQuery({ queryKey: [useModulesKey], queryFn: async ({ signal }) => fetchModules(signal), - enabled: !!streamingData, + enabled: !!schemaData, }) } diff --git a/frontend/src/api/status/use-status.ts b/frontend/src/api/status/use-status.ts new file mode 100644 index 0000000000..b38f3c379f --- /dev/null +++ b/frontend/src/api/status/use-status.ts @@ -0,0 +1,32 @@ +import { Code, ConnectError } from '@connectrpc/connect' +import { useQuery } from '@tanstack/react-query' +import { useClient } from '../../hooks/use-client' +import { ControllerService } from '../../protos/xyz/block/ftl/v1/ftl_connect' + +const useStatusKey = 'status' + +export const useStatus = () => { + const client = useClient(ControllerService) + + const fetchStatus = async (signal: AbortSignal) => { + try { + console.debug('fetching status from FTL') + const status = await client.status({}, { signal }) + return status + } catch (error) { + if (error instanceof ConnectError) { + if (error.code !== Code.Canceled) { + console.error('fetchStatus - Connect error:', error) + } + } else { + console.error('fetchStatus:', error) + } + throw error + } + } + + return useQuery({ + queryKey: [useStatusKey], + queryFn: async ({ signal }) => fetchStatus(signal), + }) +} diff --git a/frontend/src/api/timeline/use-timeline.ts b/frontend/src/api/timeline/use-timeline.ts index 63b30f86b0..c640ca94ae 100644 --- a/frontend/src/api/timeline/use-timeline.ts +++ b/frontend/src/api/timeline/use-timeline.ts @@ -20,7 +20,7 @@ export const useTimeline = (isStreaming: boolean, filters: EventsQuery_Filter[], const fetchTimeline = async ({ signal }: { signal: AbortSignal }) => { try { - console.log('fetching timeline') + console.debug('fetching timeline') const response = await client.getEvents({ filters, limit, order }, { signal }) return response.events } catch (error) { @@ -35,8 +35,8 @@ export const useTimeline = (isStreaming: boolean, filters: EventsQuery_Filter[], const streamTimeline = async ({ signal }: { signal: AbortSignal }) => { try { - console.log('streaming timeline') - console.log('filters:', filters) + console.debug('streaming timeline') + console.debug('filters:', filters) for await (const response of client.streamEvents({ updateInterval: { seconds: BigInt(1) }, query: { limit, filters, order } }, { signal })) { if (response.events) { const prev = queryClient.getQueryData(queryKey) ?? [] diff --git a/frontend/src/layout/Layout.tsx b/frontend/src/layout/Layout.tsx index 787429395b..0e63b8520c 100644 --- a/frontend/src/layout/Layout.tsx +++ b/frontend/src/layout/Layout.tsx @@ -1,10 +1,14 @@ import { Outlet } from 'react-router-dom' +import { useStatus } from '../api/status/use-status' import { Navigation } from './navigation/Navigation' export const Layout = () => { + const status = useStatus() + const version = status.data?.controllers?.[0]?.version + return (
- +
diff --git a/frontend/src/layout/navigation/Navigation.tsx b/frontend/src/layout/navigation/Navigation.tsx index 0096eed3fb..9ff869f383 100644 --- a/frontend/src/layout/navigation/Navigation.tsx +++ b/frontend/src/layout/navigation/Navigation.tsx @@ -12,7 +12,7 @@ const navigation = [ { name: 'Infrastructure', href: '/infrastructure', icon: ServerStackIcon }, ] -export const Navigation = () => { +export const Navigation = ({ version }: { version?: string }) => { return (