From e9e6efa1fd2b1eb6b2b386b0246108debae7ff87 Mon Sep 17 00:00:00 2001 From: Daneryl Date: Fri, 11 Oct 2024 09:55:38 +0200 Subject: [PATCH] csv with dots on the header text now work properly --- app/api/csv/csv.ts | 2 +- app/api/csv/specs/csvLoader.spec.js | 1 + app/api/csv/specs/csvLoaderFixtures.ts | 5 +++++ app/api/csv/specs/test.csv | 8 ++++---- package.json | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/api/csv/csv.ts b/app/api/csv/csv.ts index 6e0662a1e5..64effd2dd7 100644 --- a/app/api/csv/csv.ts +++ b/app/api/csv/csv.ts @@ -58,7 +58,7 @@ const csv = (readStream: Readable, stopOnError = false) => ({ async read() { this.reading = true; - return csvtojson({ delimiter: DELIMITERS }) + return csvtojson({ delimiter: DELIMITERS, flatKeys: true }) .fromStream(readStream) .subscribe(async (row: CSVRow, index) => { if (!this.reading) { diff --git a/app/api/csv/specs/csvLoader.spec.js b/app/api/csv/specs/csvLoader.spec.js index c13d39f1d2..7742e94ce3 100644 --- a/app/api/csv/specs/csvLoader.spec.js +++ b/app/api/csv/specs/csvLoader.spec.js @@ -169,6 +169,7 @@ describe('csvLoader', () => { numeric_label: [{ value: 1977 }], select_label: [{ label: 'thesauri1', value: expect.any(String) }], text_label: [{ value: 'text value 1' }], + header_with_dots: [{ value: 'header with dots value 1' }], }); }); diff --git a/app/api/csv/specs/csvLoaderFixtures.ts b/app/api/csv/specs/csvLoaderFixtures.ts index 42242b8922..3cf4d2a95e 100644 --- a/app/api/csv/specs/csvLoaderFixtures.ts +++ b/app/api/csv/specs/csvLoaderFixtures.ts @@ -62,6 +62,11 @@ export default { label: 'text label', name: templateUtils.safeName('text label'), }, + { + type: propertyTypes.text, + label: 'header.with. dots', + name: templateUtils.safeName('header.with.dots'), + }, { type: propertyTypes.numeric, label: 'numeric label', diff --git a/app/api/csv/specs/test.csv b/app/api/csv/specs/test.csv index 59765b22f6..1ebae0ee4d 100644 --- a/app/api/csv/specs/test.csv +++ b/app/api/csv/specs/test.csv @@ -1,5 +1,5 @@ -Title , text label , numeric label, non configured, select_label, not defined type, geolocation_geolocation,auto id, additional tag(s), Multi Select Label, Date label, Language +Title , header.with.dots, text label , numeric label, non configured, select_label, not defined type, geolocation_geolocation,auto id, additional tag(s), Multi Select Label, Date label, Language -title1, text value 1, 1977, ______________, thesauri1 , notType1 , 1|1,,tag1, multivalue1,03/01/2022,English -title2, text value 2, 2019, ______________, thesauri2 , notType2 , ,,tag2, multivalue2,01/03/2022,Spanish -title3, text value 3, 2020, ______________, thesauri2 , notType3 , 0|0,,tag3, multivalue1|multivalue3,01/01/2022,AnyStringIsGood +title1, header with dots value 1, text value 1, 1977, ______________, thesauri1 , notType1 , 1|1,,tag1, multivalue1,03/01/2022,English +title2, header with dots value 2, text value 2, 2019, ______________, thesauri2 , notType2 , ,,tag2, multivalue2,01/03/2022,Spanish +title3, header with dots value 3, text value 3, 2020, ______________, thesauri2 , notType3 , 0|0,,tag3, multivalue1|multivalue3,01/01/2022,AnyStringIsGood diff --git a/package.json b/package.json index 3934d3fbad..ec87d864eb 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "hot-e2e": "DATABASE_NAME=uwazi_e2e INDEX_NAME=uwazi_e2e EXTERNAL_SERVICES=true yarn hot", "run-e2e": "DATABASE_NAME=uwazi_e2e INDEX_NAME=uwazi_e2e EXTERNAL_SERVICES=true yarn run-production", "hot-inspect": "export HOT=true; export BABEL_ENV=debug; yarn run watch-types & yarn dev-server --inspect & yarn run webpack-server", - "hot-debug": "export HOT=true; export BABEL_ENV=debug; node --no-experimental-fetch --inspect-brk=9229 server.js", + "hot-debug": "export HOT=true; export BABEL_ENV=debug; node --no-experimental-fetch --inspect-brk=9229 server.js & yarn run webpack-server", "reindex": "node scripts/run.js ../database/reindex_elastic.js", "import-csv": "node --no-experimental-fetch scripts/run.js ../database/import_csv.js", "blank-state": "node --no-experimental-fetch scripts/bash.js ./database/blank_state.sh",