|
|
@@ -12,6 +12,7 @@ import CheckboxRow from "components/form-components/CheckboxRow";
|
|
|
import { Environment, EnvironmentDeploymentMode } from "../types";
|
|
|
import SaveButton from "components/SaveButton";
|
|
|
import _ from "lodash";
|
|
|
+import TabRegion from "components/TabRegion";
|
|
|
import { Context } from "shared/Context";
|
|
|
import PageNotFound from "components/PageNotFound";
|
|
|
import Banner from "components/Banner";
|
|
|
@@ -33,6 +34,7 @@ const EnvironmentSettings = () => {
|
|
|
Context
|
|
|
);
|
|
|
const [selectedBranches, setSelectedBranches] = useState([]);
|
|
|
+ const [currentTab, setCurrentTab] = useState("pull-request");
|
|
|
const [environment, setEnvironment] = useState<Environment>();
|
|
|
const [saveStatus, setSaveStatus] = useState("");
|
|
|
const [newCommentsDisabled, setNewCommentsDisabled] = useState(false);
|
|
|
@@ -174,6 +176,55 @@ const EnvironmentSettings = () => {
|
|
|
setSaveStatus("");
|
|
|
};
|
|
|
|
|
|
+ const handleSavePullRequest = async () => {
|
|
|
+ let annotations: Record<string, string> = {};
|
|
|
+
|
|
|
+ setSaveStatus("loading");
|
|
|
+
|
|
|
+ namespaceAnnotations
|
|
|
+ .filter((elem: KeyValueType, index: number, self: KeyValueType[]) => {
|
|
|
+ // remove any collisions that are duplicates
|
|
|
+ let numCollisions = self.reduce((n, _elem: KeyValueType) => {
|
|
|
+ return n + (_elem.key === elem.key ? 1 : 0);
|
|
|
+ }, 0);
|
|
|
+
|
|
|
+ if (numCollisions == 1) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return (
|
|
|
+ index ===
|
|
|
+ self.findIndex((_elem: KeyValueType) => _elem.key === elem.key)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .forEach((elem: KeyValueType) => {
|
|
|
+ if (elem.key !== "" && elem.value !== "") {
|
|
|
+ annotations[elem.key] = elem.value;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ try {
|
|
|
+ await api.updateEnvironment(
|
|
|
+ "<token>",
|
|
|
+ {
|
|
|
+ mode: deploymentMode,
|
|
|
+ disable_new_comments: newCommentsDisabled,
|
|
|
+ git_repo_branches: selectedBranches,
|
|
|
+ namespace_annotations: annotations,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ project_id: currentProject.id,
|
|
|
+ cluster_id: currentCluster.id,
|
|
|
+ environment_id: Number(environmentId),
|
|
|
+ }
|
|
|
+ );
|
|
|
+ } catch (err) {
|
|
|
+ setCurrentError(err);
|
|
|
+ }
|
|
|
+
|
|
|
+ setSaveStatus("");
|
|
|
+ };
|
|
|
+
|
|
|
const closeDeleteConfirmationModal = () => {
|
|
|
setShowDeleteModal(false);
|
|
|
setDeleteConfirmationPrompt("");
|
|
|
@@ -211,6 +262,108 @@ const EnvironmentSettings = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const renderTabContents = () => {
|
|
|
+ if (currentTab === "additional-settings") {
|
|
|
+ return (
|
|
|
+ <StyledPlaceholder>
|
|
|
+ <Heading isAtTop>Delete preview environment</Heading>
|
|
|
+ <Helper>
|
|
|
+ Remove the Porter preview environment integration for this repo. All
|
|
|
+ associated preview deployments will also be destroyed.
|
|
|
+ </Helper>
|
|
|
+ <DeleteButton
|
|
|
+ disabled={saveStatus === "loading"}
|
|
|
+ onClick={() => {
|
|
|
+ setShowDeleteModal(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ Delete preview environment
|
|
|
+ </DeleteButton>
|
|
|
+ </StyledPlaceholder>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ if (currentTab === "advanced") {
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <StyledPlaceholder>
|
|
|
+ <Heading isAtTop>Allowed branches</Heading>
|
|
|
+ <Helper>
|
|
|
+ Only allow preview deployments for branches in this list. Leave
|
|
|
+ empty to allow all branches.
|
|
|
+ </Helper>
|
|
|
+ <BranchFilterSelector
|
|
|
+ onChange={setSelectedBranches}
|
|
|
+ options={availableBranches}
|
|
|
+ value={selectedBranches}
|
|
|
+ showLoading={isLoadingBranches}
|
|
|
+ />
|
|
|
+ <Br />
|
|
|
+ <Heading>Namespace annotations</Heading>
|
|
|
+ <Helper>
|
|
|
+ Custom annotations to be injected into the Kubernetes namespace
|
|
|
+ created for each deployment.
|
|
|
+ </Helper>
|
|
|
+ <NamespaceAnnotations
|
|
|
+ values={namespaceAnnotations}
|
|
|
+ setValues={(x: KeyValueType[]) => {
|
|
|
+ let annotations: KeyValueType[] = [];
|
|
|
+ x.forEach((entry) => {
|
|
|
+ annotations.push({ key: entry.key, value: entry.value });
|
|
|
+ });
|
|
|
+ setNamespaceAnnotations(annotations);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </StyledPlaceholder>
|
|
|
+ <SavePreviewEnvironmentSettings
|
|
|
+ text={"Save settings"}
|
|
|
+ status={saveStatus}
|
|
|
+ clearPosition={true}
|
|
|
+ statusPosition={"right"}
|
|
|
+ onClick={handleSave}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <StyledPlaceholder>
|
|
|
+ <Heading isAtTop>Pull request comment settings</Heading>
|
|
|
+ <Helper>
|
|
|
+ Update the most recent PR comment on every deploy. If disabled, a
|
|
|
+ new PR comment is made per deploy.
|
|
|
+ </Helper>
|
|
|
+ <CheckboxRow
|
|
|
+ label="Update the most recent PR comment"
|
|
|
+ checked={newCommentsDisabled}
|
|
|
+ toggle={() => setNewCommentsDisabled(!newCommentsDisabled)}
|
|
|
+ />
|
|
|
+ <Br />
|
|
|
+ <Heading>Automatic preview deployments</Heading>
|
|
|
+ <Helper>
|
|
|
+ When enabled, preview deployments are automatically created for all
|
|
|
+ new pull requests.
|
|
|
+ </Helper>
|
|
|
+ <CheckboxRow
|
|
|
+ label="Automatically create preview deployments"
|
|
|
+ checked={deploymentMode === "auto"}
|
|
|
+ toggle={() =>
|
|
|
+ setDeploymentMode((deploymentMode) =>
|
|
|
+ deploymentMode === "auto" ? "manual" : "auto"
|
|
|
+ )
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </StyledPlaceholder>
|
|
|
+ <SavePreviewEnvironmentSettings
|
|
|
+ text={"Save settings"}
|
|
|
+ status={saveStatus}
|
|
|
+ clearPosition={true}
|
|
|
+ statusPosition={"right"}
|
|
|
+ onClick={handleSavePullRequest}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
{showDeleteModal ? (
|
|
|
@@ -250,84 +403,17 @@ const EnvironmentSettings = () => {
|
|
|
environment.
|
|
|
</Banner>
|
|
|
</WarningBannerWrapper>
|
|
|
- <StyledPlaceholder>
|
|
|
- <Heading isAtTop>Pull request comment settings</Heading>
|
|
|
- <Helper>
|
|
|
- Update the most recent PR comment on every deploy. If disabled, a new
|
|
|
- PR comment is made per deploy.
|
|
|
- </Helper>
|
|
|
- <CheckboxRow
|
|
|
- label="Update the most recent PR comment"
|
|
|
- checked={newCommentsDisabled}
|
|
|
- toggle={() => setNewCommentsDisabled(!newCommentsDisabled)}
|
|
|
- />
|
|
|
- <Br />
|
|
|
- <Heading>Automatic preview deployments</Heading>
|
|
|
- <Helper>
|
|
|
- When enabled, preview deployments are automatically created for all
|
|
|
- new pull requests.
|
|
|
- </Helper>
|
|
|
- <CheckboxRow
|
|
|
- label="Automatically create preview deployments"
|
|
|
- checked={deploymentMode === "auto"}
|
|
|
- toggle={() =>
|
|
|
- setDeploymentMode((deploymentMode) =>
|
|
|
- deploymentMode === "auto" ? "manual" : "auto"
|
|
|
- )
|
|
|
- }
|
|
|
- />
|
|
|
- <Br />
|
|
|
- <Heading>Select allowed branches</Heading>
|
|
|
- <Helper>
|
|
|
- If the pull request has a base branch included in this list, it will
|
|
|
- be allowed to be deployed.
|
|
|
- <br />
|
|
|
- (Leave empty to allow all branches)
|
|
|
- </Helper>
|
|
|
- <BranchFilterSelector
|
|
|
- onChange={setSelectedBranches}
|
|
|
- options={availableBranches}
|
|
|
- value={selectedBranches}
|
|
|
- showLoading={isLoadingBranches}
|
|
|
- />
|
|
|
- <Br />
|
|
|
- <Heading>Namespace annotations</Heading>
|
|
|
- <Helper>
|
|
|
- Custom annotations to be injected into the Kubernetes namespace
|
|
|
- created for each deployment.
|
|
|
- </Helper>
|
|
|
- <NamespaceAnnotations
|
|
|
- values={namespaceAnnotations}
|
|
|
- setValues={(x: KeyValueType[]) => {
|
|
|
- let annotations: KeyValueType[] = [];
|
|
|
- x.forEach((entry) => {
|
|
|
- annotations.push({ key: entry.key, value: entry.value });
|
|
|
- });
|
|
|
- setNamespaceAnnotations(annotations);
|
|
|
- }}
|
|
|
- />
|
|
|
- <SavePreviewEnvironmentSettings
|
|
|
- text={"Save"}
|
|
|
- status={saveStatus}
|
|
|
- clearPosition={true}
|
|
|
- statusPosition={"right"}
|
|
|
- onClick={handleSave}
|
|
|
- />
|
|
|
- <Br />
|
|
|
- <Heading>Delete preview environment</Heading>
|
|
|
- <Helper>
|
|
|
- Delete the Porter preview environment integration for this repo. All
|
|
|
- preview deployments will also be destroyed.
|
|
|
- </Helper>
|
|
|
- <DeleteButton
|
|
|
- disabled={saveStatus === "loading"}
|
|
|
- onClick={() => {
|
|
|
- setShowDeleteModal(true);
|
|
|
- }}
|
|
|
- >
|
|
|
- Delete preview environment
|
|
|
- </DeleteButton>
|
|
|
- </StyledPlaceholder>
|
|
|
+ <TabRegion
|
|
|
+ currentTab={currentTab}
|
|
|
+ setCurrentTab={(x: string) => setCurrentTab(x)}
|
|
|
+ options={[
|
|
|
+ { value: "pull-request", label: "Pull request" },
|
|
|
+ { value: "advanced", label: "Advanced" },
|
|
|
+ { value: "additional-settings", label: "Additional settings" },
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ {renderTabContents()}
|
|
|
+ </TabRegion>
|
|
|
</>
|
|
|
);
|
|
|
};
|
|
|
@@ -480,5 +566,5 @@ const Breadcrumb = styled(DynamicLink)`
|
|
|
`;
|
|
|
|
|
|
const WarningBannerWrapper = styled.div`
|
|
|
- margin-block: 20px;
|
|
|
+ margin-bottom: 30px;
|
|
|
`;
|