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/sql backup 3 #506

Merged
merged 2 commits into from
Nov 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ const AddDataSource = () => {
// #endif
additional_params: values.asyncParams,
// #if [dms]
is_enable_masking: values.is_enable_masking
is_enable_masking: values.is_enable_masking,
// #endif
// #if [sqle && ee]
enable_backup: values.enableBackup
// #endif
};
return DBService.AddDBService({
Expand Down
33 changes: 31 additions & 2 deletions packages/base/src/page/DataSource/components/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
FormItemBigTitle,
FormItemLabel,
FormItemNoLabel,
FormItemSubTitle
FormItemSubTitle,
CustomLabelContent
} from '@actiontech/shared/lib/components/FormCom';
import { nameRule } from '@actiontech/shared/lib/utils/FormRule';
import DatabaseFormItem from './FormItem';
Expand Down Expand Up @@ -193,7 +194,10 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
business: props.defaultData.business,
password: props.defaultData.password,
// #if [dms]
is_enable_masking: props.defaultData.is_enable_masking
is_enable_masking: props.defaultData.is_enable_masking,
// #endif
// #if [sqle && ee]
enableBackup: props.defaultData.enable_backup
// #endif
});
setDatabaseType(props.defaultData.db_type ?? '');
Expand Down Expand Up @@ -481,6 +485,31 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
</FormAreaLineStyleWrapper>
{/* #endif */}

{/* #if [sqle && ee] */}
<FormAreaLineStyleWrapper>
<FormAreaBlockStyleWrapper>
<FormItemSubTitle>
{t('dmsDataSource.dataSourceForm.sqlBackupConfiguration')}
</FormItemSubTitle>
<FormItemLabel
className="has-label-tip"
label={
<CustomLabelContent
title={t('dmsDataSource.dataSourceForm.enableDataSourceBackup')}
tips={t(
'dmsDataSource.dataSourceForm.enableDataSourceBackupTips'
)}
/>
}
name="enableBackup"
valuePropName="checked"
>
<BasicSwitch />
</FormItemLabel>
</FormAreaBlockStyleWrapper>
</FormAreaLineStyleWrapper>
{/* #endif */}

{/* #if [dms] */}
<FormAreaLineStyleWrapper>
<FormAreaBlockStyleWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type DataSourceFormField = {
asyncParams?: BackendFormRequestParams[];
needUpdatePassword?: boolean;
is_enable_masking?: boolean;
enableBackup?: boolean;
};

export type IDataSourceFormProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ const UpdateDataSource = () => {
additional_params: values.asyncParams,
user: values.user,
// #if [dms]
is_enable_masking: values.is_enable_masking
is_enable_masking: values.is_enable_masking,
// #endif
// #if [sqle && ee]
enable_backup: values.enableBackup
// #endif
},
project_uid: projectID
Expand Down
12 changes: 10 additions & 2 deletions packages/shared/lib/api/sqle/service/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3531,6 +3531,12 @@ export interface IUpdatePipelineNode {
type?: updatePipelineNodeTypeEnum;
}

export interface IAssociatedRollbackWorkflow {
workflow_id?: string;

workflow_name?: string;
}

