Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion app/client/src/git/ce/constants/messages.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const OPS_MODAL = {
TAB_RELEASE: "RELEASE",
TAB_RELEASE: "Release",
};

export const TAB_RELEASE = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("LatestCommitInfoView", () => {
});

it("renders correctly with null authorName", () => {
const { getByText } = render(
const { getByText, queryByTestId } = render(
<LatestCommitInfoView
authorName={null}
committedAt="2025-03-01"
Expand All @@ -29,9 +29,8 @@ describe("LatestCommitInfoView", () => {
/>,
);

expect(queryByTestId("t--git-release-released-at")).not.toBeInTheDocument();
expect(getByText("Initial commit")).toBeInTheDocument();
expect(getByText("- committed 2025-03-01")).toBeInTheDocument();
expect(getByText("abc123")).toBeInTheDocument();
});

it("renders correctly with null committedAt", () => {
Expand All @@ -45,8 +44,7 @@ describe("LatestCommitInfoView", () => {
);

expect(getByText("Initial commit")).toBeInTheDocument();
expect(getByText("John Doe committed -")).toBeInTheDocument();
expect(getByText("abc123")).toBeInTheDocument();
expect(getByText("Committed by John Doe")).toBeInTheDocument();
});

it("renders correctly with null hash", () => {
Expand All @@ -61,7 +59,6 @@ describe("LatestCommitInfoView", () => {

expect(getByText("Initial commit")).toBeInTheDocument();
expect(getByText("John Doe committed 2025-03-01")).toBeInTheDocument();
expect(getByText("-")).toBeInTheDocument();
});

it("renders correctly with null message", () => {
Expand All @@ -79,7 +76,7 @@ describe("LatestCommitInfoView", () => {
});

it("renders correctly with all null props", () => {
const { getByText } = render(
const { queryByTestId } = render(
<LatestCommitInfoView
authorName={null}
committedAt={null}
Expand All @@ -88,7 +85,6 @@ describe("LatestCommitInfoView", () => {
/>,
);

expect(getByText("- committed -")).toBeInTheDocument();
expect(getByText("-")).toBeInTheDocument();
expect(queryByTestId("t--git-release-released-at")).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ function LatestCommitInfoView({
return (
<Container marginBottom="spaces-4" padding="spaces-3">
<Flex flex={1} flexDirection="column" gap="spaces-3">
<Text renderAs="p">{message}</Text>
<Text renderAs="p">{message ?? "My latest commit message"}</Text>
<Text kind="body-s" renderAs="p">
{authorName ?? "-"} committed {committedAt ?? "-"}
{authorName && !committedAt ? `Committed by ${authorName}` : null}
{authorName && committedAt
? `${authorName} committed ${committedAt ?? "-"}`
: null}
</Text>
</Flex>
<Flex alignItems="center" justifyContent="center">
Expand Down
16 changes: 10 additions & 6 deletions app/client/src/git/components/LatestCommitInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import React from "react";
import LatestCommitInfoView from "./LatestCommitInfoView";
import useLatestCommit from "git/hooks/useLatestCommit";
import usePretag from "git/hooks/usePretag";

function LatestCommitInfo() {
const { latestCommit } = useLatestCommit();
const { pretagResponse } = usePretag();

const commitHash = pretagResponse?.hash
? pretagResponse.hash.slice(0, 7)
: null;

return (
<LatestCommitInfoView
authorName={latestCommit?.authorName ?? null}
committedAt={latestCommit?.committedAt ?? null}
hash={latestCommit?.hash ?? null}
message={latestCommit?.message ?? null}
authorName={pretagResponse?.author.name ?? null}
committedAt={pretagResponse?.committedAt ?? null}
hash={commitHash}
message={pretagResponse?.message ?? null}
/>
);
}
Expand Down
20 changes: 20 additions & 0 deletions app/client/src/git/components/OpsModal/OpsModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import styled from "styled-components";
// import ReconnectSSHError from "../components/ReconnectSSHError";
import { GitOpsTab } from "git/constants/enums";
import noop from "lodash/noop";
import isGitTaggingEnabled from "git/helpers/isGitTaggingEnabled";
import type { GitArtifactDef } from "git/types";
import TabRelease from "./TabRelease";
import { OPS_MODAL } from "git/ee/constants/messages";

const StyledModalContent = styled(ModalContent)`
&&& {
Expand All @@ -27,6 +31,7 @@ const StyledModalContent = styled(ModalContent)`
`;

interface OpsModalViewProps {
artifactDef: GitArtifactDef | null;
fetchStatus: () => void;
isOpsModalOpen: boolean;
isProtectedMode: boolean;
Expand All @@ -36,13 +41,16 @@ interface OpsModalViewProps {
}

function OpsModalView({
artifactDef = null,
fetchStatus = noop,
isOpsModalOpen = false,
isProtectedMode = false,
opsModalTab = GitOpsTab.Deploy,
repoName = null,
toggleOpsModal = noop,
}: OpsModalViewProps) {
const isTaggingEnabled = isGitTaggingEnabled(artifactDef);

useEffect(
function fetchStatusOnMountEffect() {
if (isOpsModalOpen) {
Expand Down Expand Up @@ -91,10 +99,22 @@ function OpsModalView({
>
{createMessage(MERGE)}
</Tab>
{isTaggingEnabled && (
<Tab
data-testid={"t--git-ops-tab-tag"}
disabled={isProtectedMode}
value={GitOpsTab.Release}
>
{OPS_MODAL.TAB_RELEASE}
</Tab>
)}
</TabsList>
</Tabs>
{opsModalTab === GitOpsTab.Deploy && <TabDeploy />}
{opsModalTab === GitOpsTab.Merge && <TabMerge />}
{isTaggingEnabled && opsModalTab === GitOpsTab.Release && (
<TabRelease />
)}
</StyledModalContent>
</Modal>
{/* <GitErrorPopup /> */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import LatestCommitInfo from "git/components/LatestCommitInfo";
import ReleaseNotesInput from "git/components/ReleaseNotesInput";
import ReleaseVersionRadioGroup from "git/components/ReleaseVersionRadioGroup";
import { TAB_RELEASE } from "git/ee/constants/messages";
import React, { useCallback, useState } from "react";
import noop from "lodash/noop";
import React, { useCallback, useEffect, useState } from "react";
import styled from "styled-components";

const Container = styled.div`
Expand All @@ -21,13 +22,42 @@ const StyledModalFooter = styled(ModalFooter)`
min-height: 52px;
`;

function TabRelease() {
interface TabReleaseProps {
fetchPretag: () => void;
createReleaseTag: (params: {
tag: string;
releaseNote: string;
commitSHA: string;
}) => void;
isCreateReleaseTagLoading: boolean;
latestCommitSHA: string | null;
}

function TabReleaseView({
createReleaseTag = noop,
fetchPretag = noop,
isCreateReleaseTagLoading = false,
latestCommitSHA = null,
}: TabReleaseProps) {
const [releaseVersion, setReleaseVersion] = useState<string | null>(null);
const [releaseNotes, setReleaseNotes] = useState<string | null>(null);

const isReleaseDisabled = !releaseVersion || !releaseNotes;

const handleClickOnRelease = useCallback(() => {}, []);
useEffect(
function fetchPretagOnInitEffect() {
fetchPretag();
},
[fetchPretag],
);

const handleClickOnRelease = useCallback(() => {
createReleaseTag({
tag: releaseVersion ?? "",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check for the presence of releaseVersion and then only dispatch this action?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that would silently fail without an error :(
Will be hard to debug

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can throw an error but would making this call with empty releaseVersion would also throw an error then we are fine but throwing error early would be pre-emptive

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The api will throw an error in this case
Also, the button is disabled when these values are not available. So, I don't think this case will ever get realised.
Had to add nullish coalescing because typescript

releaseNote: releaseNotes ?? "",
commitSHA: latestCommitSHA ?? "",
});
}, [createReleaseTag, latestCommitSHA, releaseNotes, releaseVersion]);

return (
<>
Expand All @@ -47,6 +77,7 @@ function TabRelease() {
<StyledModalFooter>
<Button
isDisabled={isReleaseDisabled}
isLoading={isCreateReleaseTagLoading}
onClick={handleClickOnRelease}
size="md"
>
Expand All @@ -57,4 +88,4 @@ function TabRelease() {
);
}

export default TabRelease;
export default TabReleaseView;
22 changes: 22 additions & 0 deletions app/client/src/git/components/OpsModal/TabRelease/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";
import TabReleaseView from "./TabReleaseView";
import usePretag from "git/hooks/usePretag";
import useReleaseTag from "git/hooks/useReleaseTag";

function TabRelease() {
const { fetchPretag, pretagResponse } = usePretag();
const { createReleaseTag, isCreateReleaseTagLoading } = useReleaseTag();

const latestCommitSHA = pretagResponse?.hash ?? null;

return (
<TabReleaseView
createReleaseTag={createReleaseTag}
fetchPretag={fetchPretag}
isCreateReleaseTagLoading={isCreateReleaseTagLoading}
latestCommitSHA={latestCommitSHA}
/>
);
}

export default TabRelease;
3 changes: 3 additions & 0 deletions app/client/src/git/components/OpsModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import useStatus from "git/hooks/useStatus";
import useOps from "git/hooks/useOps";
import useProtectedMode from "git/hooks/useProtectedMode";
import { GitOpsTab } from "git/constants/enums";
import { useGitContext } from "../GitContextProvider";

export default function OpsModal() {
const { artifactDef } = useGitContext();
const { isOpsModalOpen, opsModalTab, toggleOpsModal } = useOps();
const { fetchStatus } = useStatus();
const isProtectedMode = useProtectedMode();
Expand All @@ -17,6 +19,7 @@ export default function OpsModal() {

return (
<OpsModalView
artifactDef={artifactDef}
fetchStatus={fetchStatus}
isOpsModalOpen={isOpsModalOpen}
isProtectedMode={isProtectedMode}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("ReleaseVersionRadioGroupView", () => {
const renderComponent = (props = {}) => {
return render(
<ReleaseVersionRadioGroupView
currentVersion="1.0.0"
latestReleaseVersion="1.0.0"
onVersionChange={mockOnVersionChange}
releasedAt="2023-01-01"
{...props}
Expand Down Expand Up @@ -59,14 +59,12 @@ describe("ReleaseVersionRadioGroupView", () => {
expect(mockOnVersionChange).toHaveBeenCalledWith("2.0.0");
});

it("should handle null values for currentVersion and releasedAt", () => {
const { getByTestId } = renderComponent({
currentVersion: null,
it("should handle null values for latestReleaseVersion and releasedAt", () => {
const { queryByTestId } = renderComponent({
latestReleaseVersion: null,
releasedAt: null,
});

expect(getByTestId("t--git-release-released-at").textContent).toBe(
"Last released: - (-)",
);
expect(queryByTestId("t--git-release-released-at")).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import noop from "lodash/noop";
type ReleaseType = "major" | "minor" | "patch" | null;

interface ReleaseVersionRadioGroupViewProps {
currentVersion: string | null;
latestReleaseVersion: string | null;
onVersionChange: (value: string | null) => void;
releasedAt: string | null;
}

function ReleaseVersionRadioGroupView({
currentVersion = null,
latestReleaseVersion = null,
onVersionChange = noop,
releasedAt = null,
}: ReleaseVersionRadioGroupViewProps) {
const [releaseType, setReleaseType] = useState<ReleaseType>("patch");

const nextVersion = useMemo(() => {
if (!currentVersion || !releaseType) return null;
if (!releaseType) return null;

return inc(currentVersion, releaseType);
}, [currentVersion, releaseType]);
return inc(latestReleaseVersion ?? "0.0.0", releaseType);
}, [latestReleaseVersion, releaseType]);

useEffect(
function releaseVersionChangeEffect() {
Expand Down Expand Up @@ -62,10 +62,16 @@ function ReleaseVersionRadioGroupView({
<Radio value="patch">Patch</Radio>
</RadioGroup>
</Flex>
<Text data-testid="t--git-release-released-at" kind="body-s" renderAs="p">
{RELEASE_VERSION_RADIO_GROUP.LAST_RELEASED}: {currentVersion ?? "-"} (
{releasedAt ?? "-"})
</Text>
{latestReleaseVersion && (
<Text
data-testid="t--git-release-released-at"
kind="body-s"
renderAs="p"
>
{RELEASE_VERSION_RADIO_GROUP.LAST_RELEASED}:{" "}
{latestReleaseVersion ?? "-"} ({releasedAt ?? "-"})
</Text>
)}
</Flex>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import ReleaseVersionRadioGroupView from "./ReleaseVersionRadioGroupView";
import noop from "lodash/noop";
import useLatestCommit from "git/hooks/useLatestCommit";
import usePretag from "git/hooks/usePretag";

interface ReleaseVersionRadioGroupProps {
onVersionChange: (version: string | null) => void;
Expand All @@ -10,13 +10,13 @@ interface ReleaseVersionRadioGroupProps {
function ReleaseVersionRadioGroup({
onVersionChange = noop,
}: ReleaseVersionRadioGroupProps) {
const { latestCommit } = useLatestCommit();
const { pretagResponse } = usePretag();

return (
<ReleaseVersionRadioGroupView
currentVersion={latestCommit?.releaseTagName ?? null}
latestReleaseVersion={pretagResponse?.releaseTagName ?? null}
onVersionChange={onVersionChange}
releasedAt={latestCommit?.releasedAt ?? null}
releasedAt={pretagResponse?.releasedAt ?? null}
/>
);
}
Expand Down
12 changes: 12 additions & 0 deletions app/client/src/git/helpers/isGitTaggingEnabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GitArtifactType } from "git/constants/enums";
import type { GitArtifactDef } from "git/types";

function isGitTaggingEnabled(artifactDef: GitArtifactDef | null) {
if (artifactDef?.artifactType === GitArtifactType.Package) {
return true;
}

return false;
}

export default isGitTaggingEnabled;
Loading