Skip to content

Commit c766f28

Browse files
committed
feat: move export into dedicated menu action
1 parent 25cd1a4 commit c766f28

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

packages/viewer/src/EmbeddingAtlas.svelte

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,37 @@
373373
<div class="flex flex-none gap-2 items-center">
374374
<FilteredCount coordinator={coordinator} filter={crossFilter} table={data.table} />
375375
<div class="flex flex-row gap-1 items-center">
376-
<button
377-
class="flex px-2.5 mr-1 select-none items-center justify-center text-slate-500 dark:text-slate-300 rounded-full bg-white dark:bg-slate-900 border border-slate-300 dark:border-slate-600 focus-visible:outline-2 outline-blue-600 -outline-offset-1"
378-
onclick={resetFilter}
379-
title="Clear filters"
380-
>
381-
Clear
382-
</button>
376+
<Button label="Clear" title="Clear filters" onClick={resetFilter} />
377+
378+
{#if onExportSelection}
379+
<PopupButton label="Export" title="Export Selection">
380+
<div class="min-w-[420px] flex flex-col gap-2">
381+
<div class="flex flex-row gap-2">
382+
<ActionButton
383+
icon={IconExport}
384+
label="Export Selection"
385+
title="Export the selected points"
386+
class="w-48"
387+
onClick={() => onExportSelection(currentPredicate(), exportFormat)}
388+
/>
389+
<Select
390+
label="Format"
391+
value={exportFormat}
392+
onChange={(v) => (exportFormat = v)}
393+
options={[
394+
{ value: "parquet", label: "Parquet" },
395+
{ value: "jsonl", label: "JSONL" },
396+
{ value: "json", label: "JSON" },
397+
{ value: "csv", label: "CSV" },
398+
]}
399+
/>
400+
</div>
401+
</div>
402+
</PopupButton>
403+
{/if}
383404
</div>
384405
</div>
406+
385407
<div class="flex flex-none flex-row gap-2">
386408
<div class="grid grid-cols-1 grid-rows-1 justify-items-end items-center">
387409
{#key layout}
@@ -429,41 +451,17 @@
429451
}}
430452
/>
431453
{/if}
432-
<!-- Export -->
433-
{#if onExportSelection || onExportApplication}
454+
<!-- Export Application -->
455+
{#if onExportApplication}
434456
<h4 class="text-slate-500 dark:text-slate-400 select-none">Export</h4>
435457
<div class="flex flex-col gap-2">
436-
{#if onExportSelection}
437-
<div class="flex flex-row gap-2">
438-
<ActionButton
439-
icon={IconExport}
440-
label="Export Selection"
441-
title="Export the selected points"
442-
class="w-48"
443-
onClick={() => onExportSelection(currentPredicate(), exportFormat)}
444-
/>
445-
<Select
446-
label="Format"
447-
value={exportFormat}
448-
onChange={(v) => (exportFormat = v)}
449-
options={[
450-
{ value: "parquet", label: "Parquet" },
451-
{ value: "jsonl", label: "JSONL" },
452-
{ value: "json", label: "JSON" },
453-
{ value: "csv", label: "CSV" },
454-
]}
455-
/>
456-
</div>
457-
{/if}
458-
{#if onExportApplication}
459-
<ActionButton
460-
icon={IconDownload}
461-
label="Export Application"
462-
title="Download a self-contained static web application"
463-
class="w-48"
464-
onClick={onExportApplication}
465-
/>
466-
{/if}
458+
<ActionButton
459+
icon={IconDownload}
460+
label="Export Application"
461+
title="Download a self-contained static web application"
462+
class="w-48"
463+
onClick={onExportApplication}
464+
/>
467465
</div>
468466
{/if}
469467
<h4 class="text-slate-500 dark:text-slate-400 select-none">About</h4>

packages/viewer/src/app/Test.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
77
import type { EmbeddingAtlasProps } from "../api.js";
88
import { initializeDatabase } from "../utils/database.js";
9+
import { downloadBuffer } from "../utils/download";
10+
import { exportMosaicSelection, type ExportFormat } from "../utils/mosaic_exporter";
911
import type { DataSource } from "./data_source.js";
1012
1113
export class TestDataSource implements DataSource {
1214
private count: number;
1315
16+
downloadSelection: ((predicate: string | null, format: ExportFormat) => Promise<void>) | undefined = undefined;
17+
1418
constructor(count: number) {
1519
this.count = count;
1620
}
@@ -55,6 +59,11 @@
5559
UPDATE ${table} SET y = y + 5 * floor(floor(var_uniform * 24 + random()) / 5);
5660
`);
5761
62+
this.downloadSelection = async (predicate, format) => {
63+
let [bytes, name] = await exportMosaicSelection(coordinator, table, predicate, format);
64+
downloadBuffer(bytes, name);
65+
};
66+
5867
return {
5968
data: {
6069
table: table,

0 commit comments

Comments
 (0)