(core) Add TSV and DSV import/export

Summary: Adds support for importing .dsv files (an April Fools 2024 easter egg), and options for exporting .dsv and .tsv files from the Share menu.

Test Plan: Browser and server tests.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D4210
This commit is contained in:
George Gevoian
2024-03-20 09:58:24 -04:00
parent 48a8af83fc
commit 07fcce548b
15 changed files with 2672 additions and 45 deletions

View File

@@ -92,8 +92,13 @@ export interface TransformColumn {
widgetOptions: string;
}
export interface ImportParseOptions extends ParseOptions {
delimiter?: string;
encoding?: string;
}
export interface ImportResult {
options: ParseOptions;
options: ImportParseOptions;
tables: ImportTableResult[];
}
@@ -106,7 +111,7 @@ export interface ImportTableResult {
}
export interface ImportOptions {
parseOptions?: ParseOptions; // Options for parsing the source file.
parseOptions?: ImportParseOptions; // Options for parsing the source file.
mergeOptionMaps?: MergeOptionsMap[]; // Options for merging fields, indexed by uploadFileIndex.
}
@@ -328,7 +333,7 @@ export interface ActiveDocAPI {
* Imports files, removes previously created temporary hidden tables and creates the new ones.
*/
importFiles(dataSource: DataSourceTransformed,
parseOptions: ParseOptions, prevTableIds: string[]): Promise<ImportResult>;
parseOptions: ImportParseOptions, prevTableIds: string[]): Promise<ImportResult>;
/**
* Finishes import files, creates the new tables, and cleans up temporary hidden tables and uploads.

View File

@@ -470,6 +470,8 @@ export interface DocAPI {
getDownloadUrl(options: {template: boolean, removeHistory: boolean}): string;
getDownloadXlsxUrl(params?: DownloadDocParams): string;
getDownloadCsvUrl(params: DownloadDocParams): string;
getDownloadTsvUrl(params: DownloadDocParams): string;
getDownloadDsvUrl(params: DownloadDocParams): string;
getDownloadTableSchemaUrl(params: DownloadDocParams): string;
/**
* Exports current document to the Google Drive as a spreadsheet file. To invoke this method, first
@@ -1057,6 +1059,14 @@ export class DocAPIImpl extends BaseAPI implements DocAPI {
return this._url + '/download/csv?' + encodeQueryParams({...params});
}
public getDownloadTsvUrl(params: DownloadDocParams) {
return this._url + '/download/tsv?' + encodeQueryParams({...params});
}
public getDownloadDsvUrl(params: DownloadDocParams) {
return this._url + '/download/dsv?' + encodeQueryParams({...params});
}
public getDownloadTableSchemaUrl(params: DownloadDocParams) {
// We spread `params` to work around TypeScript being overly cautious.
return this._url + '/download/table-schema?' + encodeQueryParams({...params});