Unverified Commit 86473a33 authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Fix-2462] [studio] Fix refresh related content after renaming the task (#2463)

parent d89485df
......@@ -100,12 +100,13 @@ const JobModal: React.FC<JobModalProps> = (props) => {
formData.configJson.udfConfig.templateId = selectKeys[selectKeys.length - 1];
}
onSubmit({ ...values, ...formData } as Catalogue);
};
const renderForm = () => {
return (
<>
<ProFormSelect
{!values.id && <ProFormSelect
name={'type'}
label={l('catalog.type')}
tooltip={l('catalog.type.tip')}
......@@ -114,7 +115,7 @@ const JobModal: React.FC<JobModalProps> = (props) => {
disabled={!!values.id}
placeholder={l('catalog.type.placeholder')}
rules={[{ required: true, message: l('catalog.type.placeholder') }]}
/>
/>}
<ProFormText
name='name'
label={l('catalog.name')}
......
......@@ -25,7 +25,7 @@ import {
import FolderModal from '@/pages/DataStudio/LeftContainer/Project/FolderModal';
import JobModal from '@/pages/DataStudio/LeftContainer/Project/JobModal';
import JobTree from '@/pages/DataStudio/LeftContainer/Project/JobTree';
import { StateType, STUDIO_MODEL, STUDIO_MODEL_ASYNC } from '@/pages/DataStudio/model';
import {DataStudioParams, StateType, STUDIO_MODEL, STUDIO_MODEL_ASYNC} from '@/pages/DataStudio/model';
import {
handleAddOrUpdate,
handleOption,
......@@ -41,11 +41,15 @@ import { Modal, Typography } from 'antd';
import { MenuInfo } from 'rc-menu/es/interface';
import React, {Key, useEffect, useState} from 'react';
import { connect } from 'umi';
import {getCurrentTab, getTabByTaskId, mapDispatchToProps} from "@/pages/DataStudio/function";
const { Text } = Typography;
const Project: React.FC = (props: connect) => {
const { dispatch } = props;
const {
dispatch,
tabs: { panes, activeKey }
} = props;
const [projectState, setProjectState] = useState<ProjectState>(InitProjectState);
......@@ -161,13 +165,13 @@ const Project: React.FC = (props: connect) => {
options.parentId = projectState.isCreateTask
? projectState.value.id
: projectState.isEdit
? projectState.value.parentId
: options.parentId;
? projectState.value.parentId
: options.parentId;
} else {
options.url = API_CONSTANTS.SAVE_OR_UPDATE_CATALOGUE_URL;
}
const result = await handleAddOrUpdate(
handleAddOrUpdate(
options.url,
{
...values,
......@@ -176,6 +180,29 @@ const Project: React.FC = (props: connect) => {
},
() => {},
() => {
setProjectState((prevState) => ({
...prevState
}));
dispatch({ type: STUDIO_MODEL_ASYNC.queryProject });
if (projectState.isEdit) {
const {id} = values;
const currentTabs = getTabByTaskId(panes, id)
if(currentTabs){
currentTabs.label = values.name;
// currentTabs.params.taskData.name = values.name;
const {params} = currentTabs;
const {taskData} = params;
if(taskData){
taskData.name = values.name;
}
}
dispatch({ type: STUDIO_MODEL.saveTabs, payload: { ...props.tabs }});
// update active breadcrumb title
if(activeKey === currentTabs?.key){
dispatch({ type: STUDIO_MODEL.updateTabsActiveKey, payload: activeKey});
}
}
// close job modal by project state
setProjectState((prevState) => ({
...prevState,
isCreateSub: false,
......@@ -184,10 +211,6 @@ const Project: React.FC = (props: connect) => {
isCreateTask: false,
isCut: false
}));
dispatch({ type: STUDIO_MODEL_ASYNC.queryProject });
if (projectState.isRename) {
// todo: 如果是重命名/修改(修改了名字), 则需要 更新 tab 的 label
}
}
);
};
......
......@@ -17,7 +17,7 @@
*
*/
import { getCurrentData } from '@/pages/DataStudio/function';
import {getCurrentData, getCurrentTab} from '@/pages/DataStudio/function';
import { StateType, TaskDataType } from '@/pages/DataStudio/model';
import { l } from '@/utils/intl';
import { Descriptions } from 'antd';
......@@ -27,16 +27,15 @@ import { connect } from 'umi';
const JobInfo = (props: any) => {
const {
tabs: { panes, activeKey }
tabs: { panes, activeKey, activeBreadcrumbTitle }
} = props;
const [currentInfo, setCurrentInfo] = useState<Partial<TaskDataType>>(
getCurrentData(panes, activeKey) ?? {}
);
useEffect(() => {
setCurrentInfo({ ...currentInfo, ...getCurrentData(panes, activeKey) });
}, [activeKey, panes]);
setCurrentInfo({ ...getCurrentData(panes, activeKey) });
}, [activeKey, activeBreadcrumbTitle]);
return (
<div style={{ paddingInline: 8 }}>
......
......@@ -152,6 +152,21 @@ export function getCurrentTab(
}
}
export function getTabByTaskId(
panes: TabsItemType[],
id: number
): DataStudioTabsItemType | MetadataTabsItemType | undefined {
const item = panes.find((item) => item.treeKey === id);
switch (item?.type) {
case 'project':
return item as DataStudioTabsItemType;
case 'metadata':
return item as MetadataTabsItemType;
default:
return undefined;
}
}
export const getCurrentData = (
panes: TabsItemType[],
activeKey: string
......
......@@ -152,7 +152,7 @@ export interface TabsItemType {
type: TabsPageType;
subType?: TabsPageSubType;
key: string;
treeKey: string;
treeKey: number;
value: string;
icon: any;
closable: boolean;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment