Skip to content
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
6 changes: 6 additions & 0 deletions apps/admin/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {
MdAdminPanelSettings,
MdAccountTree,
MdCode,
MdOpenInNew,
MdPublic,
MdTableChart,
Expand All @@ -20,6 +21,7 @@ import {
DataCatalogPage,
LoginPage,
RecordCrossmatchDetailsPage,
SqlQueryPage,
TableDetailsPage,
TablesPage,
} from "./pages";
Expand Down Expand Up @@ -101,6 +103,9 @@ function Layout() {
<NavItem to="/data-catalog" label="Data catalog">
<MdAccountTree size={20} />
</NavItem>
<NavItem to="/sql" label="SQL">
<MdCode size={20} />
</NavItem>
<NavItem to="/tasks" label="Tasks">
<MdAdminPanelSettings size={20} />
</NavItem>
Expand All @@ -125,6 +130,7 @@ function App() {
<Route path="/tasks" element={<AdminPage />} />
<Route path="/merge-pgc" element={<AdminMergePgcPage />} />
<Route path="/tables" element={<TablesPage />} />
<Route path="/sql" element={<SqlQueryPage />} />
<Route path="/data-catalog" element={<DataCatalogPage />} />
<Route path="/data-catalog/query" element={<DataCatalogPage />} />
<Route
Expand Down
2 changes: 1 addition & 1 deletion apps/admin/src/pages/DataCatalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { useDataFetching } from "@hyperleda/lib/hooks";
import { Button } from "@hyperleda/lib/ui";
import classNames from "classnames";
import { CatalogViewTabs } from "./catalog/CatalogViewTabs";
import { CatalogSqlPanel } from "./catalog/CatalogSqlPanel";
import { CatalogSqlPanel } from "@hyperleda/lib/ui";
import {
DEFAULT_SQL_EXAMPLE,
defaultSelectForTable,
Expand Down
58 changes: 58 additions & 0 deletions apps/admin/src/pages/SqlQuery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { ReactElement, useEffect, useLayoutEffect, useState } from "react";
import { useSearchParams } from "react-router-dom";
import type { TapSyncResponse } from "@hyperleda/lib/clients/backend";
import { tapSync } from "../clients/admin";
import { adminClient } from "../clients";
import {
DEFAULT_SQL_EXAMPLE,
formatApiError,
parseSqlPermalink,
} from "@hyperleda/lib/tap";
import { CatalogSqlPanel } from "@hyperleda/lib/ui";

async function executeAdminSqlQuery(sql: string): Promise<TapSyncResponse> {
const response = await tapSync({
client: adminClient,
query: { query: sql },
});
if (response.error) {
throw new Error(formatApiError(response.error));
}
if (!response.data?.data) {
throw new Error("No data received from server");
}
return response.data.data;
}

export function SqlQueryPage(): ReactElement {
const [searchParams, setSearchParams] = useSearchParams();
const permalinkSql = searchParams.get("q");
const [sqlDraft, setSqlDraft] = useState(DEFAULT_SQL_EXAMPLE);

useEffect(() => {
document.title = "SQL | HyperLEDA";
}, []);

useLayoutEffect(() => {
if (!permalinkSql) {
return;
}
setSqlDraft(parseSqlPermalink(permalinkSql));
}, [permalinkSql]);

function handleQueryRun(sql: string): void {
setSearchParams({ q: sql }, { replace: true });
}

return (
<div className="p-8">
<CatalogSqlPanel
sql={sqlDraft}
onSqlChange={setSqlDraft}
permalinkRunKey={permalinkSql ? parseSqlPermalink(permalinkSql) : null}
onQueryRun={handleQueryRun}
executeQuery={executeAdminSqlQuery}
/>
</div>
);
}
1 change: 1 addition & 0 deletions apps/admin/src/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { SqlQueryPage } from "./SqlQuery";
export { AdminPage } from "./Admin";
export { AdminMergePgcPage } from "./AdminMergePgc";
export { CrossmatchResultsPage } from "./CrossmatchResults";
Expand Down
2 changes: 2 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
},
"dependencies": {
"@hyperleda/lib": "*",
"@monaco-editor/react": "^4.7.0",
"@tailwindcss/typography": "^0.5.20",
"@tailwindcss/vite": "^4.3.3",
"axios": "^1.19.0",
"classnames": "^2.5.1",
"flowbite-react": "^0.12.17",
"monaco-editor": "^0.56.0",
"react": "^19.2.8",
"react-dom": "^19.2.8",
"react-icons": "^5.7.0",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HomePage } from "./pages/Home";
import { SearchResultsPage } from "./pages/SearchResults";
import { ObjectDetailsPage } from "./pages/ObjectDetails";
import { NotFoundPage } from "./pages/NotFound";
import { SqlQueryPage } from "./pages/SqlQuery";
import { Navbar } from "./components/ui/Navbar";
import { SearchBar } from "./components/ui/Searchbar";

Expand Down Expand Up @@ -53,6 +54,7 @@ function App() {
}
/>
<Route path="/query" element={<SearchResultsPage />} />
<Route path="/sql" element={<SqlQueryPage />} />
<Route
path="/object/:pgcId"
element={
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/ui/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useEffect, useMemo, useRef, useState } from "react";
import { MdInfo, MdOpenInNew, MdSearch } from "react-icons/md";
import { MdCode, MdInfo, MdOpenInNew, MdSearch } from "react-icons/md";
import { NavRail, NavButton, NavItem, ThemeSwitcher } from "@hyperleda/lib/ui";
import { Link } from "@hyperleda/lib/ui";

const navItems = [
{ to: "/", icon: <MdSearch size={20} />, label: "Object search", end: true },
{ to: "/sql", icon: <MdCode size={20} />, label: "SQL", end: true },
];

const configuredProductionWeb = "https://leda.sao.ru";
Expand Down
36 changes: 36 additions & 0 deletions apps/web/src/pages/SqlQuery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ReactElement, useEffect, useLayoutEffect, useState } from "react";
import { useSearchParams } from "react-router-dom";
import { CatalogSqlPanel } from "@hyperleda/lib/ui";
import { DEFAULT_SQL_EXAMPLE, parseSqlPermalink } from "@hyperleda/lib/tap";

export function SqlQueryPage(): ReactElement {
const [searchParams, setSearchParams] = useSearchParams();
const permalinkSql = searchParams.get("q");
const [sqlDraft, setSqlDraft] = useState(DEFAULT_SQL_EXAMPLE);

useEffect(() => {
document.title = "SQL | HyperLEDA";
}, []);

useLayoutEffect(() => {
if (!permalinkSql) {
return;
}
setSqlDraft(parseSqlPermalink(permalinkSql));
}, [permalinkSql]);

function handleQueryRun(sql: string): void {
setSearchParams({ q: sql }, { replace: true });
}

return (
<div className="p-8">
<CatalogSqlPanel
sql={sqlDraft}
onSqlChange={setSqlDraft}
permalinkRunKey={permalinkSql ? parseSqlPermalink(permalinkSql) : null}
onQueryRun={handleQueryRun}
/>
</div>
);
}
4 changes: 4 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"react-markdown": "^10.1.0"
},
"peerDependencies": {
"@monaco-editor/react": "^4.7.0",
"monaco-editor": "^0.56.0",
"react": "^19.2.8",
"react-dom": "^19.2.8",
"react-icons": "^5.7.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { FormEvent, ReactElement, useEffect, useRef, useState } from "react";
import { useLocation } from "react-router-dom";
import type { TapSchemaEntry } from "@hyperleda/lib/clients/backend";
import { Button, Text } from "@hyperleda/lib/ui";
import type {
TapSchemaEntry,
TapSyncResponse,
} from "@hyperleda/lib/clients/backend";
import { Button } from "./Button";
import { SqlEditor } from "./SqlEditor";
import { SqlQueryEmbed } from "@hyperleda/lib/ui";
import { SqlQueryEmbed } from "./SqlQueryEmbed";
import { Text } from "./Text";

function runQueryShortcutLabel(): string {
if (typeof navigator === "undefined") {
Expand All @@ -18,6 +22,7 @@ interface CatalogSqlPanelProps {
schemas?: TapSchemaEntry[];
permalinkRunKey?: string | null;
onQueryRun?: (sql: string) => void;
executeQuery?: (sql: string) => Promise<TapSyncResponse>;
}

export function CatalogSqlPanel({
Expand All @@ -26,6 +31,7 @@ export function CatalogSqlPanel({
schemas,
permalinkRunKey,
onQueryRun,
executeQuery,
}: CatalogSqlPanelProps): ReactElement {
const [executedSql, setExecutedSql] = useState<string | null>(null);
const [runId, setRunId] = useState(0);
Expand Down Expand Up @@ -112,6 +118,7 @@ export function CatalogSqlPanel({
key={runId}
sql={executedSql}
onLoadingChange={setLoading}
executeQuery={executeQuery}
/>
) : null}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ReactElement, useEffect, useMemo, useRef, useState } from "react";
import Editor from "@monaco-editor/react";
import type * as Monaco from "monaco-editor";
import type { TapSchemaEntry } from "@hyperleda/lib/clients/backend";
import { useTheme } from "@hyperleda/lib/ui";
import { useTheme } from "./useTheme";

type CatalogCompletionTemplate = Omit<Monaco.languages.CompletionItem, "range">;

Expand Down
6 changes: 4 additions & 2 deletions packages/lib/src/ui/SqlQueryEmbed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ function markdownColumns(columns: Column[]): Column[] {
export function SqlQueryEmbed({
sql,
onLoadingChange,
executeQuery = executeSqlQuery,
}: {
sql: string;
onLoadingChange?: (loading: boolean) => void;
executeQuery?: (sql: string) => Promise<TapSyncResponse>;
}): ReactElement {
const [result, setResult] = useState<TapSyncResponse | null>(null);
const [loading, setLoading] = useState(true);
Expand All @@ -50,7 +52,7 @@ export function SqlQueryEmbed({
setResult(null);

try {
const payload = await executeSqlQuery(sql);
const payload = await executeQuery(sql);
if (!cancelled) {
setResult(payload);
}
Expand All @@ -69,7 +71,7 @@ export function SqlQueryEmbed({
return () => {
cancelled = true;
};
}, [sql]);
}, [sql, executeQuery]);

const tableData = result ? syncPayloadToTable(result) : null;
const rowCount = tableData?.rows.length ?? 0;
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ export { Loading } from "./Loading";
export { Text, type TextStyle, type TextSize, type TextType } from "./Text";
export { Markdown } from "./Markdown";
export { SqlQueryEmbed } from "./SqlQueryEmbed";
export { CatalogSqlPanel } from "./CatalogSqlPanel";
Loading