From 06078a28a34c54819c3a2042e23c53e87141193b Mon Sep 17 00:00:00 2001 From: Lee Wexler Date: Thu, 26 Dec 2024 13:00:48 -0500 Subject: [PATCH] Support TrackOptions for Export + remove runtime checks obsoleted by Typescript (#3870) --- svc/GridExportService.ts | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/svc/GridExportService.ts b/svc/GridExportService.ts index 4ad9d3f3d..3bca55412 100644 --- a/svc/GridExportService.ts +++ b/svc/GridExportService.ts @@ -5,17 +5,16 @@ * Copyright © 2024 Extremely Heavy Industries Inc. */ import {ExcelFormat} from '@xh/hoist/cmp/grid'; -import {HoistService, XH} from '@xh/hoist/core'; +import {HoistService, TrackOptions, XH} from '@xh/hoist/core'; import {fmtDate} from '@xh/hoist/format'; import {Icon} from '@xh/hoist/icon'; import {isLocalDate, SECONDS} from '@xh/hoist/utils/datetime'; -import {throwIf, withDefault} from '@xh/hoist/utils/js'; +import {withDefault} from '@xh/hoist/utils/js'; import download from 'downloadjs'; import {StatusCodes} from 'http-status-codes'; import { castArray, countBy, - isArray, isEmpty, isFunction, isNil, @@ -56,21 +55,6 @@ export class GridExportService extends HoistService { timeout = 30 * SECONDS }: ExportOptions = {} ) { - throwIf(!gridModel, 'GridModel required for export'); - throwIf( - !isString(filename) && !isFunction(filename), - 'Export filename must be either a string or a closure' - ); - throwIf( - !['excel', 'excelTable', 'csv'].includes(type), - `Invalid export type "${type}". Must be either "excel", "excelTable" or "csv"` - ); - throwIf( - !(isFunction(columns) || isArray(columns) || ['ALL', 'VISIBLE'].includes(columns)), - 'Invalid columns config - must be "ALL", "VISIBLE", an array of colIds, or a function' - ); - throwIf(!isBoolean(track), 'Invalid track value - must be either true or false'); - if (isFunction(filename)) filename = filename(gridModel); const config = XH.configService.get('xhExportConfig', {}), @@ -153,11 +137,13 @@ export class GridExportService extends HoistService { XH.successToast('Export complete.'); if (track) { + const trackOpts = track !== true ? track : null; XH.track({ category: 'Export', message: `Downloaded ${filename}${fileExt}`, data: {rows: rows.length, columns: exportColumns.length}, - logData: true + logData: true, + ...trackOpts }); } } catch (e) { @@ -460,7 +446,7 @@ export interface ExportOptions { columns?: 'VISIBLE' | 'ALL' | string[] | ((g: GridModel) => string[]); /** True to enable activity tracking of exports (default false). */ - track?: boolean; + track?: boolean | Partial; /** Timeout (in ms) for export request - defaults to 30 seconds. */ timeout?: number;