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) => { ...@@ -100,12 +100,13 @@ const JobModal: React.FC<JobModalProps> = (props) => {
formData.configJson.udfConfig.templateId = selectKeys[selectKeys.length - 1]; formData.configJson.udfConfig.templateId = selectKeys[selectKeys.length - 1];
} }
onSubmit({ ...values, ...formData } as Catalogue); onSubmit({ ...values, ...formData } as Catalogue);
}; };
const renderForm = () => { const renderForm = () => {
return ( return (
<> <>
<ProFormSelect {!values.id && <ProFormSelect
name={'type'} name={'type'}
label={l('catalog.type')} label={l('catalog.type')}
tooltip={l('catalog.type.tip')} tooltip={l('catalog.type.tip')}
...@@ -114,7 +115,7 @@ const JobModal: React.FC<JobModalProps> = (props) => { ...@@ -114,7 +115,7 @@ const JobModal: React.FC<JobModalProps> = (props) => {
disabled={!!values.id} disabled={!!values.id}
placeholder={l('catalog.type.placeholder')} placeholder={l('catalog.type.placeholder')}
rules={[{ required: true, message: l('catalog.type.placeholder') }]} rules={[{ required: true, message: l('catalog.type.placeholder') }]}
/> />}
<ProFormText <ProFormText
name='name' name='name'
label={l('catalog.name')} label={l('catalog.name')}
......
...@@ -25,7 +25,7 @@ import { ...@@ -25,7 +25,7 @@ import {
import FolderModal from '@/pages/DataStudio/LeftContainer/Project/FolderModal'; import FolderModal from '@/pages/DataStudio/LeftContainer/Project/FolderModal';
import JobModal from '@/pages/DataStudio/LeftContainer/Project/JobModal'; import JobModal from '@/pages/DataStudio/LeftContainer/Project/JobModal';
import JobTree from '@/pages/DataStudio/LeftContainer/Project/JobTree'; 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 { import {
handleAddOrUpdate, handleAddOrUpdate,
handleOption, handleOption,
...@@ -41,11 +41,15 @@ import { Modal, Typography } from 'antd'; ...@@ -41,11 +41,15 @@ import { Modal, Typography } from 'antd';
import { MenuInfo } from 'rc-menu/es/interface'; import { MenuInfo } from 'rc-menu/es/interface';
import React, {Key, useEffect, useState} from 'react'; import React, {Key, useEffect, useState} from 'react';
import { connect } from 'umi'; import { connect } from 'umi';
import {getCurrentTab, getTabByTaskId, mapDispatchToProps} from "@/pages/DataStudio/function";
const { Text } = Typography; const { Text } = Typography;
const Project: React.FC = (props: connect) => { const Project: React.FC = (props: connect) => {
const { dispatch } = props; const {
dispatch,
tabs: { panes, activeKey }
} = props;
const [projectState, setProjectState] = useState<ProjectState>(InitProjectState); const [projectState, setProjectState] = useState<ProjectState>(InitProjectState);
...@@ -167,7 +171,7 @@ const Project: React.FC = (props: connect) => { ...@@ -167,7 +171,7 @@ const Project: React.FC = (props: connect) => {
options.url = API_CONSTANTS.SAVE_OR_UPDATE_CATALOGUE_URL; options.url = API_CONSTANTS.SAVE_OR_UPDATE_CATALOGUE_URL;
} }
const result = await handleAddOrUpdate( handleAddOrUpdate(
options.url, options.url,
{ {
...values, ...values,
...@@ -176,6 +180,29 @@ const Project: React.FC = (props: connect) => { ...@@ -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) => ({ setProjectState((prevState) => ({
...prevState, ...prevState,
isCreateSub: false, isCreateSub: false,
...@@ -184,10 +211,6 @@ const Project: React.FC = (props: connect) => { ...@@ -184,10 +211,6 @@ const Project: React.FC = (props: connect) => {
isCreateTask: false, isCreateTask: false,
isCut: false isCut: false
})); }));
dispatch({ type: STUDIO_MODEL_ASYNC.queryProject });
if (projectState.isRename) {
// todo: 如果是重命名/修改(修改了名字), 则需要 更新 tab 的 label
}
} }
); );
}; };
......
...@@ -17,7 +17,7 @@ ...@@ -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 { StateType, TaskDataType } from '@/pages/DataStudio/model';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { Descriptions } from 'antd'; import { Descriptions } from 'antd';
...@@ -27,16 +27,15 @@ import { connect } from 'umi'; ...@@ -27,16 +27,15 @@ import { connect } from 'umi';
const JobInfo = (props: any) => { const JobInfo = (props: any) => {
const { const {
tabs: { panes, activeKey } tabs: { panes, activeKey, activeBreadcrumbTitle }
} = props; } = props;
const [currentInfo, setCurrentInfo] = useState<Partial<TaskDataType>>( const [currentInfo, setCurrentInfo] = useState<Partial<TaskDataType>>(
getCurrentData(panes, activeKey) ?? {} getCurrentData(panes, activeKey) ?? {}
); );
useEffect(() => { useEffect(() => {
setCurrentInfo({ ...currentInfo, ...getCurrentData(panes, activeKey) }); setCurrentInfo({ ...getCurrentData(panes, activeKey) });
}, [activeKey, panes]); }, [activeKey, activeBreadcrumbTitle]);
return ( return (
<div style={{ paddingInline: 8 }}> <div style={{ paddingInline: 8 }}>
......
...@@ -152,6 +152,21 @@ export function getCurrentTab( ...@@ -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 = ( export const getCurrentData = (
panes: TabsItemType[], panes: TabsItemType[],
activeKey: string activeKey: string
......
...@@ -152,7 +152,7 @@ export interface TabsItemType { ...@@ -152,7 +152,7 @@ export interface TabsItemType {
type: TabsPageType; type: TabsPageType;
subType?: TabsPageSubType; subType?: TabsPageSubType;
key: string; key: string;
treeKey: string; treeKey: number;
value: string; value: string;
icon: any; icon: any;
closable: boolean; 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