Skip to content

An open source alternative to Tableau. Embeddable visual analytic

fix: csv file chartset

ObservedObserver32678047c2de
diff --git a/packages/graphic-walker/src/dataSource/dataSelection/config.ts b/packages/graphic-walker/src/dataSource/dataSelection/config.ts
new file mode 100644
index 00000000..55378afd
--- /dev/null
+++ b/packages/graphic-walker/src/dataSource/dataSelection/config.ts
@@ -0,0 +1,28 @@
+import { IDropdownSelectOption } from "../../components/dropdownSelect";
+
+export const charsetOptions: IDropdownSelectOption[] = [
+ {
+ label: 'UTF-8',
+ value: 'utf-8',
+ },
+ {
+ label: 'GB2312',
+ value: 'gb2312',
+ },
+ {
+ label: 'US-ASCII',
+ value: 'us-ascii',
+ },
+ {
+ label: 'Big5',
+ value: 'big5',
+ },
+ {
+ label: 'Big5-HKSCS',
+ value: 'Big5-HKSCS',
+ },
+ {
+ label: 'GB18030',
+ value: 'GB18030',
+ },
+]
\ No newline at end of file
diff --git a/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx b/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx
index b0228b98..fee801e1 100644
--- a/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx
+++ b/packages/graphic-walker/src/dataSource/dataSelection/csvData.tsx
@@ -1,4 +1,4 @@
-import React, { useRef, useCallback } from "react";
+import React, { useRef, useCallback, useState } from "react";
import { FileReader } from "@kanaries/web-data-loader";
import { IRow } from "../../interfaces";
import Table from "../table";
@@ -8,25 +8,51 @@ import { observer } from "mobx-react-lite";
import { useTranslation } from "react-i18next";
import DefaultButton from "../../components/button/default";
import PrimaryButton from "../../components/button/primary";
+import DropdownSelect from "../../components/dropdownSelect";
+import { charsetOptions } from "./config";
const Container = styled.div`
overflow-x: auto;
+ min-height: 300px;
`;
interface ICSVData {}
const CSVData: React.FC<ICSVData> = (props) => {
const fileRef = useRef<HTMLInputElement>(null);
const { commonStore } = useGlobalStore();
- const { tmpDSName, tmpDataSource } = commonStore;
+ const { tmpDSName, tmpDataSource, tmpDSRawFields } = commonStore;
+ const [encoding, setEncoding] = useState<string>("utf-8");
const onSubmitData = useCallback(() => {
commonStore.commitTempDS();
}, []);
const { t } = useTranslation("translation", { keyPrefix: "DataSource.dialog.file" });
+ const fileLoaded = tmpDataSource.length > 0 && tmpDSRawFields.length > 0;
return (
<Container>
+ {!fileLoaded && (
+ <div className="text-center">
+ <svg
+ className="mx-auto h-12 w-12 text-gray-400"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ vectorEffect="non-scaling-stroke"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth={2}
+ d="M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"
+ />
+ </svg>
+ <h3 className="mt-2 text-sm font-semibold text-gray-900">{t('choose_file')}</h3>
+ <p className="mt-1 text-sm text-gray-500">{t('get_start_desc')}</p>
+ </div>
+ )}
<input
style={{ display: "none" }}
type="file"
@@ -39,44 +65,61 @@ const CSVData: React.FC<ICSVData> = (props) => {
file,
config: { type: "reservoirSampling", size: Infinity },
onLoading: () => {},
+ encoding,
}).then((data) => {
commonStore.updateTempDS(data as IRow[]);
});
}
}}
/>
- <div className="my-1">
- <DefaultButton
- className="mr-2"
- onClick={() => {
- if (fileRef.current) {
- fileRef.current.click();
- }
- }}
- text={t("open")}
- />
- <PrimaryButton
- className="mr-2"
- text={t("submit")}
- disabled={tmpDataSource.length === 0}
- onClick={() => {
- onSubmitData();
- }}
- />
- </div>
- <div className="my-2">
- <label className="block text-xs text-gray-800 dark:text-gray-200 mb-1 font-bold">{t("dataset_name")}</label>
- <input
- type="text"
- placeholder={t("dataset_name")}
- value={tmpDSName}
- onChange={(e) => {
- commonStore.updateTempName(e.target.value);
- }}
- className="text-xs p-2 rounded border border-gray-200 dark:border-gray-800 outline-none focus:outline-none focus:border-blue-500 placeholder:italic placeholder:text-slate-400 dark:bg-stone-900"
- />
- </div>
- <Table />
+ {!fileLoaded && (
+ <div className="my-1 flex justify-center">
+ <DefaultButton
+ className="mr-2"
+ onClick={() => {
+ if (fileRef.current) {
+ fileRef.current.click();
+ }
+ }}
+ text={t("open")}
+ />
+ <div className="inline-block relative">
+ <DropdownSelect
+ buttonClassName="w-36"
+ options={charsetOptions}
+ selectedKey={encoding}
+ onSelect={(k) => {
+ setEncoding(k);
+ }}
+ />
+ </div>
+ </div>
+ )}
+ {fileLoaded && (
+ <div className="mb-2 mt-6">
+ <label className="block text-xs text-gray-800 dark:text-gray-200 mb-1 font-bold">
+ {t("dataset_name")}
+ </label>
+ <input
+ type="text"
+ placeholder={t("dataset_name")}
+ value={tmpDSName}
+ onChange={(e) => {
+ commonStore.updateTempName(e.target.value);
+ }}
+ className="text-xs mr-2 p-2 rounded border border-gray-200 dark:border-gray-800 outline-none focus:outline-none focus:border-blue-500 placeholder:italic placeholder:text-slate-400 dark:bg-stone-900"
+ />
+ <PrimaryButton
+ className="mr-2"
+ text={t("submit")}
+ disabled={tmpDataSource.length === 0}
+ onClick={() => {
+ onSubmitData();
+ }}
+ />
+ </div>
+ )}
+ {fileLoaded && <Table />}
</Container>
);
};
diff --git a/packages/graphic-walker/src/locales/en-US.json b/packages/graphic-walker/src/locales/en-US.json
index eb80f205..a555c263 100644
--- a/packages/graphic-walker/src/locales/en-US.json
+++ b/packages/graphic-walker/src/locales/en-US.json
@@ -105,7 +105,9 @@
"file": {
"open": "Open...",
"submit": "Submit",
- "dataset_name": "Dataset Name"
+ "dataset_name": "Dataset Name",
+ "choose_file": "Choose a Data File",
+ "get_start_desc": "Get started by creating a dataset."
},
"public": {
"submit": "Submit"
diff --git a/packages/graphic-walker/src/locales/zh-CN.json b/packages/graphic-walker/src/locales/zh-CN.json
index 4ba122dd..fb9e18d1 100644
--- a/packages/graphic-walker/src/locales/zh-CN.json
+++ b/packages/graphic-walker/src/locales/zh-CN.json
@@ -105,7 +105,9 @@
"file": {
"open": "打开文件...",
"submit": "确认",
- "dataset_name": "数据集名称"
+ "dataset_name": "数据集名称",
+ "choose_file": "选择文件",
+ "get_start_desc": "创建一个数据集以开始分析"
},
"public": {
"submit": "确认"