This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
commit 17cdea97e7ba4f38e6b3acdaf4a56a982fdaa709 Author: Marat Gubaidullin <marat.gubaidul...@gmail.com> AuthorDate: Tue Feb 28 14:56:21 2023 -0500 fix #644 --- .../org/apache/camel/karavan/api/GitResource.java | 7 +- .../apache/camel/karavan/service/GitService.java | 14 +- karavan-app/src/main/webui/src/api/KaravanApi.tsx | 5 +- .../main/webui/src/projects/ProjectPageToolbar.tsx | 150 +++++++++++++-------- 4 files changed, 108 insertions(+), 68 deletions(-) diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/api/GitResource.java b/karavan-app/src/main/java/org/apache/camel/karavan/api/GitResource.java index 2f85a37b..9bd7d21a 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/api/GitResource.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/api/GitResource.java @@ -26,6 +26,7 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import java.util.HashMap; @Path("/api/git") public class GitResource { @@ -35,10 +36,12 @@ public class GitResource { private static final Logger LOGGER = Logger.getLogger(GitResource.class.getName()); + @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) - public Project push(Project project) throws Exception { - return gitService.commitAndPushProject(project); + public Project push(HashMap<String, String> params) throws Exception { + System.out.println(params); + return gitService.commitAndPushProject(params.get("projectId"), params.get("message")); } } \ No newline at end of file diff --git a/karavan-app/src/main/java/org/apache/camel/karavan/service/GitService.java b/karavan-app/src/main/java/org/apache/camel/karavan/service/GitService.java index be83abf2..26f2c821 100644 --- a/karavan-app/src/main/java/org/apache/camel/karavan/service/GitService.java +++ b/karavan-app/src/main/java/org/apache/camel/karavan/service/GitService.java @@ -95,10 +95,10 @@ public class GitService { } } - public Project commitAndPushProject(Project project) throws Exception { - Project p = infinispanService.getProject(project.getProjectId()); - List<ProjectFile> files = infinispanService.getProjectFiles(project.getProjectId()); - RevCommit commit = commitAndPushProject(p, files); + public Project commitAndPushProject(String projectId, String message) throws Exception { + Project p = infinispanService.getProject(projectId); + List<ProjectFile> files = infinispanService.getProjectFiles(projectId); + RevCommit commit = commitAndPushProject(p, files, message); String commitId = commit.getId().getName(); Long lastUpdate = commit.getCommitTime() * 1000L; p.setLastCommit(commitId); @@ -107,7 +107,7 @@ public class GitService { return p; } - public RevCommit commitAndPushProject(Project project, List<ProjectFile> files) throws GitAPIException, IOException, URISyntaxException { + public RevCommit commitAndPushProject(Project project, List<ProjectFile> files, String message) throws GitAPIException, IOException, URISyntaxException { LOGGER.info("Commit and push project " + project.getProjectId()); GitConfig gitConfig = getGitConfig(); CredentialsProvider cred = new UsernamePasswordCredentialsProvider(gitConfig.getUsername(), gitConfig.getPassword()); @@ -126,7 +126,7 @@ public class GitService { } writeProjectToFolder(folder, project, files); addDeletedFilesToIndex(git, folder, project, files); - return commitAddedAndPush(git, gitConfig.getBranch(), cred, project.getProjectId()); + return commitAddedAndPush(git, gitConfig.getBranch(), cred, message); } public List<GitRepo> readProjectsFromRepository() { @@ -248,7 +248,7 @@ public class GitService { public RevCommit commitAddedAndPush(Git git, String branch, CredentialsProvider cred, String message) throws GitAPIException, IOException, URISyntaxException { LOGGER.info("Commit and push changes"); LOGGER.info("Git add: " + git.add().addFilepattern(".").call()); - RevCommit commit = git.commit().setMessage(LocalDateTime.now() + ": " + message).call(); + RevCommit commit = git.commit().setMessage(message).call(); LOGGER.info("Git commit: " + commit); Iterable<PushResult> result = git.push().add(branch).setRemote("origin").setCredentialsProvider(cred).call(); LOGGER.info("Git push: " + result); diff --git a/karavan-app/src/main/webui/src/api/KaravanApi.tsx b/karavan-app/src/main/webui/src/api/KaravanApi.tsx index 5d9e84d0..53af69f5 100644 --- a/karavan-app/src/main/webui/src/api/KaravanApi.tsx +++ b/karavan-app/src/main/webui/src/api/KaravanApi.tsx @@ -273,8 +273,9 @@ export class KaravanApi { }); } - static async push(project: Project, after: (res: AxiosResponse<any>) => void) { - instance.post('/api/git', project) + static async push(params: {}, after: (res: AxiosResponse<any>) => void) { + console.log(params) + instance.post('/api/git', params) .then(res => { after(res); }).catch(err => { diff --git a/karavan-app/src/main/webui/src/projects/ProjectPageToolbar.tsx b/karavan-app/src/main/webui/src/projects/ProjectPageToolbar.tsx index e4acc565..35facb46 100644 --- a/karavan-app/src/main/webui/src/projects/ProjectPageToolbar.tsx +++ b/karavan-app/src/main/webui/src/projects/ProjectPageToolbar.tsx @@ -7,10 +7,10 @@ import { FlexItem, ToggleGroup, ToggleGroupItem, - Checkbox, Tooltip, ToolbarItem + Checkbox, Tooltip, ToolbarItem, Modal, ModalVariant, Form, FormGroup, TextInput, FormHelperText, HelperText, HelperTextItem } from '@patternfly/react-core'; import '../designer/karavan.css'; -import {Project, ProjectFile} from "./ProjectModels"; +import {Project, ProjectFile, ProjectFileTypes} from "./ProjectModels"; import UploadIcon from "@patternfly/react-icons/dist/esm/icons/upload-icon"; import DownloadIcon from "@patternfly/react-icons/dist/esm/icons/download-icon"; import DownloadImageIcon from "@patternfly/react-icons/dist/esm/icons/image-icon"; @@ -18,6 +18,7 @@ import PlusIcon from "@patternfly/react-icons/dist/esm/icons/plus-icon"; import {CamelDefinitionYaml} from "karavan-core/lib/api/CamelDefinitionYaml"; import PushIcon from "@patternfly/react-icons/dist/esm/icons/code-branch-icon"; import {KaravanApi} from "../api/KaravanApi"; +import {CamelUi} from "../designer/utils/CamelUi"; interface Props { project: Project, @@ -40,17 +41,25 @@ interface Props { interface State { isPushing: boolean, + commitMessageIsOpen: boolean, + commitMessage: string } export class ProjectPageToolbar extends React.Component<Props> { public state: State = { isPushing: false, + commitMessageIsOpen: false, + commitMessage: '' }; push = (after?: () => void) => { - this.setState({isPushing: true}); - KaravanApi.push(this.props.project, res => { + this.setState({isPushing: true, commitMessageIsOpen: false}); + const params = { + "projectId": this.props.project.projectId, + "message": this.state.commitMessage + }; + KaravanApi.push(params, res => { if (res.status === 200 || res.status === 201) { this.setState({isPushing: false}); after?.call(this); @@ -84,7 +93,7 @@ export class ProjectPageToolbar extends React.Component<Props> { variant={needCommit ? "primary" : "secondary"} className="project-button" icon={!isPushing ? <PushIcon/> : <div></div>} - onClick={e => this.push()}> + onClick={() => this.setState({commitMessageIsOpen: true})}> {isPushing ? "..." : "Commit"} </Button> </Tooltip> @@ -96,7 +105,7 @@ export class ProjectPageToolbar extends React.Component<Props> { } getProjectToolbar() { - const {isPushing} = this.state; + const {isPushing, commitMessage} = this.state; const {file, needCommit, mode, editAdvancedProperties, addProperty, setEditAdvancedProperties, download, downloadImage, setCreateModalOpen, setUploadModalOpen} = this.props; const isFile = file !== undefined; const isYaml = file !== undefined && file.name.endsWith("yaml"); @@ -104,68 +113,95 @@ export class ProjectPageToolbar extends React.Component<Props> { const isProperties = file !== undefined && file.name.endsWith("properties"); return <Toolbar id="toolbar-group-types"> <ToolbarContent> - <Flex className="toolbar" direction={{default: "row"}} alignItems={{default:"alignItemsCenter"}}> - {isYaml && <FlexItem> - <ToggleGroup> - <ToggleGroupItem text="Design" buttonId="design" isSelected={mode === "design"} - onChange={s => this.props.setMode.call(this, "design")} /> - <ToggleGroupItem text="Code" buttonId="code" isSelected={mode === "code"} - onChange={s => this.props.setMode.call(this, "code")} /> - </ToggleGroup> - </FlexItem>} + <Flex className="toolbar" direction={{default: "row"}} alignItems={{default: "alignItemsCenter"}}> + {isYaml && <FlexItem> + <ToggleGroup> + <ToggleGroupItem text="Design" buttonId="design" isSelected={mode === "design"} + onChange={s => this.props.setMode.call(this, "design")}/> + <ToggleGroupItem text="Code" buttonId="code" isSelected={mode === "code"} + onChange={s => this.props.setMode.call(this, "code")}/> + </ToggleGroup> + </FlexItem>} - {isProperties && <FlexItem> - <Checkbox - id="advanced" - label="Edit advanced" - isChecked={editAdvancedProperties} - onChange={checked => setEditAdvancedProperties.call(this, checked)} - /> - </FlexItem>} - {isProperties && <FlexItem> - <Button isSmall variant="primary" icon={<PlusIcon/>} onClick={e => addProperty.call(this)}>Add property</Button> - </FlexItem>} + {isProperties && <FlexItem> + <Checkbox + id="advanced" + label="Edit advanced" + isChecked={editAdvancedProperties} + onChange={checked => setEditAdvancedProperties.call(this, checked)} + /> + </FlexItem>} + {isProperties && <FlexItem> + <Button isSmall variant="primary" icon={<PlusIcon/>} onClick={e => addProperty.call(this)}>Add property</Button> + </FlexItem>} - {isFile && <FlexItem> - <Tooltip content="Download source" position={"bottom-end"}> - <Button isSmall variant="control" icon={<DownloadIcon/>} onClick={e => download.call(this)}/> - </Tooltip> - </FlexItem>} - {isIntegration && <FlexItem> - <Tooltip content="Download image" position={"bottom-end"}> - <Button isSmall variant="control" icon={<DownloadImageIcon/>} onClick={e => downloadImage.call(this)}/> - </Tooltip> - </FlexItem>} - {!isFile && <FlexItem> - <Button isSmall variant={"secondary"} icon={<PlusIcon/>} - onClick={e => setCreateModalOpen.call(this)}>Create</Button> - </FlexItem>} - {!isFile && <FlexItem> - <Button isSmall variant="secondary" icon={<UploadIcon/>} - onClick={e => setUploadModalOpen.call(this)}>Upload</Button> - </FlexItem>} - {!isFile && <FlexItem> - <Tooltip content="Commit and push to git" position={"bottom-end"}> - <Button isLoading={isPushing ? true : undefined} - isSmall - variant={needCommit ? "primary" : "secondary"} - className="project-button" - icon={!isPushing ? <PushIcon/> : <div></div>} - onClick={e => this.push()}> - {isPushing ? "..." : "Commit"} - </Button> - </Tooltip> - </FlexItem>} - </Flex> + {isFile && <FlexItem> + <Tooltip content="Download source" position={"bottom-end"}> + <Button isSmall variant="control" icon={<DownloadIcon/>} onClick={e => download.call(this)}/> + </Tooltip> + </FlexItem>} + {isIntegration && <FlexItem> + <Tooltip content="Download image" position={"bottom-end"}> + <Button isSmall variant="control" icon={<DownloadImageIcon/>} onClick={e => downloadImage.call(this)}/> + </Tooltip> + </FlexItem>} + {!isFile && <FlexItem> + <Button isSmall variant={"secondary"} icon={<PlusIcon/>} + onClick={e => setCreateModalOpen.call(this)}>Create</Button> + </FlexItem>} + {!isFile && <FlexItem> + <Button isSmall variant="secondary" icon={<UploadIcon/>} + onClick={e => setUploadModalOpen.call(this)}>Upload</Button> + </FlexItem>} + {!isFile && <FlexItem> + <Tooltip content="Commit and push to git" position={"bottom-end"}> + <Button isLoading={isPushing ? true : undefined} + isSmall + variant={needCommit ? "primary" : "secondary"} + className="project-button" + icon={!isPushing ? <PushIcon/> : <div></div>} + onClick={() => this.setState({ + commitMessageIsOpen: true, + commitMessage : commitMessage === '' ? new Date().toLocaleString() : commitMessage + })}> + {isPushing ? "..." : "Commit"} + </Button> + </Tooltip> + </FlexItem>} + </Flex> </ToolbarContent> </Toolbar> } + getCommitModal() { + let {commitMessage, commitMessageIsOpen} = this.state; + return ( + <Modal + title="Commit" + variant={ModalVariant.small} + isOpen={commitMessageIsOpen} + onClose={() => this.setState({commitMessageIsOpen: false})} + actions={[ + <Button key="confirm" variant="primary" onClick={() => this.push()}>Save</Button>, + <Button key="cancel" variant="secondary" onClick={() => this.setState({commitMessageIsOpen: false})}>Cancel</Button> + ]} + > + <Form autoComplete="off" isHorizontal className="create-file-form"> + <FormGroup label="Message" fieldId="name" isRequired> + <TextInput value={commitMessage} onChange={value => this.setState({commitMessage: value})}/> + <FormHelperText isHidden={false} component="div"/> + </FormGroup> + </Form> + </Modal> + ) + } + render() { const {isTemplates} = this.props; return <div> {isTemplates && this.getTemplatesToolbar()} {!isTemplates && this.getProjectToolbar()} + {this.getCommitModal()} </div> } }