export interface IAssociatedStageWorkflows {
sql_version_stage_id?: number;

Expand Down Expand Up @@ -3646,7 +3652,7 @@ export interface IAuditSQLResV2 {
}

export interface IAuditTaskSQLResV2 {
associate_workflow_ids?: string[];
associated_rollback_workflows?: IAssociatedRollbackWorkflow[];

audit_level?: string;

Expand All @@ -3670,7 +3676,7 @@ export interface IAuditTaskSQLResV2 {

number?: number;

rollback_sql?: string;
rollback_sqls?: string[];

sql_source_file?: string;

Expand Down Expand Up @@ -3974,6 +3980,8 @@ export interface IWorkflowRecordResV2 {
}

export interface IWorkflowResV2 {
associated_rollback_workflows?: IAssociatedRollbackWorkflow[];

associated_stage_workflows?: IAssociatedStageWorkflows[];

create_time?: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/sqle/src/locale/zh-CN/execWorkflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ export default {
remark: '备注',
addRemark: '添加备注',
originSql: '原始SQL'
}
},
associatedRollbackWorkflow: '关联回滚工单'
},

audit: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import SwitchField from './SwitchField';
const SqlBackupSwitcher: React.FC<SqlBackupSwitcherProps> = ({
fieldPrefixPath,
databaseInfo,
isSameSqlForAll
isSameSqlForAll,
isAtRejectStep
}) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -73,6 +74,7 @@ const SqlBackupSwitcher: React.FC<SqlBackupSwitcherProps> = ({
)
: t('execWorkflow.create.form.sqlInfo.cancelSwitchSqlBackupTips')
}
disabled={isAtRejectStep}
/>
</FormItemLabel>
</EmptyBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { SwitcherFieldProps } from './index.type';
const SwitchField: React.FC<SwitcherFieldProps> = ({
checked,
onChange,
title
title,
disabled = false
}) => {
const { t } = useTranslation();

Expand All @@ -29,6 +30,7 @@ const SwitchField: React.FC<SwitcherFieldProps> = ({
onCancel={hidePopconfirm}
>
<BasicSwitch
disabled={disabled}
checked={checked}
className="backup-switcher"
onChange={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ export type SqlFormatterAndSubmitterProps = {

export type SqlBackupSwitcherProps = Pick<
SqlStatementFormItemProps,
'fieldPrefixPath' | 'databaseInfo' | 'isSameSqlForAll'
'fieldPrefixPath' | 'databaseInfo' | 'isSameSqlForAll' | 'isAtRejectStep'
>;

export type SwitcherFieldProps = {
checked?: boolean;
onChange?: (v: boolean) => void;
title?: string;
disabled?: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const SqlStatementFormItem: React.FC<SqlStatementFormItemProps> = ({
fieldPrefixPath={fieldPrefixPath}
databaseInfo={databaseInfo}
isSameSqlForAll={isSameSqlForAll}
isAtRejectStep={isAtRejectStep}
/>
{/* #endif */}
<SqlFormatterAndSubmitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { TaskResultContentTypeEnum } from './index.data';
import { BackupStrategyDictionary } from '../../../../../../Common/AuditResultList/Table/index.data';
import { UpdateSqlBackupStrategyReqStrategyEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum';
import { WarningFilled } from '@actiontech/icons';
import RollbackWorkflowEntry from './components/RollbackWorkflowEntry';

const SqlMode: React.FC<SqlExecuteResultCardProps> = ({
projectID,
Expand Down Expand Up @@ -99,6 +100,13 @@ const SqlMode: React.FC<SqlExecuteResultCardProps> = ({
</div>
</Space>
<Space>
{/* #if [ee] */}
<EmptyBox if={!!props.associated_rollback_workflows?.length}>
<RollbackWorkflowEntry
workflows={props.associated_rollback_workflows}
/>
</EmptyBox>
{/* #endif */}
<BasicButton size="small" onClick={onCopyExecSql}>
{t('execWorkflow.audit.copyExecSql')}
</BasicButton>
Expand All @@ -125,12 +133,14 @@ const SqlMode: React.FC<SqlExecuteResultCardProps> = ({
label: t('execWorkflow.audit.table.rollback'),
children: (
<Space direction="vertical">
{/* #if [ee] */}
<EmptyBox if={!!props.backup_strategy_tip}>
<Space className="backup-conflict-tips">
<WarningFilled width={16} height={16} />
{props.backup_strategy_tip}
</Space>
</EmptyBox>
{/* #endif */}
<Space className="result-card-content-rollback">
{/* #if [ee] */}
<EmptyBox
Expand Down Expand Up @@ -158,7 +168,7 @@ const SqlMode: React.FC<SqlExecuteResultCardProps> = ({
/>
{/* #endif */}
<SQLRenderer
sql={props.rollback_sql?.join('\n')}
sql={props.rollback_sqls?.join('\n')}
showLineNumbers
/>
</Space>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { RollbackWorkflowEntryProps } from '../index.type';
import { Dropdown, MenuProps } from 'antd';
import { BasicButton, TypedLink } from '@actiontech/shared';
import { DownOutlined } from '@actiontech/icons';
import { useMemo } from 'react';
import { ROUTE_PATHS } from '@actiontech/shared/lib/data/routePaths';
import { useCurrentProject } from '@actiontech/shared/lib/global';
import { useTranslation } from 'react-i18next';
import { RollbackWorkflowItemStyleWrapper } from './style';

const RollbackWorkflowEntry: React.FC<RollbackWorkflowEntryProps> = ({
workflows
}) => {
const { t } = useTranslation();

const { projectID } = useCurrentProject();

const menuItems: MenuProps['items'] = useMemo(() => {
return (
workflows?.map((item) => {
return {
key: item.workflow_id,
label: (
<RollbackWorkflowItemStyleWrapper title={item.workflow_name}>
<TypedLink
target="_blank"
to={ROUTE_PATHS.SQLE.SQL_EXEC_WORKFLOW.detail}
params={{ projectID, workflowId: item.workflow_id ?? '' }}
>
{item.workflow_name}
</TypedLink>
</RollbackWorkflowItemStyleWrapper>
),
type: 'group'
};
}) ?? []
);
}, [workflows, projectID]);

return (
<Dropdown menu={{ items: menuItems }} trigger={['click']}>
<BasicButton>
{t('execWorkflow.detail.associatedRollbackWorkflow')}
<DownOutlined color="currentColor" />
</BasicButton>
</Dropdown>
);
};

export default RollbackWorkflowEntry;
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ export const TaskResultDescribeStyleWrapper = styled('div')`
font-size: 13px;
}
`;

export const RollbackWorkflowItemStyleWrapper = styled('div')`
max-width: 300px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
IAuditTaskSQLResV2,
IAuditFileStatistic
IAuditFileStatistic,
IAssociatedRollbackWorkflow
} from '@actiontech/shared/lib/api/sqle/service/common';
import { WorkflowResV2ExecModeEnum } from '@actiontech/shared/lib/api/sqle/service/common.enum';

Expand All @@ -27,3 +28,7 @@ export type ResultCardProps =
| (FileExecuteResultCardProps & {
executeMode: WorkflowResV2ExecModeEnum.sql_file;
});

export type RollbackWorkflowEntryProps = {
workflows?: IAssociatedRollbackWorkflow[];
};
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ const ModifySqlStatement: React.FC<ModifySqlStatementProps> = ({
form.setFieldValue(SAME_SQL_MODE_DEFAULT_FIELD_KEY, {
currentUploadType: currentTasks?.[0]?.sql_source,
exec_mode: currentTasks?.[0]?.exec_mode,
file_sort_method: currentTasks?.[0]?.file_order_method
file_sort_method: currentTasks?.[0]?.file_order_method,
backup: currentTasks?.[0]?.enable_backup
});
} else {
sqlStatementTabActiveKey.set(
Expand All @@ -204,7 +205,8 @@ const ModifySqlStatement: React.FC<ModifySqlStatementProps> = ({
form.setFieldValue(item.task_id?.toString() ?? '', {
currentUploadType: item.sql_source,
exec_mode: item.exec_mode,
file_sort_method: item.file_order_method
file_sort_method: item.file_order_method,
backup: item.enable_backup
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,22 @@ const useWorkflowDetailAction = ({
if (!workflowInfo?.record?.status) {
return false;
}
return [
WorkflowRecordResV2StatusEnum.finished,
WorkflowRecordResV2StatusEnum.exec_failed,
WorkflowRecordResV2StatusEnum.canceled
].includes(workflowInfo.record.status);
}, [workflowInfo?.record?.status]);

return (
[
WorkflowRecordResV2StatusEnum.finished,
WorkflowRecordResV2StatusEnum.exec_failed,
WorkflowRecordResV2StatusEnum.canceled
].includes(workflowInfo.record.status) &&
workflowInfo.record.workflow_step_list
?.find((v) => v.type === WorkflowStepResV2TypeEnum.sql_execute)
?.assignee_user_name_list?.includes(username)
);
}, [
workflowInfo?.record?.status,
username,
workflowInfo?.record?.workflow_step_list
]);

const rollbackWorkflow = () => {
startRollback();
Expand Down