Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/components/csvDownloader/csv-export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { useCallback } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { CsvExportProps } from './csv-export.type';
import { useCsvExport } from './use-csv-export';
import { ExportCsvButton } from './export-csv-button';

export function CsvExport({
studyUuid,
nodeUuid,
rootNetworkUuid,
columns,
tableNamePrefix = '',
tableName,
Expand All @@ -20,9 +23,34 @@ export function CsvExport({
exportDataAsCsv,
}: CsvExportProps): JSX.Element {
const { downloadCSVData } = useCsvExport();
const [isCsvExportLoading, setIsCsvExportLoading] = useState(false);
const [isCsvExportSuccessful, setIsCsvExportSuccessful] = useState(false);

useEffect(() => {
setIsCsvExportSuccessful(false);
}, [studyUuid, nodeUuid, rootNetworkUuid]);

useEffect(() => {
if (disabled) {
// reinit the success state when the button is disabled,
// for example when the calcul status change or results change
setIsCsvExportSuccessful(false);
}
}, [disabled]);

const download = useCallback(() => {
setIsCsvExportLoading(true);
downloadCSVData({ columns, tableName, tableNamePrefix, skipColumnHeaders, language, exportDataAsCsv });
setIsCsvExportLoading(false);
setIsCsvExportSuccessful(true);
}, [downloadCSVData, columns, tableName, tableNamePrefix, skipColumnHeaders, language, exportDataAsCsv]);

return <ExportCsvButton disabled={disabled} onClick={download} />;
return (
<ExportCsvButton
disabled={disabled}
onClick={download}
isDownloadLoading={isCsvExportLoading}
isDownloadSuccessful={isCsvExportSuccessful}
/>
);
}
4 changes: 4 additions & 0 deletions src/components/csvDownloader/csv-export.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { ColDef, CsvExportParams } from 'ag-grid-community';
import type { UUID } from 'crypto';
import { GsLang } from '../../utils';

export type CsvDownloadProps = {
Expand All @@ -18,5 +19,8 @@ export type CsvDownloadProps = {
};

export type CsvExportProps = CsvDownloadProps & {
studyUuid: UUID;
nodeUuid: UUID;
rootNetworkUuid: UUID;
disabled: boolean;
};
Loading