-
Notifications
You must be signed in to change notification settings - Fork 14
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
chore: refactor /database parallel rendering #255
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eb7c02d
chore: refactor /database parallel rendering
duyet a5c7df3
Merge branch 'main' of github.com:duyet/clickhouse-monitoring into fi…
duyet 9d6ff64
chore: rename `<Background />` to `<BackgroudJobs />`
duyet 9b4abfb
feat: engineType() add error handling
duyet 9711906
refactor: refactor `<ErrorAlert />`
duyet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ServerComponentLazy } from '@/components/server-component-lazy' | ||
import { engineType } from '../engine-type' | ||
import { Extras } from '../extras/extras' | ||
import { SampleData } from '../extras/sample-data' | ||
import { TableDDL } from '../extras/table-ddl' | ||
|
||
interface Props { | ||
params: { | ||
database: string | ||
table: string | ||
} | ||
} | ||
|
||
export default async function Dictionary({ | ||
params: { database, table }, | ||
}: Props) { | ||
const engine = await engineType(database, table) | ||
if (engine !== 'Dictionary') return <></> | ||
|
||
const dictUsage = `SELECT dictGet('${database}.${table}', 'key', 'value')` | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<Extras database={database} table={table} /> | ||
|
||
<div className="mt-6 w-fit overflow-auto"> | ||
<h2 className="mb-3 text-lg font-semibold">Dictionary usage</h2> | ||
<pre className="text-sm"> | ||
<code>{dictUsage}</code> | ||
</pre> | ||
</div> | ||
|
||
<div className="mt-3 w-fit overflow-auto"> | ||
<h2 className="mb-3 text-lg font-semibold">Dictionary DDL</h2> | ||
<TableDDL database={database} table={table} /> | ||
</div> | ||
|
||
<ServerComponentLazy> | ||
<div className="mt-6 w-fit overflow-auto"> | ||
<h2 className="mb-3 text-lg font-semibold">Sample Data</h2> | ||
<SampleData database={database} table={table} /> | ||
</div> | ||
</ServerComponentLazy> | ||
</div> | ||
) | ||
} |
34 changes: 34 additions & 0 deletions
34
app/database/[database]/[table]/@materializedview/materialized-view.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { engineType } from '../engine-type' | ||
import { Extras } from '../extras/extras' | ||
import { TableDDL } from '../extras/table-ddl' | ||
|
||
interface Props { | ||
params: { | ||
database: string | ||
table: string | ||
} | ||
} | ||
|
||
export default async function MaterializedView({ | ||
params: { database, table }, | ||
}: Props) { | ||
const engine = await engineType(database, table) | ||
if (engine !== 'MaterializedView') return <></> | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<Extras database={database} table={table} /> | ||
|
||
<div className="mt-3 w-fit overflow-auto"> | ||
<h2 className="mb-3 text-lg font-semibold"> | ||
MaterializedView:{' '} | ||
<code> | ||
{database}.{table} | ||
</code> | ||
</h2> | ||
|
||
<TableDDL database={database} table={table} /> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { TextAlignBottomIcon } from '@radix-ui/react-icons' | ||
import Link from 'next/link' | ||
|
||
import { DataTable } from '@/components/data-table/data-table' | ||
import { Button } from '@/components/ui/button' | ||
import { fetchDataWithCache } from '@/lib/clickhouse' | ||
import { Extras } from '../extras/extras' | ||
|
||
import { config, type Row } from '../config' | ||
import { engineType } from '../engine-type' | ||
|
||
interface Props { | ||
params: { | ||
database: string | ||
table: string | ||
} | ||
} | ||
|
||
export default async function MergeTree({ | ||
params: { database, table }, | ||
}: Props) { | ||
const engine = await engineType(database, table) | ||
if (engine.includes('MergeTree') === false) return <></> | ||
|
||
const columns = await fetchDataWithCache()<Row[]>({ | ||
query: config.sql, | ||
query_params: { | ||
database, | ||
table, | ||
}, | ||
}) | ||
|
||
let description = '' | ||
try { | ||
const raw = await fetchDataWithCache()<{ comment: string }[]>({ | ||
query: ` | ||
SELECT comment | ||
FROM system.tables | ||
WHERE (database = {database: String}) | ||
AND (name = {table: String}) | ||
`, | ||
query_params: { database, table }, | ||
}) | ||
|
||
description = raw?.[0]?.comment || '' | ||
} catch (e) { | ||
console.error('Error fetching table description', e) | ||
} | ||
|
||
return ( | ||
<DataTable | ||
title={`Table: ${database}.${table}`} | ||
description={description} | ||
toolbarExtras={<Extras database={database} table={table} />} | ||
topRightToolbarExtras={ | ||
<TopRightToolbarExtras database={database} table={table} /> | ||
} | ||
config={config} | ||
data={columns} | ||
/> | ||
) | ||
} | ||
|
||
const TopRightToolbarExtras = ({ | ||
database, | ||
table, | ||
}: { | ||
database: string | ||
table: string | ||
}) => ( | ||
<Link href={`/top-usage-columns?table=${database}.${table}`}> | ||
<Button | ||
variant="outline" | ||
className="flex flex-row gap-2 text-muted-foreground" | ||
> | ||
<TextAlignBottomIcon className="size-3" /> | ||
Top usage columns | ||
</Button> | ||
</Link> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { engineType } from '../engine-type' | ||
import { Extras } from '../extras/extras' | ||
import { TableDDL } from '../extras/table-ddl' | ||
|
||
interface Props { | ||
params: { | ||
database: string | ||
table: string | ||
} | ||
} | ||
|
||
export default async function View({ params: { database, table } }: Props) { | ||
const engine = await engineType(database, table) | ||
if (engine !== 'View') return <></> | ||
|
||
return ( | ||
<div className="flex flex-col"> | ||
<Extras database={database} table={table} /> | ||
|
||
<div className="mt-3 w-fit overflow-auto"> | ||
<h2 className="mb-3 text-lg font-semibold">View definition:</h2> | ||
|
||
<TableDDL database={database} table={table} /> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { fetchDataWithCache } from '@/lib/clickhouse' | ||
|
||
export const engineType = async (database: string, table: string) => { | ||
const resp = await fetchDataWithCache()<{ engine: string }[]>({ | ||
query: ` | ||
SELECT engine | ||
FROM system.tables | ||
WHERE (database = {database: String}) | ||
AND (name = {table: String}) | ||
`, | ||
query_params: { database, table }, | ||
}) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Error handling for fetchDataWithCache Consider adding error handling for the |
||
return resp?.[0]?.engine || '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ArrowLeftIcon } from '@radix-ui/react-icons' | ||
import Link from 'next/link' | ||
|
||
import { Button } from '@/components/ui/button' | ||
import { AlternativeTables } from './alternative-tables' | ||
import { RunningQueriesButton } from './runnning-queries-button' | ||
import { SampleDataButton } from './sample-data-button' | ||
import { ShowDDL } from './show-ddl-button' | ||
import { TableInfo } from './table-info' | ||
|
||
export const Extras = ({ | ||
database, | ||
table, | ||
}: { | ||
database: string | ||
table: string | ||
}) => ( | ||
<div className="mb-3 flex flex-row justify-between gap-3"> | ||
<div className="flex flex-row gap-3"> | ||
<Link href={`/database/${database}`}> | ||
<Button | ||
variant="outline" | ||
size="sm" | ||
className="flex flex-row gap-2 text-muted-foreground" | ||
> | ||
<ArrowLeftIcon className="size-3" /> | ||
Back to {database} | ||
</Button> | ||
</Link> | ||
<AlternativeTables database={database} table={table} /> | ||
</div> | ||
|
||
<div className="flex flex-row gap-3"> | ||
<ShowDDL database={database} table={table} /> | ||
<TableInfo database={database} table={table} /> | ||
<SampleDataButton database={database} table={table} /> | ||
<RunningQueriesButton database={database} table={table} /> | ||
</div> | ||
</div> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react' | ||
|
||
interface LayoutProps { | ||
children: React.ReactNode | ||
mergetree: React.ReactNode | ||
dictionary: React.ReactNode | ||
materializedview: React.ReactNode | ||
view: React.ReactNode | ||
} | ||
|
||
export default function Layout({ | ||
view, | ||
dictionary, | ||
materializedview, | ||
mergetree, | ||
}: LayoutProps) { | ||
return ( | ||
<div> | ||
{view} | ||
{dictionary} | ||
{materializedview} | ||
{mergetree} | ||
</div> | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Error handling for engineType
Consider adding error handling for the
engineType
function call to handle cases where the fetch might fail.