mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Drag&Drop: Dynamically load sheets module (#69536)
dynamically load sheets module
This commit is contained in:
parent
24502c4c4a
commit
e0ce6c3a94
@ -2,7 +2,6 @@ import { Accept } from 'react-dropzone';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { toDataFrame } from '@grafana/data';
|
||||
import { readSpreadsheet } from 'app/core/utils/sheet';
|
||||
|
||||
import { FileImportResult } from './types';
|
||||
|
||||
@ -27,6 +26,8 @@ export function formatFileTypes(acceptedFiles: Accept) {
|
||||
export function filesToDataframes(files: File[]): Observable<FileImportResult> {
|
||||
return new Observable<FileImportResult>((subscriber) => {
|
||||
let completedFiles = 0;
|
||||
import('app/core/utils/sheet')
|
||||
.then((sheet) => {
|
||||
files.forEach((file) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsArrayBuffer(file);
|
||||
@ -38,7 +39,7 @@ export function filesToDataframes(files: File[]): Observable<FileImportResult> {
|
||||
const json = JSON.parse(decoder.decode(result));
|
||||
subscriber.next({ dataFrames: [toDataFrame(json)], file: file });
|
||||
} else {
|
||||
subscriber.next({ dataFrames: readSpreadsheet(result), file: file });
|
||||
subscriber.next({ dataFrames: sheet.readSpreadsheet(result), file: file });
|
||||
}
|
||||
if (++completedFiles >= files.length) {
|
||||
subscriber.complete();
|
||||
@ -46,5 +47,9 @@ export function filesToDataframes(files: File[]): Observable<FileImportResult> {
|
||||
}
|
||||
};
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
throw 'Failed to load sheets module';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user