Skip to content

Commit

Permalink
[refactor/taskConfig][taier-ui]unify the get of dataSource (#1076)
Browse files Browse the repository at this point in the history
# 简介
- 统一数据源获取


# Related
Closed #861
  • Loading branch information
mortalYoung committed May 8, 2023
1 parent b4241a7 commit 7abf6b5
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions taier-ui/src/pages/rightBar/taskConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useContext, useEffect, useMemo, useState } from 'react';
import { useContext, useMemo } from 'react';
import { FormContext } from '@/services/rightBarService';
import { Checkbox, Form, Input, InputNumber, Select, Collapse } from 'antd';
import molecule from '@dtinsight/molecule';
import { DATA_SOURCE_ENUM, DIRTY_DATA_SAVE, formItemLayout } from '@/constant';
import { dirtyMaxRecord, dirtyFailRecord, dirtySaveType, logPrintTimes } from '@/components/helpDoc/docs';
import api from '@/api';
import type { IDataSourceProps } from '@/interface';
import { dataSourceService } from '@/services';
import type { IRightBarComponentProps } from '@/services/rightBarService';
import type { FormInstance } from 'antd';

Expand All @@ -26,8 +25,6 @@ interface IFormFieldProps {
export default function TaskConfig({ current }: IRightBarComponentProps) {
const { form } = useContext(FormContext) as { form?: FormInstance<IFormFieldProps> };

const [dataSourceList, setDataSourceList] = useState<{ label: string; value: number }[]>([]);

const handleFormValuesChange = () => {
setTimeout(() => {
const { openDirtyDataManage, ...restValues } = form?.getFieldsValue() || {};
Expand All @@ -46,16 +43,6 @@ export default function TaskConfig({ current }: IRightBarComponentProps) {
}, 0);
};

useEffect(() => {
api.getAllDataSource({}).then((res) => {
if (res.code === 1) {
const mysqlDataSource =
(res.data as IDataSourceProps[])?.filter((d) => d.dataTypeCode === DATA_SOURCE_ENUM.MYSQL) || [];
setDataSourceList(mysqlDataSource.map((i) => ({ label: i.dataName, value: i.dataInfoId })));
}
});
}, []);

const initialValues = useMemo<IFormFieldProps>(() => {
if (current?.tab?.data) {
const { maxRows, maxCollectFailedRows, outputType, linkInfo, tableName, logPrintInterval } = (current.tab
Expand All @@ -76,6 +63,15 @@ export default function TaskConfig({ current }: IRightBarComponentProps) {
};
}, [current?.activeTab]);

const dataSourceList = useMemo(
() =>
dataSourceService
.getDataSource()
.filter((d) => d.dataTypeCode === DATA_SOURCE_ENUM.MYSQL)
.map((i) => ({ label: i.dataName, value: i.dataInfoId })),
[]
);

return (
<molecule.component.Scrollbar>
<Collapse bordered={false} ghost defaultActiveKey={['1']}>
Expand Down

0 comments on commit 7abf6b5

Please sign in to comment.