feat(import): support comma decimal separator for CSV/TSV
This commit is contained in:
15 files changed
+184
-6
No files matched your search
@@ -135,6 +135,7 @@ const errorMessage = ref("");
|
||||
const wizardStep = ref<TableImportWizardStep>("source");
|
||||
const fileInput = ref<HTMLInputElement | null>(null);
|
||||
const delimiter = ref(",");
|
||||
const decimalSeparator = ref<"." | ",">(".");
|
||||
const textEncoding = ref<api.TableImportTextEncoding>("auto");
|
||||
const titleRow = ref(1);
|
||||
const dataStartRow = ref(2);
|
||||
@@ -397,6 +398,7 @@ function resetState() {
|
||||
activeTaskIndex.value = 0;
|
||||
sourceFormat.value = "csv";
|
||||
delimiter.value = ",";
|
||||
decimalSeparator.value = ".";
|
||||
textEncoding.value = "auto";
|
||||
titleRow.value = 1;
|
||||
dataStartRow.value = 2;
|
||||
@@ -465,6 +467,7 @@ function taskParseOptions(format: api.TableImportSourceFormat, sheetName = ""):
|
||||
return buildTableImportParseOptions({
|
||||
format,
|
||||
delimiter: delimiter.value,
|
||||
decimalSeparator: decimalSeparator.value,
|
||||
textEncoding: textEncoding.value,
|
||||
titleRow: titleRow.value,
|
||||
dataStartRow: dataStartRow.value,
|
||||
@@ -1223,7 +1226,7 @@ watch(
|
||||
onBeforeUnmount(stopDialogDrag);
|
||||
|
||||
watch([sourceFormat, delimiter, titleRow, dataStartRow, lastDataRow, trimValues, emptyStringAsNull, selectedSheet, jsonShape, previewLimit], schedulePreviewReload);
|
||||
watch(textEncoding, schedulePreviewReloadAfterEncodingChange);
|
||||
watch([textEncoding, decimalSeparator], schedulePreviewReloadAfterEncodingChange);
|
||||
watch([newTableName, columnMapping, columnDataTypes], saveActiveBatchTask, { deep: true });
|
||||
watch(wizardStep, (step) => {
|
||||
if (step !== "mapping") closeDataTypePicker();
|
||||
@@ -1434,7 +1437,7 @@ watch(rawProgressPercent, (percent) => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="sourceFormat === 'csv' || sourceFormat === 'tsv' || sourceFormat === 'delimited'" class="grid grid-cols-5 gap-3 rounded-md border p-3">
|
||||
<div v-if="sourceFormat === 'csv' || sourceFormat === 'tsv' || sourceFormat === 'delimited'" class="grid grid-cols-2 gap-3 rounded-md border p-3 md:grid-cols-3 xl:grid-cols-6">
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-xs">{{ t("tableImport.encoding") }}</Label>
|
||||
<Select :model-value="textEncoding" @update:model-value="(value: any) => (textEncoding = value)">
|
||||
@@ -1455,6 +1458,18 @@ watch(rawProgressPercent, (percent) => {
|
||||
<Label class="text-xs">{{ t("tableImport.delimiter") }}</Label>
|
||||
<Input v-model="delimiter" :disabled="sourceFormat !== 'delimited'" class="h-8 text-xs font-mono" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-xs">{{ t("tableImport.decimalSeparator") }}</Label>
|
||||
<Select v-model="decimalSeparator">
|
||||
<SelectTrigger class="h-8 text-xs font-mono" :aria-label="t('tableImport.decimalSeparator')">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value=".">.</SelectItem>
|
||||
<SelectItem value=",">,</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label class="text-xs">{{ t("tableImport.titleRow") }}</Label>
|
||||
<Input v-model.number="titleRow" type="number" min="0" class="h-8 text-xs" />
|
||||
|
||||
+40
-3
@@ -113,16 +113,29 @@ vi.mock("@/components/ui/label", async () => {
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/select", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
const { defineComponent, h, inject, provide } = await import("vue");
|
||||
const passthrough = defineComponent({
|
||||
setup(_props, { slots }) {
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
});
|
||||
return {
|
||||
Select: passthrough,
|
||||
Select: defineComponent({
|
||||
props: { modelValue: String },
|
||||
emits: ["update:modelValue"],
|
||||
setup(_props, { emit, slots }) {
|
||||
provide("selectOption", (value: string) => emit("update:modelValue", value));
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
}),
|
||||
SelectContent: passthrough,
|
||||
SelectItem: passthrough,
|
||||
SelectItem: defineComponent({
|
||||
props: { value: String },
|
||||
setup(props, { slots }) {
|
||||
const selectOption = inject<(value: string) => void>("selectOption");
|
||||
return () => h("span", { "data-select-option": props.value, onClick: () => selectOption?.(props.value || "") }, slots.default?.());
|
||||
},
|
||||
}),
|
||||
SelectTrigger: passthrough,
|
||||
SelectValue: passthrough,
|
||||
};
|
||||
@@ -279,6 +292,30 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("TableImportDialog batch selection", () => {
|
||||
it("reloads a single CSV preview and passes the selected decimal separator to import", async () => {
|
||||
mocks.previewTableImportFile.mockImplementation(() => Promise.resolve(delimitedPreview()));
|
||||
await mountDialog([new File(['amount,note\n"12,50",plain'], "rows.csv")]);
|
||||
expect(mocks.previewTableImportFile.mock.calls.at(-1)?.[1].parseOptions.decimalSeparator).toBe(".");
|
||||
|
||||
document.body.querySelector<HTMLElement>('[data-select-option=","]')!.click();
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
await flushAsyncUpdates();
|
||||
expect(mocks.previewTableImportFile.mock.calls.at(-1)?.[1].parseOptions.decimalSeparator).toBe(",");
|
||||
|
||||
await startImport();
|
||||
expect(mocks.importTableFile.mock.calls[0]![0].parseOptions?.decimalSeparator).toBe(",");
|
||||
});
|
||||
|
||||
it("reloads selected batch CSV previews when the decimal separator changes", async () => {
|
||||
mocks.previewTableImportFile.mockImplementation(() => Promise.resolve(delimitedPreview()));
|
||||
await mountDialog([new File(["id,name"], "first.csv"), new File(["id,name"], "second.csv")]);
|
||||
mocks.previewTableImportFile.mockClear();
|
||||
document.body.querySelector<HTMLElement>('[data-select-option=","]')!.click();
|
||||
await flushAsyncUpdates();
|
||||
expect(mocks.previewTableImportFile).toHaveBeenCalledTimes(2);
|
||||
expect(mocks.previewTableImportFile.mock.calls.map(([, options]) => options.parseOptions.decimalSeparator)).toEqual([",", ","]);
|
||||
});
|
||||
|
||||
it("uses all desktop grid columns when Parquet is unavailable", async () => {
|
||||
await mountSourceDialog();
|
||||
|
||||
|
||||
Reference in new issue
Block a user