Skip to content

Commit

Permalink
Merge pull request #334 from actiontech/fix/issue-2031
Browse files Browse the repository at this point in the history
fix: fix uploadType reset bug
  • Loading branch information
Rain-1214 authored Nov 16, 2023
2 parents 3f5613a + b5774ba commit d049e9b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/data/EmitterKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum EmitterKey {

Reset_Create_Order_Form = 'RESET_CREATE_ORDER_FORM',

Reset_Upload_Type_Content = 'RESET_UPLOAD_TYPE_CONTENT',

Reset_Test_Data_Source_Connect = 'RESET_TEST_DATA_SOURCE_CONNECT',

Reset_Workflow_Template_Form = 'RESET_WORKFLOW_TEMPLATE_FORM',
Expand Down
3 changes: 2 additions & 1 deletion src/page/Order/Create/SqlInfoForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const SqlInfoForm: React.FC<SqlInfoFormProps> = (props) => {
useBoolean();
const [connectErrorMessage, setConnectErrorMessage] = useState<string[]>([]);
const [changeSqlModeDisabled, setChangeSqlModeDisabled] = useState(false);

const instanceNameList = useMemo(() => {
return Array.from(instanceNames).map(([_, name]) => name ?? '');
}, [instanceNames]);
Expand Down Expand Up @@ -231,6 +231,7 @@ const SqlInfoForm: React.FC<SqlInfoFormProps> = (props) => {
setInstanceNames(new Map([[0, '']]));
setConnectInitHideTrue();
setCurrentSqlMode(WorkflowResV2ModeEnum.same_sqls);
EventEmitter.emit(EmitterKey.Reset_Upload_Type_Content);
};
EventEmitter.subscribe(
EmitterKey.Reset_Create_Order_Form,
Expand Down
3 changes: 2 additions & 1 deletion src/page/Order/Create/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ describe('Order/Create', () => {
const emitSpy = jest.spyOn(EventEmitter, 'emit');
fireEvent.click(screen.getByText('common.resetAndClose'));

expect(emitSpy).toBeCalledTimes(1);
expect(emitSpy).toBeCalledTimes(2);
expect(emitSpy).toBeCalledWith(EmitterKey.Reset_Create_Order_Form);
expect(emitSpy).toBeCalledWith(EmitterKey.Reset_Upload_Type_Content);
expect(getBySelector('.ant-modal-wrap')).toHaveStyle('display: none');
expect(screen.getByLabelText('order.baseInfo.name')).toHaveValue('');
});
Expand Down
22 changes: 22 additions & 0 deletions src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import useChangeTheme from '../../../hooks/useChangeTheme';
import useMonacoEditor from '../../../hooks/useMonacoEditor';
import useStyles from '../../../theme';
import { getFileFromUploadChangeEvent } from '../../../utils/Common';
import EmitterKey from '../../../data/EmitterKey';
import EventEmitter from '../../../utils/EventEmitter';

const MonacoEditorFunComponent =
MonacoEditor as ComponentType<MonacoEditorProps>;
Expand Down Expand Up @@ -54,6 +56,10 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
return [fieldName ?? '0', name];
};

const resetUploadTypeContent = () => {
setCurrentSQLInputTYpe(SQLInputType.manualInput);
}

const { editorDidMount } = useMonacoEditor(form, {
formName: generateFieldName('sql'),
});
Expand All @@ -68,6 +74,22 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
}
}, [fieldName, form, sqlStatement]);

useEffect(() => {
EventEmitter.subscribe(
EmitterKey.Reset_Upload_Type_Content,
resetUploadTypeContent
);

return () => {
EventEmitter.unsubscribe(
EmitterKey.Reset_Upload_Type_Content,
resetUploadTypeContent
);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])


return (
<>
<Form.Item
Expand Down

0 comments on commit d049e9b

Please sign in to comment.