Skip to content

Commit bbaae27

Browse files
authored
Feat: Add endpoint to get current version + display version in footer (#1174)
1 parent 8846ff4 commit bbaae27

12 files changed

Lines changed: 143 additions & 100 deletions

File tree

web/client/openapi.json

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -525,17 +525,17 @@
525525
}
526526
}
527527
},
528-
"/api/context": {
528+
"/api/meta": {
529529
"get": {
530-
"summary": "Get Api Context",
531-
"description": "Get the context",
532-
"operationId": "get_api_context_api_context_get",
530+
"summary": "Get Api Meta",
531+
"description": "Get the metadata",
532+
"operationId": "get_api_meta_api_meta_get",
533533
"responses": {
534534
"200": {
535535
"description": "Successful Response",
536536
"content": {
537537
"application/json": {
538-
"schema": { "$ref": "#/components/schemas/Context" }
538+
"schema": { "$ref": "#/components/schemas/Meta" }
539539
}
540540
}
541541
}
@@ -788,36 +788,6 @@
788788
"required": ["name", "type"],
789789
"title": "Column"
790790
},
791-
"Context": {
792-
"properties": {
793-
"concurrent_tasks": {
794-
"type": "integer",
795-
"title": "Concurrent Tasks"
796-
},
797-
"engine_adapter": { "type": "string", "title": "Engine Adapter" },
798-
"time_column_format": {
799-
"type": "string",
800-
"title": "Time Column Format"
801-
},
802-
"scheduler": { "type": "string", "title": "Scheduler" },
803-
"models": {
804-
"items": { "type": "string" },
805-
"type": "array",
806-
"title": "Models",
807-
"default": []
808-
},
809-
"config": { "type": "string", "title": "Config" }
810-
},
811-
"type": "object",
812-
"required": [
813-
"concurrent_tasks",
814-
"engine_adapter",
815-
"time_column_format",
816-
"scheduler",
817-
"config"
818-
],
819-
"title": "Context"
820-
},
821791
"ContextEnvironment": {
822792
"properties": {
823793
"environment": { "type": "string", "title": "Environment" },
@@ -1067,6 +1037,12 @@
10671037
"type": "object",
10681038
"title": "LineageColumn"
10691039
},
1040+
"Meta": {
1041+
"properties": { "version": { "type": "string", "title": "Version" } },
1042+
"type": "object",
1043+
"required": ["version"],
1044+
"title": "Meta"
1045+
},
10701046
"Model": {
10711047
"properties": {
10721048
"name": { "type": "string", "title": "Name" },

web/client/src/App.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { useEffect, useCallback, Suspense } from 'react'
2+
import { RouterProvider } from 'react-router-dom'
3+
import { Divider } from '@components/divider/Divider'
4+
import Header from './library/pages/root/Header'
5+
import Footer from './library/pages/root/Footer'
6+
import { router } from './routes'
7+
import Loading from '@components/loading/Loading'
8+
import Spinner from '@components/logo/Spinner'
9+
import { debounceAsync } from './utils'
10+
import { useApiMeta } from './api'
11+
import { useStoreContext } from '@context/context'
12+
13+
export default function App(): JSX.Element {
14+
const setVersion = useStoreContext(s => s.setVersion)
15+
16+
const { refetch: getMeta } = useApiMeta()
17+
18+
const debouncedGetMeta = useCallback(debounceAsync(getMeta, 1000, true), [
19+
getMeta,
20+
])
21+
22+
useEffect(() => {
23+
void debouncedGetMeta().then(({ data }) => {
24+
setVersion(data?.version)
25+
})
26+
27+
return () => {
28+
debouncedGetMeta.cancel()
29+
}
30+
}, [])
31+
32+
return (
33+
<>
34+
<Header />
35+
<Divider />
36+
<main className="h-full overflow-hidden">
37+
<Suspense
38+
fallback={
39+
<div className="flex justify-center items-center w-full h-full">
40+
<Loading className="inline-block">
41+
<Spinner className="w-3 h-3 border border-neutral-10 mr-4" />
42+
<h3 className="text-md">Loading Page...</h3>
43+
</Loading>
44+
</div>
45+
}
46+
>
47+
<RouterProvider router={router} />
48+
</Suspense>
49+
</main>
50+
<Divider />
51+
<Footer />
52+
</>
53+
)
54+
}

web/client/src/api/index.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,38 @@ import {
3838
getTableDiffApiTableDiffGet,
3939
type GetTableDiffApiTableDiffGetParams,
4040
type TableDiff,
41-
FetchdfInput,
41+
type FetchdfInput,
42+
Meta,
43+
getApiMetaApiMetaGet,
4244
} from './client'
4345
import {
4446
useIDE,
4547
type ErrorIDE,
4648
EnumErrorKey,
4749
} from '~/library/pages/ide/context'
4850

51+
export function useApiMeta(): UseQueryResult<Meta> {
52+
const { addError, removeError } = useIDE()
53+
54+
return useQuery<Meta, ErrorIDE>({
55+
queryKey: [`/api/meta`],
56+
queryFn: async ({ signal }) => {
57+
removeError(EnumErrorKey.Meta)
58+
59+
return await getApiMetaApiMetaGet({ signal })
60+
},
61+
cacheTime: 0,
62+
enabled: false,
63+
onError(error) {
64+
if (isCancelledError(error)) {
65+
console.log('getApiMetaApiMetaGet', 'Request aborted by React Query')
66+
} else {
67+
addError(EnumErrorKey.Meta, error)
68+
}
69+
},
70+
})
71+
}
72+
4973
export function useApiModelLineage(
5074
modelName: string,
5175
): UseQueryResult<ModelLineageApiLineageModelNameGet200> {

web/client/src/context/context.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import {
1515
import { isStringEmptyOrNil } from '~/utils'
1616

1717
interface ContextStore {
18+
version?: string
1819
showConfirmation: boolean
1920
confirmations: Confirmation[]
2021
environment: ModelEnvironment
2122
environments: Set<ModelEnvironment>
2223
initialStartDate?: ContextEnvironmentStart
2324
initialEndDate?: ContextEnvironmentEnd
2425
models: Map<string, ModelSQLMeshModel>
26+
setVersion: (version?: string) => void
2527
setShowConfirmation: (showConfirmation: boolean) => void
2628
addConfirmation: (confirmation: Confirmation) => void
2729
removeConfirmation: () => void
@@ -48,13 +50,19 @@ const environments = new Set(ModelEnvironment.getDefaultEnvironments())
4850
const environment = environments.values().next().value
4951

5052
export const useStoreContext = create<ContextStore>((set, get) => ({
53+
version: undefined,
5154
showConfirmation: false,
5255
confirmations: [],
5356
environment,
5457
environments,
5558
initialStartDate: undefined,
5659
initialEndDate: undefined,
5760
models: new Map(),
61+
setVersion(version) {
62+
set(() => ({
63+
version,
64+
}))
65+
},
5866
setShowConfirmation(showConfirmation) {
5967
set(() => ({
6068
showConfirmation,

web/client/src/library/components/report/ReportErrors.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import pluralize from 'pluralize'
33
import clsx from 'clsx'
44
import { useState, Fragment } from 'react'
55
import { useIDE, type ErrorIDE, type ErrorKey } from '../../pages/ide/context'
6-
import { toDate, toDateFormat } from '@utils/index'
6+
import { isNotNil, toDate, toDateFormat } from '@utils/index'
77
import { MinusCircleIcon, PlusCircleIcon } from '@heroicons/react/24/solid'
88
import { Divider } from '@components/divider/Divider'
9+
import { useStoreContext } from '@context/context'
910

1011
export default function ReportErrors(): JSX.Element {
1112
const { errors } = useIDE()
@@ -93,6 +94,8 @@ export function DisplayError({
9394
scope: ErrorKey
9495
error: ErrorIDE
9596
}): JSX.Element {
97+
const version = useStoreContext(s => s.version)
98+
9699
return (
97100
<div>
98101
<div className="flex w-full">
@@ -117,6 +120,11 @@ export function DisplayError({
117120
</div>
118121
</div>
119122
<div className="w-full px-4">
123+
{isNotNil(version) && (
124+
<small className="block">
125+
<b>Version</b>: {version}
126+
</small>
127+
)}
120128
{error.type != null && (
121129
<small className="block">
122130
<b>Type</b>: {error.type}

web/client/src/library/pages/ide/context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const EnumErrorKey = {
1111
EvaluateModel: 'evaluate-model',
1212
RenderModel: 'render-model',
1313
ColumnLineage: 'column-lineage',
14+
Meta: 'meta',
1415
} as const
1516

1617
export type ErrorKey = (typeof EnumErrorKey)[keyof typeof EnumErrorKey]

web/client/src/library/pages/root/Footer.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
import { useStoreContext } from '@context/context'
2+
import { isNotNil } from '@utils/index'
3+
14
export default function Footer(): JSX.Element {
5+
const version = useStoreContext(s => s.version)
6+
27
return (
38
<footer className="px-2 py-1 text-xs flex justify-between">
9+
{isNotNil(version) && (
10+
<span className="font-black inline-block mr-4">{version}</span>
11+
)}
412
<small className="text-xs">
513
© {new Date().getFullYear()}
614
&nbsp;

web/client/src/main.tsx

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import React, { Suspense, type HTMLAttributes } from 'react'
1+
import React, { type HTMLAttributes } from 'react'
22
import ThemeProvider from '@context/theme'
33
import ReactDOM from 'react-dom/client'
4-
import { RouterProvider } from 'react-router-dom'
54
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
6-
import { Divider } from '@components/divider/Divider'
7-
import Header from './library/pages/root/Header'
8-
import Footer from './library/pages/root/Footer'
9-
import { router } from './routes'
5+
import App from './App'
6+
107
import './index.css'
11-
import Loading from '@components/loading/Loading'
12-
import Spinner from '@components/logo/Spinner'
138

149
export interface PropsComponent extends HTMLAttributes<HTMLElement> {}
1510

@@ -27,24 +22,7 @@ ReactDOM.createRoot(getRootNode()).render(
2722
<React.StrictMode>
2823
<QueryClientProvider client={client}>
2924
<ThemeProvider>
30-
<Header />
31-
<Divider />
32-
<main className="h-full overflow-hidden">
33-
<Suspense
34-
fallback={
35-
<div className="flex justify-center items-center w-full h-full">
36-
<Loading className="inline-block">
37-
<Spinner className="w-3 h-3 border border-neutral-10 mr-4" />
38-
<h3 className="text-md">Loading Page...</h3>
39-
</Loading>
40-
</div>
41-
}
42-
>
43-
<RouterProvider router={router} />
44-
</Suspense>
45-
</main>
46-
<Divider />
47-
<Footer />
25+
<App />
4826
</ThemeProvider>
4927
</QueryClientProvider>
5028
</React.StrictMode>,

web/server/api/endpoints/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from web.server.api.endpoints import (
44
commands,
5-
context,
65
directories,
76
environments,
87
events,
98
files,
109
lineage,
10+
meta,
1111
models,
1212
plan,
1313
table_diff,
@@ -25,5 +25,5 @@
2525
api_router.include_router(events.router, prefix="/events")
2626
api_router.include_router(lineage.router, prefix="/lineage")
2727
api_router.include_router(models.router, prefix="/models")
28-
api_router.include_router(context.router, prefix="/context")
28+
api_router.include_router(meta.router, prefix="/meta")
2929
api_router.include_router(table_diff.router, prefix="/table_diff")

web/server/api/endpoints/context.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)