Skip to content

Commit 6cf107a

Browse files
committed
fix: explicit file name for catalog contributions
1 parent 680186f commit 6cf107a

7 files changed

Lines changed: 34 additions & 15 deletions

File tree

packages/core/src/commands/wget.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ registerAll({
6464
return;
6565
}
6666

67-
const defaultFileName = fileNameFromUrl(url);
67+
const explicitName =
68+
typeof context.params?.filename === "string" ? context.params.filename.trim() : "";
69+
const defaultFileName = explicitName || fileNameFromUrl(url);
6870
let savePath: string;
6971
const targetPath = context.params?.targetPath;
7072

packages/extension-catalog/src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export {
22
getCatalogBaseUrl,
33
registerCatalog,
44
} from "./register-catalog";
5-
export type { CatalogContribution } from "./register-catalog";
5+
export type { CatalogContribution, CatalogResourceState } from "./register-catalog";

packages/extension-catalog/src/lyra-catalog.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,22 @@ export class LyraCatalog extends LyraPart {
9393
});
9494
}
9595

96+
private wgetParamsFromCatalogData(data: { url?: string; filename?: string }) {
97+
if (!data?.url) return null;
98+
const params: { url: string; filename?: string } = { url: data.url };
99+
if (typeof data.filename === "string" && data.filename.trim()) {
100+
params.filename = data.filename.trim();
101+
}
102+
return params;
103+
}
104+
96105
onItemDblClicked(event: Event) {
97106
const item = event.currentTarget as HTMLElement & { model?: TreeNode; expanded?: boolean };
98107
const node = item?.model;
99108
if (!node) return;
100-
if (node.data?.url) {
101-
this.executeCommand("wget", { url: node.data.url });
109+
const wgetParams = this.wgetParamsFromCatalogData(node.data);
110+
if (wgetParams) {
111+
this.executeCommand("wget", wgetParams);
102112
return;
103113
}
104114
if (!node.leaf && "expanded" in item) {
@@ -108,8 +118,9 @@ export class LyraCatalog extends LyraPart {
108118

109119
private runWgetForSelection() {
110120
const item = activeSelectionSignal.get();
111-
if (item && "url" in item && item.url) {
112-
this.executeCommand("wget", { url: item.url });
121+
const wgetParams = item && this.wgetParamsFromCatalogData(item as { url?: string; filename?: string });
122+
if (wgetParams) {
123+
this.executeCommand("wget", wgetParams);
113124
}
114125
}
115126

packages/extension-catalog/src/register-catalog.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import {
33
type TreeContribution,
44
} from "@eclipse-lyra/core";
55

6+
/** Leaf item state: optional filename when URL is not path-shaped (e.g. data: in production bundles). */
7+
export type CatalogResourceState = {
8+
url: string;
9+
filename?: string;
10+
};
11+
612
export interface CatalogContribution extends TreeContribution {
713
items?: CatalogContribution[];
814
}

packages/extension-duckdb/src/duckdb-catalog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ const DUCKDB_CATALOG: CatalogContribution = {
1111
icon: "file-lines",
1212
contributionId: "catalog.duckdb.basics",
1313
items: [
14-
{ label: "Hello DuckDB", icon: "file-code", state: { url: new URL("./catalog/hello-duckdb.sql", import.meta.url).href } },
15-
{ label: "Aggregations and filters", icon: "file-code", state: { url: new URL("./catalog/aggregations.sql", import.meta.url).href } },
14+
{ label: "Hello DuckDB", icon: "file-code", state: { url: new URL("./catalog/hello-duckdb.sql", import.meta.url).href, filename: "hello-duckdb.sql" } },
15+
{ label: "Aggregations and filters", icon: "file-code", state: { url: new URL("./catalog/aggregations.sql", import.meta.url).href, filename: "aggregations.sql" } },
1616
],
1717
},
1818
{
1919
label: "Data types & functions",
2020
icon: "file-lines",
2121
contributionId: "catalog.duckdb.types",
2222
items: [
23-
{ label: "Types and built-in functions", icon: "file-code", state: { url: new URL("./catalog/types-and-functions.sql", import.meta.url).href } },
23+
{ label: "Types and built-in functions", icon: "file-code", state: { url: new URL("./catalog/types-and-functions.sql", import.meta.url).href, filename: "types-and-functions.sql" } },
2424
],
2525
},
2626
],

packages/extension-notebook/src/notebook-catalog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ const NOTEBOOK_CATALOG: CatalogContribution = {
1111
icon: "file-code",
1212
contributionId: "catalog.notebooks.javascript",
1313
items: [
14-
{ label: "JavaScript basics", icon: "lyra jupyter", state: { url: new URL("./catalog/javascript-basics.ipynb", import.meta.url).href } },
14+
{ label: "JavaScript basics", icon: "lyra jupyter", state: { url: new URL("./catalog/javascript-basics.ipynb", import.meta.url).href, filename: "javascript-basics.ipynb" } },
1515
],
1616
},
1717
{
1818
label: "DuckDB",
1919
icon: "file-code",
2020
contributionId: "catalog.notebooks.duckdb",
2121
items: [
22-
{ label: "DuckDB in notebooks", icon: "lyra jupyter", state: { url: new URL("./catalog/duckdb-sample.ipynb", import.meta.url).href } },
22+
{ label: "DuckDB in notebooks", icon: "lyra jupyter", state: { url: new URL("./catalog/duckdb-sample.ipynb", import.meta.url).href, filename: "duckdb-sample.ipynb" } },
2323
],
2424
},
2525
{
2626
label: "PGlite",
2727
icon: "file-code",
2828
contributionId: "catalog.notebooks.pglite",
2929
items: [
30-
{ label: "PostgreSQL in notebooks", icon: "lyra jupyter", state: { url: new URL("./catalog/pglite-sample.ipynb", import.meta.url).href } },
30+
{ label: "PostgreSQL in notebooks", icon: "lyra jupyter", state: { url: new URL("./catalog/pglite-sample.ipynb", import.meta.url).href, filename: "pglite-sample.ipynb" } },
3131
],
3232
},
3333
],

packages/extension-pglite/src/pglite-catalog.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ const PGLITE_CATALOG: CatalogContribution = {
1111
icon: "file-lines",
1212
contributionId: "catalog.pglite.basics",
1313
items: [
14-
{ label: "Hello PostgreSQL", icon: "file-code", state: { url: new URL("./catalog/hello-pglite.sql", import.meta.url).href } },
15-
{ label: "Tables and constraints", icon: "file-code", state: { url: new URL("./catalog/tables-and-constraints.sql", import.meta.url).href } },
14+
{ label: "Hello PostgreSQL", icon: "file-code", state: { url: new URL("./catalog/hello-pglite.sql", import.meta.url).href, filename: "hello-pglite.sql" } },
15+
{ label: "Tables and constraints", icon: "file-code", state: { url: new URL("./catalog/tables-and-constraints.sql", import.meta.url).href, filename: "tables-and-constraints.sql" } },
1616
],
1717
},
1818
{
1919
label: "Queries",
2020
icon: "file-lines",
2121
contributionId: "catalog.pglite.queries",
2222
items: [
23-
{ label: "Joins and subqueries", icon: "file-code", state: { url: new URL("./catalog/joins-and-subqueries.sql", import.meta.url).href } },
23+
{ label: "Joins and subqueries", icon: "file-code", state: { url: new URL("./catalog/joins-and-subqueries.sql", import.meta.url).href, filename: "joins-and-subqueries.sql" } },
2424
],
2525
},
2626
],

0 commit comments

Comments
 (0)