mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-29 22:58:49 +00:00
feat: increase commit message truncation length and simplify truncation logic
- Updated the maximum character length for commit message truncation from 150 to 200 characters. - Simplified the truncation logic by removing unnecessary checks and consolidating the function to focus solely on the new maximum length. - Enhanced the display logic for deployment titles to ensure better readability and user experience.
This commit is contained in:
@@ -92,39 +92,21 @@ export const ShowDeployments = ({
|
|||||||
new Set(),
|
new Set(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Maximum character length before truncating commit messages
|
const MAX_DESCRIPTION_LENGTH = 200;
|
||||||
const MAX_DESCRIPTION_LENGTH = 150;
|
|
||||||
|
|
||||||
// Helper function to truncate description intelligently
|
const truncateDescription = (description: string): string => {
|
||||||
const truncateDescription = (
|
if (description.length <= MAX_DESCRIPTION_LENGTH) {
|
||||||
description: string,
|
|
||||||
maxLength: number,
|
|
||||||
): string => {
|
|
||||||
if (maxLength <= 0) {
|
|
||||||
return description; // Don't truncate if maxLength is 0 or negative
|
|
||||||
}
|
|
||||||
if (description.length <= maxLength) {
|
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
// Try to truncate at a word boundary if possible
|
const truncated = description.slice(0, MAX_DESCRIPTION_LENGTH);
|
||||||
const truncated = description.slice(0, maxLength);
|
|
||||||
const lastSpace = truncated.lastIndexOf(" ");
|
const lastSpace = truncated.lastIndexOf(" ");
|
||||||
// If we find a space near the end (within last 20 chars), use it for cleaner truncation
|
// Truncate at word boundary if found near the end
|
||||||
if (lastSpace > maxLength - 20 && lastSpace > 0) {
|
if (lastSpace > MAX_DESCRIPTION_LENGTH - 20 && lastSpace > 0) {
|
||||||
return `${truncated.slice(0, lastSpace)}...`;
|
return `${truncated.slice(0, lastSpace)}...`;
|
||||||
}
|
}
|
||||||
return `${truncated}...`;
|
return `${truncated}...`;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if description should be truncated
|
|
||||||
const shouldTruncate = (description: string): boolean => {
|
|
||||||
// Only truncate if MAX_DESCRIPTION_LENGTH is greater than 0
|
|
||||||
if (MAX_DESCRIPTION_LENGTH <= 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return description.length > MAX_DESCRIPTION_LENGTH;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Toggle expand/collapse state for a specific deployment
|
// Toggle expand/collapse state for a specific deployment
|
||||||
const toggleDescription = (deploymentId: string) => {
|
const toggleDescription = (deploymentId: string) => {
|
||||||
setExpandedDescriptions((prev) => {
|
setExpandedDescriptions((prev) => {
|
||||||
@@ -274,165 +256,158 @@ export const ShowDeployments = ({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
{deployments?.map((deployment, index) => (
|
{deployments?.map((deployment, index) => {
|
||||||
<div
|
const titleText = deployment?.title?.trim() || "";
|
||||||
key={deployment.deploymentId}
|
const needsTruncation = titleText.length > MAX_DESCRIPTION_LENGTH;
|
||||||
className="flex items-center justify-between rounded-lg border p-4 gap-2"
|
const isExpanded = expandedDescriptions.has(
|
||||||
>
|
deployment.deploymentId,
|
||||||
<div className="flex flex-col">
|
);
|
||||||
<span className="flex items-center gap-4 font-medium capitalize text-foreground">
|
|
||||||
{index + 1}. {deployment.status}
|
|
||||||
<StatusTooltip
|
|
||||||
status={deployment?.status}
|
|
||||||
className="size-2.5"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
{(() => {
|
|
||||||
// The commit message is in the title field, so we truncate that
|
|
||||||
const titleText = deployment.title.trim();
|
|
||||||
const needsTruncation = shouldTruncate(titleText);
|
|
||||||
const isExpanded = expandedDescriptions.has(
|
|
||||||
deployment.deploymentId,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-1">
|
<div
|
||||||
{/* Commit message (from title) - truncated */}
|
key={deployment.deploymentId}
|
||||||
<span className="break-words text-sm text-muted-foreground whitespace-pre-wrap">
|
className="flex items-center justify-between rounded-lg border p-4 gap-2"
|
||||||
{isExpanded || !needsTruncation
|
>
|
||||||
? titleText
|
<div className="flex flex-col">
|
||||||
: truncateDescription(
|
<span className="flex items-center gap-4 font-medium capitalize text-foreground">
|
||||||
titleText,
|
{index + 1}. {deployment.status}
|
||||||
MAX_DESCRIPTION_LENGTH,
|
<StatusTooltip
|
||||||
)}
|
status={deployment?.status}
|
||||||
</span>
|
className="size-2.5"
|
||||||
{needsTruncation && (
|
/>
|
||||||
<button
|
</span>
|
||||||
type="button"
|
|
||||||
onClick={() =>
|
|
||||||
toggleDescription(deployment.deploymentId)
|
|
||||||
}
|
|
||||||
className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit mt-1 cursor-pointer"
|
|
||||||
aria-label={
|
|
||||||
isExpanded
|
|
||||||
? "Collapse commit message"
|
|
||||||
: "Expand commit message"
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{isExpanded ? (
|
|
||||||
<>
|
|
||||||
<ChevronUp className="size-3" />
|
|
||||||
Show less
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<ChevronDown className="size-3" />
|
|
||||||
Show more
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
{/* Hash (from description) - shown in compact form */}
|
|
||||||
{deployment.description &&
|
|
||||||
deployment.description.trim() && (
|
|
||||||
<span className="text-xs text-muted-foreground font-mono">
|
|
||||||
{deployment.description}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})()}
|
|
||||||
</div>
|
|
||||||
<div className="flex flex-col items-end gap-2">
|
|
||||||
<div className="text-sm capitalize text-muted-foreground flex items-center gap-2">
|
|
||||||
<DateTooltip date={deployment.createdAt} />
|
|
||||||
{deployment.startedAt && deployment.finishedAt && (
|
|
||||||
<Badge
|
|
||||||
variant="outline"
|
|
||||||
className="text-[10px] gap-1 flex items-center"
|
|
||||||
>
|
|
||||||
<Clock className="size-3" />
|
|
||||||
{formatDuration(
|
|
||||||
Math.floor(
|
|
||||||
(new Date(deployment.finishedAt).getTime() -
|
|
||||||
new Date(deployment.startedAt).getTime()) /
|
|
||||||
1000,
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex flex-row items-center gap-2">
|
<div className="flex flex-col gap-1">
|
||||||
{deployment.pid && deployment.status === "running" && (
|
<span className="break-words text-sm text-muted-foreground whitespace-pre-wrap">
|
||||||
<DialogAction
|
{isExpanded || !needsTruncation
|
||||||
title="Kill Process"
|
? titleText
|
||||||
description="Are you sure you want to kill the process?"
|
: truncateDescription(titleText)}
|
||||||
type="default"
|
</span>
|
||||||
onClick={async () => {
|
{needsTruncation && (
|
||||||
await killProcess({
|
<button
|
||||||
deploymentId: deployment.deploymentId,
|
type="button"
|
||||||
})
|
onClick={() =>
|
||||||
.then(() => {
|
toggleDescription(deployment.deploymentId)
|
||||||
toast.success("Process killed successfully");
|
}
|
||||||
})
|
className="flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit mt-1 cursor-pointer"
|
||||||
.catch(() => {
|
aria-label={
|
||||||
toast.error("Error killing process");
|
isExpanded
|
||||||
});
|
? "Collapse commit message"
|
||||||
}}
|
: "Expand commit message"
|
||||||
>
|
}
|
||||||
<Button
|
|
||||||
variant="destructive"
|
|
||||||
size="sm"
|
|
||||||
isLoading={isKillingProcess}
|
|
||||||
>
|
>
|
||||||
Kill Process
|
{isExpanded ? (
|
||||||
</Button>
|
<>
|
||||||
</DialogAction>
|
<ChevronUp className="size-3" />
|
||||||
)}
|
Show less
|
||||||
<Button
|
</>
|
||||||
onClick={() => {
|
) : (
|
||||||
setActiveLog(deployment);
|
<>
|
||||||
}}
|
<ChevronDown className="size-3" />
|
||||||
>
|
Show more
|
||||||
View
|
</>
|
||||||
</Button>
|
)}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{/* Hash (from description) - shown in compact form */}
|
||||||
|
{deployment.description?.trim() && (
|
||||||
|
<span className="text-xs text-muted-foreground font-mono">
|
||||||
|
{deployment.description}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col items-end gap-2 max-w-[300px] w-full justify-start">
|
||||||
|
<div className="text-sm capitalize text-muted-foreground flex items-center gap-2">
|
||||||
|
<DateTooltip date={deployment.createdAt} />
|
||||||
|
{deployment.startedAt && deployment.finishedAt && (
|
||||||
|
<Badge
|
||||||
|
variant="outline"
|
||||||
|
className="text-[10px] gap-1 flex items-center"
|
||||||
|
>
|
||||||
|
<Clock className="size-3" />
|
||||||
|
{formatDuration(
|
||||||
|
Math.floor(
|
||||||
|
(new Date(deployment.finishedAt).getTime() -
|
||||||
|
new Date(deployment.startedAt).getTime()) /
|
||||||
|
1000,
|
||||||
|
),
|
||||||
|
)}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{deployment?.rollback &&
|
<div className="flex flex-row items-center gap-2">
|
||||||
deployment.status === "done" &&
|
{deployment.pid && deployment.status === "running" && (
|
||||||
type === "application" && (
|
|
||||||
<DialogAction
|
<DialogAction
|
||||||
title="Rollback to this deployment"
|
title="Kill Process"
|
||||||
description="Are you sure you want to rollback to this deployment?"
|
description="Are you sure you want to kill the process?"
|
||||||
type="default"
|
type="default"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await rollback({
|
await killProcess({
|
||||||
rollbackId: deployment.rollback.rollbackId,
|
deploymentId: deployment.deploymentId,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
toast.success(
|
toast.success("Process killed successfully");
|
||||||
"Rollback initiated successfully",
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
toast.error("Error initiating rollback");
|
toast.error("Error killing process");
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="destructive"
|
||||||
size="sm"
|
size="sm"
|
||||||
isLoading={isRollingBack}
|
isLoading={isKillingProcess}
|
||||||
>
|
>
|
||||||
<RefreshCcw className="size-4 text-primary group-hover:text-red-500" />
|
Kill Process
|
||||||
Rollback
|
|
||||||
</Button>
|
</Button>
|
||||||
</DialogAction>
|
</DialogAction>
|
||||||
)}
|
)}
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setActiveLog(deployment);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
View
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
{deployment?.rollback &&
|
||||||
|
deployment.status === "done" &&
|
||||||
|
type === "application" && (
|
||||||
|
<DialogAction
|
||||||
|
title="Rollback to this deployment"
|
||||||
|
description="Are you sure you want to rollback to this deployment?"
|
||||||
|
type="default"
|
||||||
|
onClick={async () => {
|
||||||
|
await rollback({
|
||||||
|
rollbackId: deployment.rollback.rollbackId,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
toast.success(
|
||||||
|
"Rollback initiated successfully",
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
toast.error("Error initiating rollback");
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
isLoading={isRollingBack}
|
||||||
|
>
|
||||||
|
<RefreshCcw className="size-4 text-primary group-hover:text-red-500" />
|
||||||
|
Rollback
|
||||||
|
</Button>
|
||||||
|
</DialogAction>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
))}
|
})}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<ShowDeployment
|
<ShowDeployment
|
||||||
|
|||||||
Reference in New Issue
Block a user