Refactor table state, start adding history support, update packages
All checks were successful
build / build (push) Successful in 5m0s
All checks were successful
build / build (push) Successful in 5m0s
This commit is contained in:
10520
package-lock.json
generated
Normal file
10520
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,7 @@
|
|||||||
"@angular/compiler-cli": "^21.2.4",
|
"@angular/compiler-cli": "^21.2.4",
|
||||||
"@tauri-apps/cli": "^2.10.1",
|
"@tauri-apps/cli": "^2.10.1",
|
||||||
"@types/jasmine": "~5.1.15",
|
"@types/jasmine": "~5.1.15",
|
||||||
|
"baseline-browser-mapping": "^2.10.24",
|
||||||
"jasmine-core": "~5.12.1",
|
"jasmine-core": "~5.12.1",
|
||||||
"karma": "~6.4.4",
|
"karma": "~6.4.4",
|
||||||
"karma-chrome-launcher": "~3.2.0",
|
"karma-chrome-launcher": "~3.2.0",
|
||||||
|
|||||||
@@ -16,7 +16,9 @@
|
|||||||
>
|
>
|
||||||
<ng-template #panel>
|
<ng-template #panel>
|
||||||
<div class="h-full w-full overflow-auto">
|
<div class="h-full w-full overflow-auto">
|
||||||
<app-file-tree (selectFile)="selectedFile.set($event)"></app-file-tree>
|
<app-file-tree
|
||||||
|
(selectFile)="selectedSheet.set({ file: $event, history: [] })"
|
||||||
|
></app-file-tree>
|
||||||
</div>
|
</div>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template #panel>
|
<ng-template #panel>
|
||||||
@@ -31,12 +33,12 @@
|
|||||||
[class.border-dashed]="dragging()"
|
[class.border-dashed]="dragging()"
|
||||||
[class.border-2]="dragging()"
|
[class.border-2]="dragging()"
|
||||||
>
|
>
|
||||||
@if (tabs().length > 0) {
|
@if (sheets().length > 0) {
|
||||||
<p-tabs [(value)]="selectedTab" class="w-full" scrollable>
|
<p-tabs [(value)]="selectedTab" class="w-full" scrollable>
|
||||||
<p-tablist>
|
<p-tablist>
|
||||||
@for (tab of tabs(); track $index) {
|
@for (tab of sheets(); track $index) {
|
||||||
<p-tab [value]="$index" (auxclick)="removeTab($index)">
|
<p-tab [value]="$index" (auxclick)="removeTab($index)">
|
||||||
<span>{{ tab.name }}</span>
|
<span>{{ tab.file.name }}</span>
|
||||||
<span
|
<span
|
||||||
(click)="removeTab($index)"
|
(click)="removeTab($index)"
|
||||||
class="material-symbols-outlined"
|
class="material-symbols-outlined"
|
||||||
@@ -48,10 +50,10 @@
|
|||||||
</p-tablist>
|
</p-tablist>
|
||||||
</p-tabs>
|
</p-tabs>
|
||||||
}
|
}
|
||||||
@if (selectedFile()) {
|
@if (selectedSheet()) {
|
||||||
<app-file-viewer
|
<app-file-viewer
|
||||||
class="flex w-full flex-1"
|
class="flex w-full flex-1"
|
||||||
[file]="selectedFile()"
|
[sheet]="selectedSheet()"
|
||||||
[(columns)]="selectedFileColumns"
|
[(columns)]="selectedFileColumns"
|
||||||
></app-file-viewer>
|
></app-file-viewer>
|
||||||
} @else {
|
} @else {
|
||||||
@@ -67,13 +69,21 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template #panel>
|
<ng-template #panel>
|
||||||
<div class="col flex items-center justify-center">
|
<div class="col flex items-center justify-center">
|
||||||
Panel 3
|
@let selectedSheet = this.selectedSheet();
|
||||||
</div></ng-template
|
@if (selectedSheet) {
|
||||||
>
|
@for (state of selectedSheet.history; track $index) {
|
||||||
|
<!-- TODO: Make a diff compared to the initial state. -->
|
||||||
|
<!-- Alternative is to make state a list of patches, but probably more complicated -->
|
||||||
|
<div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}</div
|
||||||
|
></ng-template>
|
||||||
</p-splitter>
|
</p-splitter>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template #panel>
|
<ng-template #panel>
|
||||||
@if (selectedFile()) {
|
@if (selectedSheet()) {
|
||||||
<app-column-editor
|
<app-column-editor
|
||||||
class="w-full overflow-auto"
|
class="w-full overflow-auto"
|
||||||
[(columns)]="selectedFileColumns"
|
[(columns)]="selectedFileColumns"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
Component,
|
Component,
|
||||||
ElementRef,
|
ElementRef,
|
||||||
|
HostListener,
|
||||||
effect,
|
effect,
|
||||||
signal,
|
signal,
|
||||||
viewChild,
|
viewChild,
|
||||||
@@ -16,7 +17,7 @@ import { InputTextModule } from 'primeng/inputtext';
|
|||||||
import { FileTreeComponent } from './file-tree/file-tree.component';
|
import { FileTreeComponent } from './file-tree/file-tree.component';
|
||||||
import { FileViewerComponent } from './file-viewer/file-viewer.component';
|
import { FileViewerComponent } from './file-viewer/file-viewer.component';
|
||||||
import { ColumnEditorComponent } from './column-editor/column-editor.component';
|
import { ColumnEditorComponent } from './column-editor/column-editor.component';
|
||||||
import { Column } from './duckdb.service';
|
import { Column, Sheet } from './duckdb.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
@@ -37,9 +38,9 @@ import { Column } from './duckdb.service';
|
|||||||
styleUrl: './app.component.scss',
|
styleUrl: './app.component.scss',
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
protected selectedFile = signal<File | undefined>(undefined);
|
protected selectedSheet = signal<Sheet | undefined>(undefined);
|
||||||
protected selectedFileColumns = signal<Column[]>([]);
|
protected selectedFileColumns = signal<Column[]>([]);
|
||||||
protected tabs = signal<File[]>([]);
|
protected sheets = signal<Sheet[]>([]);
|
||||||
protected selectedTab = signal(0);
|
protected selectedTab = signal(0);
|
||||||
protected dragging = signal(false);
|
protected dragging = signal(false);
|
||||||
|
|
||||||
@@ -47,25 +48,25 @@ export class AppComponent {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
effect(() => {
|
effect(() => {
|
||||||
const selectedFile = this.selectedFile();
|
const selectedFile = this.selectedSheet();
|
||||||
if (selectedFile) {
|
if (selectedFile) {
|
||||||
this.addFile(selectedFile);
|
this.addSheet(selectedFile);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
effect(() => {
|
effect(() => {
|
||||||
if (this.selectedFile() !== this.tabs()[this.selectedTab()]) {
|
if (this.selectedSheet() !== this.sheets()[this.selectedTab()]) {
|
||||||
if (this.tabs().length > 0) {
|
if (this.sheets().length > 0) {
|
||||||
this.selectedFile.set(this.tabs()[Number(this.selectedTab())]);
|
this.selectedSheet.set(this.sheets()[Number(this.selectedTab())]);
|
||||||
} else {
|
} else {
|
||||||
this.selectedFile.set(undefined);
|
this.selectedSheet.set(undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected removeTab(index: number) {
|
protected removeTab(index: number) {
|
||||||
this.tabs.update((tabs) => {
|
this.sheets.update((tabs) => {
|
||||||
const copy = tabs.slice();
|
const copy = tabs.slice();
|
||||||
copy.splice(index, 1);
|
copy.splice(index, 1);
|
||||||
return copy;
|
return copy;
|
||||||
@@ -73,12 +74,12 @@ export class AppComponent {
|
|||||||
if (this.selectedTab() === index) {
|
if (this.selectedTab() === index) {
|
||||||
if (this.selectedTab() > 0) {
|
if (this.selectedTab() > 0) {
|
||||||
this.selectedTab.update((tab) => tab - 1);
|
this.selectedTab.update((tab) => tab - 1);
|
||||||
this.selectedFile.set(this.tabs()[this.selectedTab()]);
|
this.selectedSheet.set(this.sheets()[this.selectedTab()]);
|
||||||
} else if (this.tabs().length > 1) {
|
} else if (this.sheets().length > 1) {
|
||||||
this.selectedTab.update((tab) => tab + 1);
|
this.selectedTab.update((tab) => tab + 1);
|
||||||
this.selectedFile.set(this.tabs()[this.selectedTab()]);
|
this.selectedSheet.set(this.sheets()[this.selectedTab()]);
|
||||||
} else {
|
} else {
|
||||||
this.selectedFile.set(undefined);
|
this.selectedSheet.set(undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +90,7 @@ export class AppComponent {
|
|||||||
if (files) {
|
if (files) {
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (file.type === 'text/csv') {
|
if (file.type === 'text/csv') {
|
||||||
this.addFile(file);
|
this.addSheet({ file, history: [] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,31 +120,43 @@ export class AppComponent {
|
|||||||
if (files) {
|
if (files) {
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
if (file.type === 'text/csv') {
|
if (file.type === 'text/csv') {
|
||||||
this.addFile(file);
|
this.addSheet({ file, history: [] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.selectedTab.set(this.tabs().length - 1);
|
this.selectedTab.set(this.sheets().length - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private addFile(file: File) {
|
private addSheet(newSheet: Sheet) {
|
||||||
if (
|
if (
|
||||||
this.tabs().find(
|
this.sheets().find(
|
||||||
(tab) =>
|
(sheet) =>
|
||||||
tab.webkitRelativePath === file.webkitRelativePath &&
|
sheet.file.webkitRelativePath === newSheet.file.webkitRelativePath &&
|
||||||
tab.name === file.name,
|
sheet.file.name === newSheet.file.name,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
this.selectedTab.set(
|
this.selectedTab.set(
|
||||||
this.tabs().findIndex(
|
this.sheets().findIndex(
|
||||||
(tab) =>
|
(sheet) =>
|
||||||
tab.webkitRelativePath === file.webkitRelativePath &&
|
sheet.file.webkitRelativePath ===
|
||||||
tab.name === file.name,
|
newSheet.file.webkitRelativePath &&
|
||||||
|
sheet.file.name === newSheet.file.name,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.tabs.update((tabs) => [...tabs, file]);
|
this.sheets.update((tabs) => [...tabs, newSheet]);
|
||||||
this.selectedTab.set(this.tabs().length - 1);
|
this.selectedTab.set(this.sheets().length - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@HostListener('window:keydown', [
|
||||||
|
'$event.key',
|
||||||
|
'$event.ctrlKey',
|
||||||
|
'$event.metaKey',
|
||||||
|
])
|
||||||
|
keydown(key: string, hasCtrl: boolean, hasMeta: boolean) {
|
||||||
|
const sheets = this.sheets();
|
||||||
|
if (sheets.length > 1 && key === 'z' && (hasCtrl || hasMeta)) {
|
||||||
|
this.sheets()[0].history.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,18 @@ export const RowsResponse = z.object({
|
|||||||
aggregateValues: AggregateValue.array(),
|
aggregateValues: AggregateValue.array(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const TableState = z.object({
|
||||||
|
columns: z.array(Column),
|
||||||
|
sorts: z.array(SortColumn),
|
||||||
|
filters: z.array(Filter),
|
||||||
|
aggregates: z.array(Aggregate)
|
||||||
|
});
|
||||||
|
|
||||||
|
export const Sheet = z.object({
|
||||||
|
file: z.file(),
|
||||||
|
history: z.array(TableState),
|
||||||
|
})
|
||||||
|
|
||||||
export type Column = z.infer<typeof Column>;
|
export type Column = z.infer<typeof Column>;
|
||||||
export type SortColumn = z.infer<typeof SortColumn>;
|
export type SortColumn = z.infer<typeof SortColumn>;
|
||||||
export type FilterValue = z.infer<typeof FilterValue>;
|
export type FilterValue = z.infer<typeof FilterValue>;
|
||||||
@@ -57,6 +69,8 @@ export type AggregateType = z.infer<typeof AggregateType>;
|
|||||||
export type Aggregate = z.infer<typeof Aggregate>;
|
export type Aggregate = z.infer<typeof Aggregate>;
|
||||||
export type AggregateValue = z.infer<typeof AggregateValue>;
|
export type AggregateValue = z.infer<typeof AggregateValue>;
|
||||||
export type RowsResponse = z.infer<typeof RowsResponse>;
|
export type RowsResponse = z.infer<typeof RowsResponse>;
|
||||||
|
export type TableState = z.infer<typeof TableState>;
|
||||||
|
export type Sheet = z.infer<typeof Sheet>;
|
||||||
|
|
||||||
const sanitisedFileName = (file: File) =>
|
const sanitisedFileName = (file: File) =>
|
||||||
file.name.toLowerCase().replaceAll("'", '').replaceAll(/\s*/g, '');
|
file.name.toLowerCase().replaceAll("'", '').replaceAll(/\s*/g, '');
|
||||||
@@ -176,15 +190,12 @@ export class DuckdbService {
|
|||||||
file: File,
|
file: File,
|
||||||
start: number,
|
start: number,
|
||||||
numRows: number,
|
numRows: number,
|
||||||
columns: Column[],
|
state: TableState,
|
||||||
sorts: SortColumn[],
|
|
||||||
filters: Filter[],
|
|
||||||
aggregates: Aggregate[],
|
|
||||||
): Promise<RowsResponse> {
|
): Promise<RowsResponse> {
|
||||||
const conn = await this.db.connect();
|
const conn = await this.db.connect();
|
||||||
try {
|
try {
|
||||||
const whereClause = this.getWhereClause(filters);
|
const whereClause = this.getWhereClause(state.filters);
|
||||||
const mappedFilterValues = filters.flatMap((filter) =>
|
const mappedFilterValues = state.filters.flatMap((filter) =>
|
||||||
filter.value
|
filter.value
|
||||||
.filter((value) => value?.value)
|
.filter((value) => value?.value)
|
||||||
.map(
|
.map(
|
||||||
@@ -193,8 +204,8 @@ export class DuckdbService {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
let aggregatesQuery = 'SELECT COUNT(1) totalRows';
|
let aggregatesQuery = 'SELECT COUNT(1) totalRows';
|
||||||
if (aggregates.length > 0) {
|
if (state.aggregates.length > 0) {
|
||||||
for (const aggregate of aggregates) {
|
for (const aggregate of state.aggregates) {
|
||||||
aggregatesQuery += `, ${aggregate.type}("${aggregate.column}") "${aggregate.column}"`;
|
aggregatesQuery += `, ${aggregate.type}("${aggregate.column}") "${aggregate.column}"`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,9 +217,9 @@ export class DuckdbService {
|
|||||||
const aggregateValues: AggregateValue[] = Object.entries(aggregatesJson)
|
const aggregateValues: AggregateValue[] = Object.entries(aggregatesJson)
|
||||||
.filter(([key]) => key !== 'totalRows')
|
.filter(([key]) => key !== 'totalRows')
|
||||||
.map(([key, value]) => AggregateValue.parse({ column: key, value }));
|
.map(([key, value]) => AggregateValue.parse({ column: key, value }));
|
||||||
let query = `SELECT ${columns.map((column) => `"${column.name}"`).join(', ')} FROM ${sanitisedFileName(file)} ${whereClause}`;
|
let query = `SELECT ${state.columns.map((column) => `"${column.name}"`).join(', ')} FROM ${sanitisedFileName(file)} ${whereClause}`;
|
||||||
if (sorts.length > 0) {
|
if (state.sorts.length > 0) {
|
||||||
query += ` ORDER BY ${sorts.map((sort) => `"${sort.name}" ${sort.sortType}`).join(', ')}`;
|
query += ` ORDER BY ${state.sorts.map((sort) => `"${sort.name}" ${sort.sortType}`).join(', ')}`;
|
||||||
}
|
}
|
||||||
query += ` LIMIT ${numRows} OFFSET ${start}`;
|
query += ` LIMIT ${numRows} OFFSET ${start}`;
|
||||||
const stmt = await conn.prepare(query);
|
const stmt = await conn.prepare(query);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
DuckdbService,
|
DuckdbService,
|
||||||
Filter,
|
Filter,
|
||||||
FilterValue,
|
FilterValue,
|
||||||
|
Sheet,
|
||||||
aggregateTypes,
|
aggregateTypes,
|
||||||
} from '../duckdb.service';
|
} from '../duckdb.service';
|
||||||
import { ButtonModule } from 'primeng/button';
|
import { ButtonModule } from 'primeng/button';
|
||||||
@@ -44,7 +45,7 @@ import { PaginatorModule, PaginatorState } from 'primeng/paginator';
|
|||||||
PaginatorModule,
|
PaginatorModule,
|
||||||
],
|
],
|
||||||
template: `
|
template: `
|
||||||
@if (file() && enabledColumns().length > 0) {
|
@if (sheet() && enabledColumns().length > 0) {
|
||||||
<div class="h-full">
|
<div class="h-full">
|
||||||
<p-table
|
<p-table
|
||||||
#table
|
#table
|
||||||
@@ -170,37 +171,37 @@ import { PaginatorModule, PaginatorState } from 'primeng/paginator';
|
|||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
})
|
})
|
||||||
export class FileViewerComponent {
|
export class FileViewerComponent {
|
||||||
file = input<File | undefined>();
|
sheet = input<Sheet | undefined>();
|
||||||
|
|
||||||
private duckdbService = inject(DuckdbService);
|
private duckdbService = inject(DuckdbService);
|
||||||
|
|
||||||
// Can't be computed since effect has to run first so file exists in duckdb
|
// Can't be computed since effect has to run first so file exists in duckdb
|
||||||
columns = model<Column[]>([]);
|
columns = model<Column[]>([]);
|
||||||
protected aggregates = signal<(Aggregate | undefined)[]>([]);
|
protected readonly aggregates = signal<(Aggregate | undefined)[]>([]);
|
||||||
protected currentAggregateColumn = signal<number | undefined>(undefined);
|
protected readonly currentAggregateColumn = signal<number | undefined>(undefined);
|
||||||
protected aggregateValues = signal<(number | undefined)[]>([]);
|
protected readonly aggregateValues = signal<(number | undefined)[]>([]);
|
||||||
protected readonly NUM_ROWS = 200;
|
protected readonly NUM_ROWS = 200;
|
||||||
protected currentPage = signal(0);
|
protected readonly currentPage = signal(0);
|
||||||
|
|
||||||
// This is required since once the number of rows exceeds ~300000, the footer gets blocked
|
// This is required since once the number of rows exceeds ~300000, the footer gets blocked
|
||||||
// and the user can't even scroll to those bottom rows.
|
// and the user can't even scroll to those bottom rows.
|
||||||
protected readonly PAGE_SIZE = 300_000;
|
protected readonly PAGE_SIZE = 300_000;
|
||||||
|
|
||||||
protected currentValue = signal<any[]>([]);
|
protected readonly currentValue = signal<any[]>([]);
|
||||||
protected appliedFilters = signal<Filter[]>([]);
|
protected readonly appliedFilters = signal<Filter[]>([]);
|
||||||
protected currentRowCount = signal(0n);
|
protected readonly currentRowCount = signal(0n);
|
||||||
|
|
||||||
private table = viewChild(Table);
|
private readonly table = viewChild(Table);
|
||||||
|
|
||||||
protected hasAggregates = computed(
|
protected readonly hasAggregates = computed(
|
||||||
() => !!this.columns().find((col) => this.isAggregateColumn(col)),
|
() => !!this.columns().find((col) => this.isAggregateColumn(col)),
|
||||||
);
|
);
|
||||||
|
|
||||||
protected enabledColumns = computed(() =>
|
protected readonly enabledColumns = computed(() =>
|
||||||
this.columns().filter((col) => col.enabled),
|
this.columns().filter((col) => col.enabled),
|
||||||
);
|
);
|
||||||
|
|
||||||
protected aggregateItems: MenuItem[] = aggregateTypes.map((type) => ({
|
protected readonly aggregateItems: MenuItem[] = aggregateTypes.map((type) => ({
|
||||||
label: type,
|
label: type,
|
||||||
command: () => this.updateAggregateValue(type),
|
command: () => this.updateAggregateValue(type),
|
||||||
}));
|
}));
|
||||||
@@ -218,8 +219,8 @@ export class FileViewerComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected async onLazyLoad(event: TableLazyLoadEvent) {
|
protected async onLazyLoad(event: TableLazyLoadEvent) {
|
||||||
const file = this.file();
|
const sheet = this.sheet();
|
||||||
if (file) {
|
if (sheet) {
|
||||||
this.appliedFilters.set(
|
this.appliedFilters.set(
|
||||||
event.filters
|
event.filters
|
||||||
? Object.entries(event.filters).flatMap(([column, filter]) => {
|
? Object.entries(event.filters).flatMap(([column, filter]) => {
|
||||||
@@ -254,16 +255,20 @@ export class FileViewerComponent {
|
|||||||
: [],
|
: [],
|
||||||
);
|
);
|
||||||
const rows = await this.duckdbService.getRows(
|
const rows = await this.duckdbService.getRows(
|
||||||
file,
|
sheet.file,
|
||||||
(event.first ?? 0) + this.currentPage() * this.PAGE_SIZE,
|
(event.first ?? 0) + this.currentPage() * this.PAGE_SIZE,
|
||||||
event.rows ?? 0,
|
event.rows ?? 0,
|
||||||
this.columns(),
|
{
|
||||||
event.multiSortMeta?.map((meta) => ({
|
columns: this.columns(),
|
||||||
name: meta.field,
|
// TODO: We should be maintaining sorts separately so we can store them
|
||||||
sortType: meta.order < 0 ? 'desc' : 'asc',
|
sorts:
|
||||||
})) ?? [],
|
event.multiSortMeta?.map((meta) => ({
|
||||||
this.appliedFilters(),
|
name: meta.field,
|
||||||
this.aggregates().filter((agg) => !!agg) as Aggregate[],
|
sortType: meta.order < 0 ? 'desc' : 'asc',
|
||||||
|
})) ?? [],
|
||||||
|
filters: this.appliedFilters(),
|
||||||
|
aggregates: this.aggregates().filter((agg) => !!agg) as Aggregate[],
|
||||||
|
},
|
||||||
);
|
);
|
||||||
// First clear out existing data, don't want to risk loading entire file into memory
|
// First clear out existing data, don't want to risk loading entire file into memory
|
||||||
// Keep data in previous/next page so when user scrolls between 2 pages they don't see missing data
|
// Keep data in previous/next page so when user scrolls between 2 pages they don't see missing data
|
||||||
@@ -285,20 +290,18 @@ export class FileViewerComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async loadEmpty() {
|
private async loadEmpty() {
|
||||||
const file = this.file();
|
// TODO: Add to history, if the history is empty. If not empty, then load from that history
|
||||||
if (file) {
|
const sheet = this.sheet();
|
||||||
await this.duckdbService.addFile(file);
|
if (sheet) {
|
||||||
this.columns.set(await this.duckdbService.getColumns(file));
|
await this.duckdbService.addFile(sheet.file);
|
||||||
|
this.columns.set(await this.duckdbService.getColumns(sheet.file));
|
||||||
this.aggregates.set(new Array(this.columns().length));
|
this.aggregates.set(new Array(this.columns().length));
|
||||||
const rows = await this.duckdbService.getRows(
|
const rows = await this.duckdbService.getRows(sheet.file, 0, this.NUM_ROWS, {
|
||||||
file,
|
columns: this.columns(),
|
||||||
0,
|
sorts: [],
|
||||||
this.NUM_ROWS,
|
filters: [],
|
||||||
this.columns(),
|
aggregates: [],
|
||||||
[],
|
});
|
||||||
[],
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
this.currentRowCount.set(rows.totalRows);
|
this.currentRowCount.set(rows.totalRows);
|
||||||
this.currentPage.set(0);
|
this.currentPage.set(0);
|
||||||
const newValue = Array.from({
|
const newValue = Array.from({
|
||||||
@@ -318,6 +321,7 @@ export class FileViewerComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async updateAggregateValue(type: AggregateType) {
|
private async updateAggregateValue(type: AggregateType) {
|
||||||
|
// Update history
|
||||||
this.aggregates.update((aggregates) => {
|
this.aggregates.update((aggregates) => {
|
||||||
const copy = aggregates.slice();
|
const copy = aggregates.slice();
|
||||||
copy[this.currentAggregateColumn()!] = {
|
copy[this.currentAggregateColumn()!] = {
|
||||||
@@ -327,8 +331,9 @@ export class FileViewerComponent {
|
|||||||
return copy;
|
return copy;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const aggregateValue = await this.duckdbService.getAggregateValue(
|
const aggregateValue = await this.duckdbService.getAggregateValue(
|
||||||
this.file()!,
|
this.sheet()!.file,
|
||||||
this.appliedFilters(),
|
this.appliedFilters(),
|
||||||
this.aggregates()[this.currentAggregateColumn()!]!,
|
this.aggregates()[this.currentAggregateColumn()!]!,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user