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]: Offline Execute workflow #435

Merged
merged 2 commits into from
Oct 8, 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: 7 additions & 7 deletions packages/shared/lib/api/sqle/service/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2192,12 +2192,6 @@ export interface IReportPushConfigList {
type?: string;
}

export interface IRetryExecWorkflowReqV1 {
task_ids?: number[];

workflow_id?: string;
}

export interface IRewriteRule {
message?: string;

Expand Down Expand Up @@ -3401,7 +3395,13 @@ export interface IBatchCancelWorkflowsReqV2 {
}

export interface IBatchCompleteWorkflowsReqV2 {
workflow_id_list?: string[];
workflow_list?: ICompleteWorkflowReq[];
}

export interface ICompleteWorkflowReq {
desc?: string;

workflow_id?: string;
}

export interface ICreateWorkflowReqV2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ describe('sqle/ExecWorkflow/Detail', () => {

expect(batchCompleteWorkflowsSpy).toHaveBeenCalledTimes(1);
expect(batchCompleteWorkflowsSpy).toHaveBeenCalledWith({
workflow_id_list: [workflowsDetailData.workflow_id],
workflow_list: [{ workflow_id: workflowsDetailData.workflow_id }],
project_name: mockProjectInfo.projectName
});
await act(async () => jest.advanceTimersByTime(3000));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const useGenerateWorkflowStepsProps = ({
const completeAction = useCallback(async () => {
return workflow
.batchCompleteWorkflowsV2({
workflow_id_list: [workflowId],
workflow_list: [{ workflow_id: workflowId }],
project_name: projectName
})
.then((res) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,40 @@
import { useTranslation } from 'react-i18next';
import WorkflowStatus from '../../../../../SqlExecWorkflow/List/components/WorkflowStatus';
import { WorkflowDetailResV1StatusEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum';
import { IBasicTable } from '@actiontech/shared/lib/components/BasicTable';

const WorkflowTableField: React.FC<{
value?: React.Key[];
onChange?: (value: React.Key[]) => void;
workflowList?: IAssociateWorkflows[];
loading: boolean;
}> = ({ loading, workflowList, onChange, value }) => {
const { t } = useTranslation();

const onSelectChange = (keys: React.Key[]) => {
onChange?.(keys);
};

const columns = [
const columns: IBasicTable<IAssociateWorkflows>['columns'] = [
{
dataIndex: 'workflow_name',
title: t('versionManagement.associateWorkflow.workflowName')
},
{
LZS911 marked this conversation as resolved.
Show resolved Hide resolved
dataIndex: 'desc',
title: t('versionManagement.associateWorkflow.workflowDesc'),
render: (desc: string) => desc || '-'
},
{
dataIndex: 'status',
title: t('versionManagement.associateWorkflow.workflowStatus'),
render: (status: string) => (
<WorkflowStatus
status={status as unknown as WorkflowDetailResV1StatusEnum}
/>
)
},
{
dataIndex: 'desc',
title: t('versionManagement.associateWorkflow.workflowDesc'),
render: (desc: string) => desc || '-'
}
];

Check warning on line 39 in packages/sqle/src/page/VersionManagement/Detail/Modal/AssociateWorkflowModal/WorkflowTableField/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

return (
<BasicTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,50 @@
import { FormItemLabel } from '@actiontech/shared/lib/components/FormCom';
import workflow from '@actiontech/shared/lib/api/sqle/service/workflow';

const OfflineExecModal = () => {
const { t } = useTranslation();

const dispatch = useDispatch();

const [messageApi, messageContextHolder] = message.useMessage();

const [submitting, { setTrue: startSubmit, setFalse: submitFinish }] =
useBoolean();

const [form] = Form.useForm<{ remarks: string }>();

const { projectName } = useCurrentProject();

const { workflowId, visible } = useSelector((state: IReduxState) => ({
workflowId: state.versionManagement.workflowId,
visible:
!!state.versionManagement.modalStatus[
ModalName.Version_Management_Offline_Execute_Modal
]
}));

const onClose = () => {
form.resetFields();
dispatch(
updateVersionManagementModalStatus({
modalName: ModalName.Version_Management_Offline_Execute_Modal,
status: false
})
);
dispatch(updateSelectVersionStageId({ stageId: null }));
};

const onSubmit = () => {
form.validateFields();
// todo 待后端补充备注字段
const onSubmit = async () => {

Check warning on line 53 in packages/sqle/src/page/VersionManagement/Detail/Modal/OfflineExecModal/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const values = await form.validateFields();

Check warning on line 54 in packages/sqle/src/page/VersionManagement/Detail/Modal/OfflineExecModal/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
startSubmit();
workflow
.batchCompleteWorkflowsV2({
workflow_id_list: [workflowId ?? ''],
workflow_list: [
{
workflow_id: workflowId ?? '',

Check warning on line 60 in packages/sqle/src/page/VersionManagement/Detail/Modal/OfflineExecModal/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 60 in packages/sqle/src/page/VersionManagement/Detail/Modal/OfflineExecModal/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
desc: values.remarks
}
],
project_name: projectName
})
.then((res) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,85 +11,91 @@
import { EmptyBox, ReminderInformation } from '@actiontech/shared';
import { useTranslation } from 'react-i18next';

const useTestConnection = (releaseWorkflows: TargetReleaseWorkflowType[]) => {
const { projectName } = useCurrentProject();

const { t } = useTranslation();

const instanceNames = useMemo(() => {
return releaseWorkflows?.reduce(
(prev: Array<{ name: string }>, next: TargetReleaseWorkflowType) => {
return prev.concat(
next.target_release_instances
?.filter((i: TargetReleaseInstanceType) => !!i.target_instance_name)
?.map((i) => ({
name: i.target_instance_name!
})) ?? []
);
},
[]
);
}, [releaseWorkflows]);

const {
data: connectionInfo,
loading: getConnectionInfoLoading,
run: getConnectionInfo
run: getConnectionInfo,
mutate: setConnectionInfo
} = useRequest(
() => {
const params: IBatchCheckInstanceIsConnectableByNameParams = {
instances: instanceNames,
project_name: projectName
};

return instance
.batchCheckInstanceIsConnectableByName(params)
.then((res) => {
if (res.data.code === ResponseCode.SUCCESS) {
return res.data.data;
}
});
},
{ manual: true }
);

const renderTestDatabasesConnectInfo = useCallback(
(name?: string) => {
const result = connectionInfo?.find((v) => v.instance_name === name);
if (!result) {
return null;
}

return (
<>
<EmptyBox if={!!result.is_instance_connectable}>
<ReminderInformation
status="success"
message={t('common.testDatabaseConnectButton.testSuccess')}
/>
</EmptyBox>
<EmptyBox
if={
!result.is_instance_connectable && !!result.connect_error_message
}
>
<ReminderInformation
status="error"
message={result.connect_error_message ?? t('common.unknownError')}
/>
</EmptyBox>
</>
);
},
[t, connectionInfo]
);

const clearConnectionInfo = useCallback(() => {

Check warning on line 88 in packages/sqle/src/page/VersionManagement/Detail/Modal/ReleaseModal/hooks/useTestConnection.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
setConnectionInfo(undefined);

Check warning on line 89 in packages/sqle/src/page/VersionManagement/Detail/Modal/ReleaseModal/hooks/useTestConnection.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}, [setConnectionInfo]);

Check warning on line 90 in packages/sqle/src/page/VersionManagement/Detail/Modal/ReleaseModal/hooks/useTestConnection.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

return {
renderTestDatabasesConnectInfo,
getConnectionInfoLoading,
getConnectionInfo,
testConnectionAble: !!instanceNames?.length
testConnectionAble: !!instanceNames?.length,
clearConnectionInfo
};

Check warning on line 98 in packages/sqle/src/page/VersionManagement/Detail/Modal/ReleaseModal/hooks/useTestConnection.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
};

Check warning on line 99 in packages/sqle/src/page/VersionManagement/Detail/Modal/ReleaseModal/hooks/useTestConnection.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

export default useTestConnection;
Original file line number Diff line number Diff line change
Expand Up @@ -32,88 +32,90 @@
import EmitterKey from '../../../../../data/EmitterKey';
import EventEmitter from '../../../../../utils/EventEmitter';

const ReleaseModal: React.FC = () => {
const { t } = useTranslation();

const dispatch = useDispatch();

const { versionId } = useParams<{ versionId: string }>();

const { projectName, projectID } = useCurrentProject();

const [messageApi, messageContextHolder] = message.useMessage();

const [form] = Form.useForm<ReleaseWorkflowFormType>();

const [submitting, { setTrue: startSubmit, setFalse: submitFinish }] =
useBoolean();

const releaseWorkflows = Form.useWatch('release_workflows', form);

const {
renderTestDatabasesConnectInfo,
getConnectionInfoLoading,
getConnectionInfo,
testConnectionAble
testConnectionAble,
clearConnectionInfo
} = useTestConnection(releaseWorkflows);

const { stageId, currentStageWorkflowList, visible } = useSelector(
(state: IReduxState) => ({
stageId: state.versionManagement.stageId,
currentStageWorkflowList:
state.versionManagement.currentStageWorkflowList,
visible:
!!state.versionManagement.modalStatus[
ModalName.Version_Management_Release_Modal
]
})
);

const { data: nextStageInstances, loading: getNextStageInstanceLoading } =
useRequest(
() => {
return sqlVersion
.getDependenciesBetweenStageInstanceV1({
project_name: projectName,
sql_version_stage_id: `${stageId}`,
sql_version_id: versionId ?? ''
})
.then((res) => {
if (res.data.code === ResponseCode.SUCCESS) {
return res.data.data;
}
});
},
{
ready: !!stageId && visible,
onSuccess: (res) => {
const initValues = currentStageWorkflowList?.map((workflow) => {
return {
workflow_id: workflow.workflow_id,
target_release_instances: workflow.workflow_instances?.map(
(instance) => {
const nextInstances = res?.filter(
(i) => i.stage_instance_id === instance.instances_id
);
return {
instance_id: instance.instances_id,
instance_schema: instance.instance_schema,
target_instance_id:
nextInstances?.length === 1
? nextInstances?.[0].next_stage_instance_id
: undefined
};
}
)
};
});
form.setFieldValue('release_workflows', initValues);
}
}
);

const onClose = () => {
form.resetFields();
clearConnectionInfo();

Check warning on line 118 in packages/sqle/src/page/VersionManagement/Detail/Modal/ReleaseModal/index.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
dispatch(
updateVersionManagementModalStatus({
modalName: ModalName.Version_Management_Release_Modal,
Expand Down
Loading