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

feat: Allow to select branch name when using the UI #1707

Merged
merged 4 commits into from
Jan 17, 2025
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
47 changes: 35 additions & 12 deletions ui/src/domain/Jobs/Create.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { React, useState, useEffect } from "react";
import { Form, Button, Select, Modal, Space, message } from "antd";
import {Form, Button, Select, Modal, Space, message, Input} from "antd";
import {
ORGANIZATION_ARCHIVE,
WORKSPACE_ARCHIVE,
Expand All @@ -19,6 +19,7 @@ export const CreateJob = ({ changeJob }) => {
const [visible, setVisible] = useState(false);
const [form] = Form.useForm();
const [templates, setTemplates] = useState([]);
const [branchName, setBranchName] = useState([]);
const [loading, setLoading] = useState(false);
const onCancel = () => {
setVisible(false);
Expand All @@ -27,30 +28,44 @@ export const CreateJob = ({ changeJob }) => {
useEffect(() => {
setLoading(true);
loadTemplates();
loadBranch();
}, [organizationId]);

const loadTemplates = () => {
const loadBranch = () => {
axiosInstance
.get(`organization/${organizationId}/template`)
.get(`organization/${organizationId}/workspace/${workspaceId}`)
.then((response) => {
var templatesList = response.data.data.filter(function (obj) {
//exclude CLI based templates
return (
obj.attributes.name !== "Terraform-Plan/Apply-Cli" &&
obj.attributes.name !== "Terraform-Plan/Destroy-Cli"
);
});
setTemplates(templatesList);
setLoading(false);
console.log(response.data);
console.log(response.data.data.attributes.branch);
var branchName = response.data.data.attributes.branch;
console.log("Default branch:" + branchName);
setBranchName(branchName);
});
};

const loadTemplates = () => {
axiosInstance
.get(`organization/${organizationId}/template`)
.then((response) => {
var templatesList = response.data.data.filter(function (obj) {
//exclude CLI based templates
return (
obj.attributes.name !== "Terraform-Plan/Apply-Cli" &&
obj.attributes.name !== "Terraform-Plan/Destroy-Cli"
);
});
setTemplates(templatesList);
setLoading(false);
});
};

const onCreate = (values) => {
const body = {
data: {
type: "job",
attributes: {
templateReference: values.templateId,
overrideBranch: values.branchName,
via: "UI",
},
relationships: {
Expand Down Expand Up @@ -152,6 +167,14 @@ export const CreateJob = ({ changeJob }) => {
</Select>
)}
</Form.Item>
<Form.Item
name="branchName"
label="Branch Name"
tooltip="Select the branch to use for this job. When using the CLI driven workflow do not modify the branch name."
initialValue={branchName}
>
<Input />
</Form.Item>
</Form>
</Space>
</Modal>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/domain/Workspaces/Details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ export const WorkspaceDetails = ({ setOrganizationName, selectedTab }) => {
>
{workspace.data.attributes.locked ? "Unlock" : "Lock"}
</Button>
<CreateJob changeJob={changeJob} />
<CreateJob changeJob={changeJob } />
</Space>
</>
}
Expand Down
Loading