Skip to content

Commit d66e9dd

Browse files
committed
feat: custom error message for trying to export and empty datahub table
1 parent 2ce6d23 commit d66e9dd

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

apps/web/src/routes/_app/datahub/index.tsx

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { PageHeader } from '@/components/PageHeader';
2323
import { subjectsQueryOptions, useSubjectsQuery } from '@/hooks/useSubjectsQuery';
2424
import { useAppStore } from '@/store';
2525
import { downloadExcel } from '@/utils/excel';
26-
2726
type MasterDataTableProps = {
2827
data: Subject[];
2928
onSelect: (subject: Subject) => void;
@@ -93,21 +92,28 @@ const RouteComponent = () => {
9392

9493
const handleExportSelection = (option: 'CSV' | 'Excel' | 'JSON') => {
9594
const baseFilename = `${currentUser!.username}_${new Date().toISOString()}`;
96-
addNotification({
97-
message: t({
98-
en: 'Exporting entries, please wait...',
99-
fr: 'Téléchargement des entrées, veuillez patienter...'
100-
}),
101-
type: 'info'
102-
});
10395
getExportRecords()
10496
.then((data): any => {
10597
const listedSubjects = tableData.map((record) => {
106-
return record.id.replace(/^.*?\$/, '');
98+
return removeSubjectIdScope(record.id);
10799
});
108100

109101
const filteredData = data.filter((dataEntry) => listedSubjects.includes(dataEntry.subjectId));
110102

103+
if (filteredData.length < 1) {
104+
throw Error(
105+
t({ en: 'Export failed: No entries to export', fr: "Échec de l'exportation : aucune entrée à exporter" })
106+
);
107+
}
108+
109+
addNotification({
110+
message: t({
111+
en: 'Exporting entries, please wait...',
112+
fr: 'Téléchargement des entrées, veuillez patienter...'
113+
}),
114+
type: 'info'
115+
});
116+
111117
switch (option) {
112118
case 'CSV':
113119
void download('README.txt', t('datahub.index.table.exportHelpText'));
@@ -127,10 +133,17 @@ const RouteComponent = () => {
127133
})
128134
.catch((err) => {
129135
console.error(err);
130-
addNotification({
131-
message: t({ en: 'Export failed', fr: "Échec de l'exportation" }),
132-
type: 'error'
133-
});
136+
if (err instanceof Error && err.message) {
137+
addNotification({
138+
message: err.message,
139+
type: 'error'
140+
});
141+
} else {
142+
addNotification({
143+
message: t({ en: 'Export failed', fr: "Échec de l'exportation" }),
144+
type: 'error'
145+
});
146+
}
134147
});
135148
};
136149

@@ -154,10 +167,7 @@ const RouteComponent = () => {
154167
}
155168

156169
const filtered = data.filter((record) =>
157-
record.id
158-
.replace(/^.*?\$/, '')
159-
.toLowerCase()
160-
.includes(searchString.toLowerCase())
170+
removeSubjectIdScope(record.id).toLowerCase().includes(searchString.toLowerCase())
161171
);
162172

163173
setTableData(filtered);

0 commit comments

Comments
 (0)