Skip to content

Commit

Permalink
csv: fix preview of small csv
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcastro2 authored and slint committed Nov 20, 2023
1 parent 167998a commit 14842cd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Papa from "papaparse";
}

const URL = $("#app").attr("data-csv-source");
const fileSize = $("#app").attr("data-csv-size");
const maxRowsPerChunk = 50;
const $tableHeader = $("#table-header");
const $tableBody = $("#table-body");
Expand All @@ -33,6 +34,11 @@ import Papa from "papaparse";
papaParser.resume();
});

// If the RemoteChunkSize is bigger than the size of the file it fails with a 416
if (fileSize < Papa.RemoteChunkSize) {
Papa.RemoteChunkSize = fileSize
}

Papa.parse(URL, {
download: true,
skipEmptyLines: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Papa from "papaparse";
}

const URL = $("#app").attr("data-csv-source");
const fileSize = $("#app").attr("data-csv-size");
const maxRowsPerChunk = 50;
const $tableHeader = $("#table-header");
const $tableBody = $("#table-body");
Expand All @@ -33,6 +34,11 @@ import Papa from "papaparse";
papaParser.resume();
});

// If the RemoteChunkSize is bigger than the size of the file it fails with a 416
if (fileSize < Papa.RemoteChunkSize) {
Papa.RemoteChunkSize = fileSize
}

Papa.parse(URL, {
download: true,
skipEmptyLines: true,
Expand Down
2 changes: 1 addition & 1 deletion invenio_previewer/templates/invenio_previewer/csv_bar.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{%- extends config.PREVIEWER_ABSTRACT_TEMPLATE %}

{% block panel %}
<div id="app" data-csv-source="{{ file.uri }}">
<div id="app" data-csv-source="{{ file.uri }}" data-csv-size="{{file.size}}">
<table class="ui selectable celled table unstackable">
<thead id="table-header">
</thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{%- extends config.PREVIEWER_ABSTRACT_TEMPLATE %}

{% block panel %}
<div id="app" data-csv-source="{{ file.uri }}">
<div id="app" data-csv-source="{{ file.uri }}" data-csv-size="{{file.size}}">
<table class="ui selectable celled table unstackable">
<thead id="table-header">
</thead>
Expand Down

0 comments on commit 14842cd

Please sign in to comment.