Skip to content

Commit a0b2032

Browse files
committed
feat: use downloadSubjectTableExcel function and provide excel options in dl method
1 parent 2d93716 commit a0b2032

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

apps/web/src/hooks/useInstrumentVisualization.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useInstrument } from '@/hooks/useInstrument';
1111
import { useInstrumentInfoQuery } from '@/hooks/useInstrumentInfoQuery';
1212
import { useInstrumentRecords } from '@/hooks/useInstrumentRecords';
1313
import { useAppStore } from '@/store';
14+
import { downloadSubjectTableExcel } from '@/utils/excel';
1415

1516
type InstrumentVisualizationRecord = {
1617
[key: string]: unknown;
@@ -53,7 +54,7 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
5354
}
5455
});
5556

56-
const dl = (option: 'CSV' | 'CSV Long' | 'JSON' | 'TSV' | 'TSV Long') => {
57+
const dl = (option: 'CSV' | 'CSV Long' | 'Excel' | 'Excel Long' | 'JSON' | 'TSV' | 'TSV Long') => {
5758
if (!instrument) {
5859
notifications.addNotification({ message: t('errors.noInstrumentSelected'), type: 'error' });
5960
return;
@@ -157,6 +158,16 @@ export function useInstrumentVisualization({ params }: UseInstrumentVisualizatio
157158
});
158159
break;
159160
}
161+
case 'Excel': {
162+
const rows = makeWideRows();
163+
downloadSubjectTableExcel(`${baseFilename}.xlsx`, rows);
164+
break;
165+
}
166+
case 'Excel Long': {
167+
const rows = makeLongRows();
168+
downloadSubjectTableExcel(`${baseFilename}.xlsx`, rows);
169+
break;
170+
}
160171
case 'JSON': {
161172
exportRecords.map((item) => {
162173
item.subjectID = params.subjectId;

apps/web/src/routes/_app/datahub/$subjectId/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const RouteComponent = () => {
3838
widthFull
3939
data-spotlight-type="export-data-dropdown"
4040
disabled={!instrumentId}
41-
options={['TSV', 'TSV Long', 'JSON', 'CSV', 'CSV Long']}
41+
options={['TSV', 'TSV Long', 'JSON', 'CSV', 'CSV Long', 'Excel', 'Excel Long']}
4242
title={t('core.download')}
4343
triggerClassName="min-w-32"
4444
onSelection={dl}

0 commit comments

Comments
 (0)