Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enum syntax highlighting #3001

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions frontend/console/src/api/modules/use-modules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Code, ConnectError } from '@connectrpc/connect'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { useEffect } from 'react'
import { useQuery } from '@tanstack/react-query'
import { useClient } from '../../hooks/use-client'
import { ConsoleService } from '../../protos/xyz/block/ftl/v1/console/console_connect'
import { useSchema } from '../schema/use-schema'
Expand All @@ -9,16 +8,7 @@ const useModulesKey = 'modules'

export const useModules = () => {
const client = useClient(ConsoleService)
const queryClient = useQueryClient()
const { data: schemaData } = useSchema()

useEffect(() => {
if (schemaData) {
queryClient.invalidateQueries({
queryKey: [useModulesKey],
})
}
}, [schemaData, queryClient])
const { data: schemaData, dataUpdatedAt: schemaUpdatedAt } = useSchema()

const fetchModules = async (signal: AbortSignal) => {
try {
Expand All @@ -38,7 +28,7 @@ export const useModules = () => {
}

return useQuery({
queryKey: [useModulesKey],
queryKey: [useModulesKey, schemaUpdatedAt],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this, the schema would change (delete old modules) and never trigger the modules to reload. This should be better once we have a dedicated streaming endpoint :)

Also note that with the current deployment/schema stuff, it's possible to have 2 active deployments for the same module for a few seconds while the old module gets cleaned up. We'll want to add handling to our streaming endpoint to return the most recently activated deployment vs. returning both the old and new.

In the future, this will need more attention since we'll likely want to show multiple deployed versions, but until we have versioning worked out we should probably just show the most recent active deployment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, that makes sense. Thanks for catching that! The streaming endpoint does already filter for unique module names and chooses the latest when there is a dup. I haven't added update handling to the backend yet, though, so it's not yet tested.

queryFn: async ({ signal }) => fetchModules(signal),
enabled: !!schemaData,
})
Expand Down
4 changes: 2 additions & 2 deletions frontend/console/src/api/schema/use-schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Code, ConnectError } from '@connectrpc/connect'
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { type UseQueryResult, useQuery, useQueryClient } from '@tanstack/react-query'
import { useClient } from '../../hooks/use-client.ts'
import { useVisibility } from '../../hooks/use-visibility.ts'
import { ControllerService } from '../../protos/xyz/block/ftl/v1/ftl_connect.ts'
Expand All @@ -9,7 +9,7 @@ const streamingSchemaKey = 'streamingSchema'
const currentDeployments: Record<string, string> = {}
const schemaMap: Record<string, PullSchemaResponse> = {}

export const useSchema = () => {
export const useSchema = (): UseQueryResult<PullSchemaResponse[], Error> => {
const client = useClient(ControllerService)
const queryClient = useQueryClient()
const isVisible = useVisibility()
Expand Down
2 changes: 1 addition & 1 deletion frontend/console/src/features/modules/schema/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function maybeRenderDeclName(token: string, declType: string, tokens: string[],
return
}
if (declType === 'enum') {
return [<LinkToken key='l' token={token.slice(0, token.length - 1)} containerRect={containerRect} />, token.slice(-1)]
return [<LinkToken key='l' token={token} containerRect={containerRect} />]
}
if (declType === 'verb') {
return <LinkVerbNameToken token={token} containerRect={containerRect} />
Expand Down
Loading