Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/clone sql exec wrokflow #381

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/shared/lib/api/common/ApiBase/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import axios from 'axios';
import TestMockApi from '../../../testUtil/mockApi';
import { eventEmitter } from '../../../utils/EventEmitter';
import EmitterKey from '../../../data/EmitterKey';
import 'blob-polyfill';

const downloadSpy = jest.spyOn(Download, 'downloadByCreateElementA');
const emitSpy = jest.spyOn(eventEmitter, 'emit');
Expand Down Expand Up @@ -131,4 +132,17 @@ describe('Api', () => {
expect(token).toBe('');
}
});

test('should return file stream when request header includes content-disposition and inline', async () => {
let res;

try {
res = await apiInstance.post('/file/stream');
} finally {
expect(downloadSpy).not.toHaveBeenCalled();
res?.data.text().then((res: string) => {
expect(res).toBe('use aaa');
});
}
});
});
7 changes: 5 additions & 2 deletions packages/shared/lib/api/common/ApiBase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import store from '../../../../../base/src/store';
import {
getResponseErrorMessage,
getResponseCode,
isExportFileResponse
isExportFileResponse,
isFileStreamResponse
} from '../../../utils/Common';
import { eventEmitter } from '../../../utils/EventEmitter';
import { NotificationInstanceKeyType } from '../../../hooks/useNotificationContext';
Expand Down Expand Up @@ -34,7 +35,9 @@ class ApiBase {
Download.downloadByCreateElementA(res.data, filename);
return res;
} else if (
(res.status === 200 && code !== ResponseCode.SUCCESS) ||
(res.status === 200 &&
code !== ResponseCode.SUCCESS &&
!isFileStreamResponse(res)) ||
res.status !== 200
) {
const message = await getResponseErrorMessage(res);
Expand Down
4 changes: 4 additions & 0 deletions packages/shared/lib/api/sqle/service/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,12 @@ export interface IAuditTaskResV1 {

exec_end_time?: string;

exec_mode?: string;

exec_start_time?: string;

file_order_method?: string;

instance_db_type?: string;

instance_name?: string;
Expand Down
14 changes: 8 additions & 6 deletions packages/shared/lib/api/sqle/service/workflow/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ export interface IExportWorkflowV1Params {
fuzzy_keyword?: string;
}

export interface IGetWorkflowAttachmentParams {
project_name: string;

workflow_id: string;
}

export interface ITerminateMultipleTaskByWorkflowV1Params {
workflow_id: string;

Expand All @@ -141,6 +135,14 @@ export interface ITerminateMultipleTaskByWorkflowV1Params {

export interface ITerminateMultipleTaskByWorkflowV1Return extends IBaseRes {}

export interface IGetWorkflowAttachmentParams {
project_name: string;

workflow_id: string;

task_id: string;
}

export interface ITerminateSingleTaskByWorkflowV1Params {
workflow_id: string;

Expand Down
21 changes: 12 additions & 9 deletions packages/shared/lib/api/sqle/service/workflow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import {
IBatchCompleteWorkflowsV1Params,
IBatchCompleteWorkflowsV1Return,
IExportWorkflowV1Params,
IGetWorkflowAttachmentParams,
ITerminateMultipleTaskByWorkflowV1Params,
ITerminateMultipleTaskByWorkflowV1Return,
IGetWorkflowAttachmentParams,
ITerminateSingleTaskByWorkflowV1Params,
ITerminateSingleTaskByWorkflowV1Return,
IGetWorkflowV1Params,
Expand Down Expand Up @@ -188,8 +188,8 @@ class WorkflowService extends ServiceBase {
);
}

public getWorkflowAttachment(
params: IGetWorkflowAttachmentParams,
public terminateMultipleTaskByWorkflowV1(
params: ITerminateMultipleTaskByWorkflowV1Params,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
Expand All @@ -199,15 +199,15 @@ class WorkflowService extends ServiceBase {
const workflow_id = paramsData.workflow_id;
delete paramsData.workflow_id;

return this.get<any>(
`/v1/projects/${project_name}/workflows/${workflow_id}/attachment`,
return this.post<ITerminateMultipleTaskByWorkflowV1Return>(
`/v1/projects/${project_name}/workflows/${workflow_id}/tasks/terminate`,
paramsData,
options
);
}

public terminateMultipleTaskByWorkflowV1(
params: ITerminateMultipleTaskByWorkflowV1Params,
public getWorkflowAttachment(
params: IGetWorkflowAttachmentParams,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
Expand All @@ -217,8 +217,11 @@ class WorkflowService extends ServiceBase {
const workflow_id = paramsData.workflow_id;
delete paramsData.workflow_id;

return this.post<ITerminateMultipleTaskByWorkflowV1Return>(
`/v1/projects/${project_name}/workflows/${workflow_id}/tasks/terminate`,
const task_id = paramsData.task_id;
delete paramsData.task_id;

return this.get<any>(
`/v1/projects/${project_name}/workflows/${workflow_id}/tasks/${task_id}/attachment`,
paramsData,
options
);
Expand Down
13 changes: 12 additions & 1 deletion packages/shared/lib/testUtil/baseApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class MockBaseApi implements MockApi {
this.downloadFileByEnName(),
this.response500(),
this.responseToken(),
this.mockLoginWithoutToken()
this.mockLoginWithoutToken(),
this.responseFileStream()
];
}

Expand Down Expand Up @@ -90,6 +91,16 @@ class MockBaseApi implements MockApi {
);
});
}

private responseFileStream() {
return rest.post('/file/stream', (_, res, ctx) => {
return res(
ctx.status(200),
ctx.set('content-disposition', `inline`),
ctx.body(new Blob(['use aaa']))
);
});
}
}

export default new MockBaseApi();
4 changes: 4 additions & 0 deletions packages/shared/lib/utils/Common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export const isExportFileResponse = (res: AxiosResponse<any, any>): boolean => {
return res.headers?.['content-disposition']?.includes('attachment') ?? false;
};

export const isFileStreamResponse = (res: AxiosResponse<any, any>): boolean => {
return res.headers?.['content-disposition']?.includes('inline') ?? false;
};

export const jsonParse = <T>(str: string, defaultVal: any = {}): T => {
let val: any;
try {
Expand Down
25 changes: 25 additions & 0 deletions packages/shared/lib/utils/__tests__/Common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getResponseErrorMessage,
getResponseCode,
isExportFileResponse,
isFileStreamResponse,
getFileFromUploadChangeEvent,
jsonParse,
translateTimeForRequest
Expand Down Expand Up @@ -220,6 +221,30 @@ describe('utils/Common', () => {
).toBe(false);
});

test('test isFileStreamResponse', () => {
expect(
isFileStreamResponse({
status: 200,
headers: {
'content-disposition': 'inline'
},
config: {},
statusText: '',
data: ''
})
).toBe(true);

expect(
isFileStreamResponse({
status: 200,
headers: {},
config: {},
statusText: '',
data: ''
})
).toBe(false);
});

test('test jsonParse', () => {
expect(jsonParse('')).toEqual({});
expect(jsonParse('{')).toEqual({});
Expand Down
7 changes: 6 additions & 1 deletion packages/sqle/src/locale/zh-CN/execWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export default {
executeSqlMode: 'SQL模式',
executeFileMode: '文件模式',
selectFileSortMethod: '选择文件排序方式'
},
tour: {
modifyName: '修改工单名称',
modifyDataSource: '修改数据源'
}
},

Expand Down Expand Up @@ -201,7 +205,8 @@ export default {
stepNumberIsUndefined: '当前节点的步骤数未定义!',
closeWorkflow: '关闭工单',
closeConfirm: '您确认关闭当前工单?',
closeWorkflowSuccessTips: '工单关闭成功'
closeWorkflowSuccessTips: '工单关闭成功',
cloneExecWorkflow: '上线到其他实例'
},

paginationDisplay: '分页展示',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ const SqlExecModeSelector: React.FC<SqlExecModeSelectorProps> = ({

const disabledSqlFileExecMode =
!isSupportFileModeExecuteSql ||
![
AuditTaskResV1SqlSourceEnum.sql_file,
AuditTaskResV1SqlSourceEnum.zip_file
].includes(currentSqlUploadType);
(!!currentSqlUploadType &&
![
AuditTaskResV1SqlSourceEnum.sql_file,
AuditTaskResV1SqlSourceEnum.zip_file
].includes(currentSqlUploadType));

// #if [ee]
const isSupportsFileSortUpload =
Expand Down
1 change: 1 addition & 0 deletions packages/sqle/src/page/SqlExecWorkflow/Common/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const SOURCE_WORKFLOW_PATH_KEY = 'sourceWorkflowId';
Loading
Loading