Skip to content

Commit

Permalink
Support TrackOptions for Export + remove runtime checks obsoleted by …
Browse files Browse the repository at this point in the history
…Typescript (#3870)
  • Loading branch information
lbwexler authored Dec 26, 2024
1 parent 4629590 commit 06078a2
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions svc/GridExportService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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', {}),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<TrackOptions>;

/** Timeout (in ms) for export request - defaults to 30 seconds. */
timeout?: number;
Expand Down

0 comments on commit 06078a2

Please sign in to comment.