From 197d0ac7646ecff6b8e1939790d22351e7b7c5e5 Mon Sep 17 00:00:00 2001 From: daskyrk Date: Wed, 12 May 2021 14:31:40 +0800 Subject: [PATCH] feat: add commit action 'update' --- .../yml-editor/pipeline-yml/pipeline-editor.tsx | 9 ++++----- .../pages/pipeline/config-detail/index.tsx | 9 ++++----- .../pages/repo/components/add-pipelineyml.tsx | 5 ++--- .../repo/components/audit-template-manager.tsx | 7 +++---- .../pages/repo/components/repo-editor.tsx | 13 ++++++------- .../repo/components/repo-file-container.tsx | 12 +++++------- .../pages/repo/components/repo-mr-form.tsx | 5 ++--- .../pages/repo/components/repo-nav.tsx | 7 +++---- .../pages/repo/components/yml-editor.tsx | 16 +++++++--------- shell/app/modules/application/types/repo.d.ts | 2 +- 10 files changed, 37 insertions(+), 48 deletions(-) diff --git a/shell/app/modules/application/common/yml-editor/pipeline-yml/pipeline-editor.tsx b/shell/app/modules/application/common/yml-editor/pipeline-yml/pipeline-editor.tsx index 1864bf10e7..85741845ed 100644 --- a/shell/app/modules/application/common/yml-editor/pipeline-yml/pipeline-editor.tsx +++ b/shell/app/modules/application/common/yml-editor/pipeline-yml/pipeline-editor.tsx @@ -107,20 +107,19 @@ const PipelineEditor = (props: IYmlEditorProps) => { const commitData = (commitContent: string, values: any) => { const { path } = tree; const { branch, message: commitMsg } = values; - const data = { + + commit({ branch, message: commitMsg || `Update ${fileName}`, actions: [ { content: commitContent, path, - action: 'add', + action: 'update', pathType: 'blob', }, ], - }; - - commit(data).then(() => { + }).then(() => { onCancel(); message.success(i18n.t('application:modify file successfully')); getRepoBlob(); diff --git a/shell/app/modules/application/pages/pipeline/config-detail/index.tsx b/shell/app/modules/application/pages/pipeline/config-detail/index.tsx index 680dcf7cca..0a9773eecb 100644 --- a/shell/app/modules/application/pages/pipeline/config-detail/index.tsx +++ b/shell/app/modules/application/pages/pipeline/config-detail/index.tsx @@ -62,20 +62,19 @@ const PipelineConfigDetail = (props: IProps) => { const onUpdateYml = (ymlStr: string) => { const fileName = caseDetail.name; const { branch, path } = getBranchPath(caseDetail); - const data = { + + return commit({ branch, message: `Update ${fileName}`, actions: [ { content: ymlStr, path, - action: 'add', + action: 'update', pathType: 'blob', }, ], - }; - - return commit(data).then(() => { + }).then(() => { getTreeNodeDetailNew({ id: nodeId, ...scopeParams }); if (recordRef.current && recordRef.current.reload) { recordRef.current.reload(); diff --git a/shell/app/modules/application/pages/repo/components/add-pipelineyml.tsx b/shell/app/modules/application/pages/repo/components/add-pipelineyml.tsx index 2510a6292f..109b0bd751 100644 --- a/shell/app/modules/application/pages/repo/components/add-pipelineyml.tsx +++ b/shell/app/modules/application/pages/repo/components/add-pipelineyml.tsx @@ -136,7 +136,7 @@ const AddPipelineYml = () => { if (error) { return; } - const data = { + commit({ ...values, actions: [ { @@ -146,8 +146,7 @@ const AddPipelineYml = () => { pathType: 'blob', }, ], - }; - commit(data).then((res: any) => { + }).then((res: any) => { if (res.success) { cancelEdit(); message.success(i18n.t('application:create file successfully')); diff --git a/shell/app/modules/application/pages/repo/components/audit-template-manager.tsx b/shell/app/modules/application/pages/repo/components/audit-template-manager.tsx index 5fcddfba13..6a8fc199c7 100644 --- a/shell/app/modules/application/pages/repo/components/audit-template-manager.tsx +++ b/shell/app/modules/application/pages/repo/components/audit-template-manager.tsx @@ -65,10 +65,10 @@ export const AuditTemplateManager = () => { }); const handleSubmit = (content: string) => { - const data = { + commit({ actions: [ { - action: 'add', + action: 'update', content, path: 'audit/template.json', pathType: 'blob', @@ -76,8 +76,7 @@ export const AuditTemplateManager = () => { ], branch, message: 'Update template.json', - }; - commit(data).then((res) => { + }).then((res) => { if (res.success) { message.success(i18n.t('application:update file successfully')); getRepoBlob(); diff --git a/shell/app/modules/application/pages/repo/components/repo-editor.tsx b/shell/app/modules/application/pages/repo/components/repo-editor.tsx index 9025b42eac..0ff805eccd 100644 --- a/shell/app/modules/application/pages/repo/components/repo-editor.tsx +++ b/shell/app/modules/application/pages/repo/components/repo-editor.tsx @@ -82,22 +82,21 @@ const RepoEditor = ({ autoHeight, maxLines, ops, isDiceOrPipelineFile, name, blo } } - form.validateFields((error: Error, values: Pick) => { + form.validateFields((error: Error, values: Pick) => { if (error) { return; } - const data = { + commit({ ...values, actions: [ { - action: 'add', + action: isAddMode ? 'add' : 'update', content: state.value, path, pathType: 'blob', }, ], - }; - commit(data).then((res) => { + }).then((res) => { if (res.success) { changeMode({ editFile: false, addFile: false }); if (isAddMode) { @@ -131,14 +130,14 @@ const RepoEditor = ({ autoHeight, maxLines, ops, isDiceOrPipelineFile, name, blo name: 'branch', type: 'select', initialValue: branch || 'master', - options: branches.map((a:string) => ({ name: a, value: a })), + options: branches.map((a: string) => ({ name: a, value: a })), itemProps: { placeholder: i18n.t('application:submit branch'), disabled: true, }, }, { - getComp: ({ form }: {form: any}) => ( + getComp: ({ form }: { form: any }) => (