diff --git a/app/plugin/TableOperations.ts b/app/plugin/TableOperations.ts index 3deb4eb5..9ca64d09 100644 --- a/app/plugin/TableOperations.ts +++ b/app/plugin/TableOperations.ts @@ -18,8 +18,7 @@ export interface TableOperations { /** * Delete a record or records. */ - destroy(recordId: Types.RecordId): Promise; - destroy(recordIds: Types.RecordId[]): Promise; + destroy(recordIds: Types.RecordId|Types.RecordId[]): Promise; /** * Add or update a record or records. diff --git a/app/plugin/TableOperationsImpl.ts b/app/plugin/TableOperationsImpl.ts index e569a73c..214a5a89 100644 --- a/app/plugin/TableOperationsImpl.ts +++ b/app/plugin/TableOperationsImpl.ts @@ -67,15 +67,12 @@ export class TableOperationsImpl implements TableOperations { }); } - public destroy(recordId: Types.RecordId): Promise; - public destroy(recordIds: Types.RecordId[]): Promise; - public async destroy(recordIdOrRecordIds: Types.RecordId|Types.RecordId[]): Promise { - return withRecords(recordIdOrRecordIds, async (recordIds) => { + public async destroy(recordIdOrRecordIds: Types.RecordId|Types.RecordId[]): Promise { + await withRecords(recordIdOrRecordIds, async (recordIds) => { const tableId = await this._platform.getTableId(); const actions = [['BulkRemoveRecord', tableId, recordIds]]; - const sandboxRes = await this._applyUserActions( - tableId, [], actions); - return sandboxRes.retValues[0]; + await this._applyUserActions(tableId, [], actions); + return []; }); } diff --git a/app/plugin/grist-plugin-api.ts b/app/plugin/grist-plugin-api.ts index dd17c180..d52c662d 100644 --- a/app/plugin/grist-plugin-api.ts +++ b/app/plugin/grist-plugin-api.ts @@ -216,13 +216,13 @@ async function getMappingsIfChanged(data: any): Promise { * Returns null if not all required columns were mapped or not widget doesn't support * custom column mapping. */ -export function mapColumnNames(data: any, options: { +export function mapColumnNames(data: any, options?: { columns?: ColumnsToMap mappings?: WidgetColumnMap|null, reverse?: boolean, }) { options = {columns: _columnsToMap, mappings: _mappingsCache, reverse: false, ...options}; - // If not column configuration was requested or + // If no column configuration was requested or // table has no rows, return original data. if (!options.columns) { return data; @@ -246,8 +246,8 @@ export function mapColumnNames(data: any, options: { function isOptional(col: string) { return Boolean( // Columns passed as strings are required. - !options.columns?.includes(col) - && options.columns?.find(c => typeof c === 'object' && c?.name === col && c.optional) + !options!.columns?.includes(col) + && options!.columns?.find(c => typeof c === 'object' && c?.name === col && c.optional) ); } // For each widget column in mapping. @@ -292,7 +292,7 @@ export function mapColumnNames(data: any, options: { * original table in a widget with column mappings. As for mapColumnNames(), * we don't attempt to do these transformations automatically. */ -export function mapColumnNamesBack(data: any, options: { +export function mapColumnNamesBack(data: any, options?: { columns?: ColumnsToMap mappings?: WidgetColumnMap|null, }) { @@ -320,10 +320,10 @@ export function onRecord(callback: (data: RowRecord | null, mappings: WidgetColu * For custom widgets, add a handler that will be called whenever the * new (blank) row is selected. */ -export function onNewRecord(callback: () => unknown) { +export function onNewRecord(callback: (mappings: WidgetColumnMap | null) => unknown) { on('message', async function(msg) { if (msg.tableId && msg.rowId === 'new') { - callback(); + callback(await getMappingsIfChanged(msg)); } }); } diff --git a/app/server/lib/DocApi.ts b/app/server/lib/DocApi.ts index c7d6b44f..3b5b0492 100644 --- a/app/server/lib/DocApi.ts +++ b/app/server/lib/DocApi.ts @@ -298,7 +298,8 @@ export class DocWorkerApi { this._app.post('/api/docs/:docId/tables/:tableId/data/delete', canEdit, withDoc(async (activeDoc, req, res) => { const rowIds = req.body; const op = getTableOperations(req, activeDoc); - res.json(await op.destroy(rowIds)); + await op.destroy(rowIds); + res.json(null); })); // Download full document