Skip to content
Merged
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
6 changes: 3 additions & 3 deletions frontend/src2/data_source/UploadCSVFileDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ function resetFile() {
<Dialog
v-model="show"
:options="{
title: csvData.tablename ? __('Import Table') : __('Upload CSV/Excel File'),
title: csvData.tablename ? __('Import Table') : __('Upload CSV/Excel/JSON File'),
size: fileUploaded ? '4xl' : '',
}"
>
<template #body-content>
<FileUploader
v-if="!fileUploaded"
:uploadArgs="{ private: true }"
:file-types="['.csv', '.xlsx']"
:file-types="['.csv', '.xlsx', '.json', '.jsonl']"
@success="uploadFile"
>
<template #default="{ progress, uploading, openFileSelector }">
Expand All @@ -116,7 +116,7 @@ function resetFile() {
/>
<div class="text-center">
<p v-if="!uploading" class="text-sm font-medium text-gray-800">
Select a CSV or Excel file to upload
Select a CSV, Excel, or JSON file to upload
</p>
<p v-if="!uploading" class="mt-1 text-xs text-gray-600">
or drag and drop it here
Expand Down
1 change: 1 addition & 0 deletions frontend/src2/query/components/QueryBuilderTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function addNewColumn() {
:enable-column-rename="true"
:enable-alerts="true"
:enable-new-column="true"
:enable-drill-down="true"
>
<template #header-prefix="{ column }">
<ColumnTypeChange
Expand Down
12 changes: 10 additions & 2 deletions insights/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def get_csv_file(filename: str):
extension = parts[-1] if parts else ""
extension = extension.lstrip(".")

if not extension or extension not in ["csv", "xlsx"]:
if not extension or extension not in ["csv", "xlsx", "json", "jsonl"]:
frappe.throw(
f"Only CSV and XLSX files are supported. Detected extension: '{extension}' from filename: '{file_name}'"
f"Only CSV, XLSX, JSON, and JSONL files are supported. Detected extension: '{extension}' from filename: '{file_name}'"
)
return file, extension

Expand Down Expand Up @@ -128,6 +128,8 @@ def get_file_data(filename: str):
try:
if ext in ["xlsx"]:
table = db.read_xlsx(file_path)
elif ext in ["json", "jsonl"]:
table = db.read_json(file_path)
else:
table = db.read_csv(file_path, table_name=file_name)

Expand Down Expand Up @@ -162,6 +164,8 @@ def import_csv_data(filename: str, tablename: str = ""):
try:
if ext in ["xlsx"]:
table = db.read_xlsx(file_path)
elif ext in ["json", "jsonl"]:
table = db.read_json(file_path)
else:
table = db.read_csv(file_path, table_name=table_name)
db.create_table(table_name, table, overwrite=True)
Expand All @@ -171,6 +175,10 @@ def import_csv_data(filename: str, tablename: str = ""):
frappe.throw(
"Failed to read Excel data from uploaded file. Please ensure the file is a valid Excel format and try again."
)
elif ext in ["json", "jsonl"]:
frappe.throw(
"Failed to read JSON data from uploaded file. Please ensure the file is a valid JSON or JSONL format and try again."
)
else:
frappe.throw("Failed to read CSV data from uploaded file. Please try again.")
finally:
Expand Down
Loading