Skip to content

Commit

Permalink
fix: render problem (#655)
Browse files Browse the repository at this point in the history
* fix: render problem

* mod: code review
  • Loading branch information
hetao92 authored Oct 11, 2023
1 parent e3ed564 commit 31affc1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 41 deletions.
79 changes: 43 additions & 36 deletions app/components/FileConfigSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Button, Input, Modal, Table, Popconfirm, Dropdown, MenuProps } from 'an
import { v4 as uuidv4 } from 'uuid';
import { useCallback, useEffect, useState } from 'react';
import { usePapaParse } from 'react-papaparse';
import { debounce } from 'lodash';
import cls from 'classnames';
import { StudioFile } from '@app/interfaces/import';
import { observer, useLocalObservable } from 'mobx-react-lite';
Expand Down Expand Up @@ -62,40 +63,43 @@ const FileConfigSetting = (props: IProps) => {
useEffect(() => {
state.activeItem && readFile();
}, [state.activeItem]);
const readFile = useCallback(() => {
const { activeItem, setState } = state;
if (!activeItem) return;
setState({ loading: true });
let content = [];
if (activeItem.sample !== undefined) {
readString(activeItem.sample, {
delimiter: activeItem.delimiter || ',',
worker: true,
skipEmptyLines: true,
step: (row) => {
content = [...content, row.data];
},
complete: () => {
setState({ loading: false, previewContent: content });
},
});
} else {
const url = URL.createObjectURL(activeItem);
readRemoteFile(url, {
delimiter: activeItem.delimiter,
download: true,
preview: 5,
worker: true,
skipEmptyLines: true,
step: (row) => {
content = [...content, row.data];
},
complete: () => {
setState({ loading: false, previewContent: content });
},
});
}
}, []);
const readFile = useCallback(
debounce(() => {
const { activeItem, setState } = state;
if (!activeItem) return;
setState({ loading: true });
let content = [];
if (activeItem.sample !== undefined) {
readString(activeItem.sample, {
delimiter: activeItem.delimiter || ',',
worker: true,
skipEmptyLines: true,
step: (row) => {
content = [...content, row.data];
},
complete: () => {
setState({ loading: false, previewContent: content });
},
});
} else {
const url = URL.createObjectURL(activeItem);
readRemoteFile(url, {
delimiter: activeItem.delimiter,
download: true,
preview: 5,
worker: true,
skipEmptyLines: true,
step: (row) => {
content = [...content, row.data];
},
complete: () => {
setState({ loading: false, previewContent: content });
},
});
}
}, 300),
[],
);

const onCheckAllChange = useCallback((e: CheckboxChangeEvent) => {
const { data, setState } = state;
Expand Down Expand Up @@ -126,9 +130,12 @@ const FileConfigSetting = (props: IProps) => {
}, []);

const updateDelimiter = useCallback((e: React.ChangeEvent<HTMLInputElement>, item: StudioFile) => {
const { activeItem } = state;
const { activeItem, setState, data } = state;
e.stopPropagation();
item.delimiter = e.target.value;
setState({
data: data.map((i) => (i.path === item.path && (i.delimiter = e.target.value), i)),
});
item === activeItem && readFile();
}, []);

Expand Down Expand Up @@ -281,7 +288,7 @@ const FileConfigSetting = (props: IProps) => {
className={styles.previewTable}
dataSource={data}
columns={columns}
rowKey={() => uuidv4()}
rowKey="path"
pagination={false}
/>
</div>
Expand Down
1 change: 0 additions & 1 deletion app/config/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ export default {
port: 'Port',
username: 'Username',
password: 'Password',
success: 'succeed',
clear: 'Log out',
title: `Connect to ${window.gConfig.databaseName}`,
tip: "Don't know the address? Docs->",
Expand Down
1 change: 0 additions & 1 deletion app/config/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export default {
port: 'Port',
username: '用户名',
password: '密码',
success: '配置成功',
clear: '登出',
title: '配置数据库',
tip: '连接数据库说明文档->',
Expand Down
4 changes: 2 additions & 2 deletions app/pages/Import/TaskList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const TaskList = () => {
const { dataImport, global, moduleConfiguration, schema } = useStore();
const { spaces, getSpaces } = schema;
const isMounted = useRef(true);
const [filter, setFilter] = useState({ page: 1, pageSize: 10, space: '' });
const [filter, setFilter] = useState({ page: 1, pageSize: 10, space: undefined });
const { intl, currentLocale } = useI18n();
const history = useHistory();
const { taskList, getTaskList, stopTask, deleteTask } = dataImport;
Expand Down Expand Up @@ -70,7 +70,7 @@ const TaskList = () => {
}, []);
const initList = useCallback(async () => {
setLoading(true);
await getData({ page: 1, space: '' });
await getData({ page: 1, space: undefined });
setLoading(false);
}, []);
const handleRerun = () => {
Expand Down
1 change: 0 additions & 1 deletion app/stores/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export class GlobalStore {
},
)) as any;
if (code === 0) {
message.success(intl.get('configServer.success'));
cookies.set('nh', _host);
cookies.set('nu', username);
const socketConncted = await this.ngqlRunner.connect({
Expand Down

0 comments on commit 31affc1

Please sign in to comment.