Skip to content

Commit

Permalink
feat: show real version in console nav (#2526)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman authored Aug 28, 2024
1 parent bf5adf5 commit 0106f6c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
8 changes: 4 additions & 4 deletions frontend/src/api/modules/use-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -40,6 +40,6 @@ export const useModules = () => {
return useQuery({
queryKey: [useModulesKey],
queryFn: async ({ signal }) => fetchModules(signal),
enabled: !!streamingData,
enabled: !!schemaData,
})
}
32 changes: 32 additions & 0 deletions frontend/src/api/status/use-status.ts
Original file line number Diff line number Diff line change
@@ -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),
})
}
6 changes: 3 additions & 3 deletions frontend/src/api/timeline/use-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<Event[]>(queryKey) ?? []
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className='min-w-[800px] min-h-[600px] max-w-full max-h-full h-full flex flex-col dark:bg-gray-800 bg-white text-gray-700 dark:text-gray-200'>
<Navigation />
<Navigation version={version} />
<main className='flex-1'>
<Outlet />
</main>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/layout/navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const navigation = [
{ name: 'Infrastructure', href: '/infrastructure', icon: ServerStackIcon },
]

export const Navigation = () => {
export const Navigation = ({ version }: { version?: string }) => {
return (
<nav className='bg-indigo-600'>
<div className='mx-auto px-4 sm:px-6'>
Expand Down Expand Up @@ -40,7 +40,7 @@ export const Navigation = () => {
</div>
<div>
<div className='ml-4 flex items-center space-x-4'>
<Version version='v0.235.0' />
<Version version={version} />
<DarkModeSwitch />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation/Version.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const Version = ({ version }: { version: string }) => {
export const Version = ({ version }: { version?: string }) => {
return <span className='text-xs font-roboto-mono text-gray-300'>{version}</span>
}

0 comments on commit 0106f6c

Please sign in to comment.