displaying shortened git commit hash

This commit is contained in:
biersoeckli
2024-11-15 09:49:20 +00:00
parent 9d0a539aa3
commit d67e5e75c0
3 changed files with 15 additions and 3 deletions

View File

@@ -18,6 +18,7 @@ import DeploymentStatusBadge from "./deployment-status-badge";
import { io } from "socket.io-client";
import { podLogsSocket } from "@/lib/sockets";
import { BuildLogsDialog } from "./build-logs-overlay";
import ShortCommitHash from "@/components/custom/short-commit-hash";
export default function BuildsTab({
app
@@ -86,7 +87,7 @@ export default function BuildsTab({
['buildJobName', 'Build Job Name', false],
['status', 'Status', true, (item) => <DeploymentStatusBadge>{item.status}</DeploymentStatusBadge>],
["startTime", "Started At", true, (item) => formatDateTime(item.createdAt)],
['gitCommit', 'Git Commit', true],
['gitCommit', 'Git Commit', true, (item) => <ShortCommitHash>{item.gitCommit}</ShortCommitHash>],
]}
data={appBuilds}
hideSearchBar={true}

View File

@@ -2,12 +2,12 @@
import { toast } from "sonner";
export function Code({ children, copieable = true }: { children: string | null | undefined, copieable?: boolean }) {
export function Code({ children, copieable = true, copieableValue }: { children: string | null | undefined, copieable?: boolean, copieableValue?: string }) {
return (children &&
<code className={'relative rounded bg-muted px-[0.3rem] py-[0.2rem] font-mono text-sm font-semibold ' + (copieable ? 'cursor-pointer' : '')}
onClick={() => {
if (!copieable) return;
navigator.clipboard.writeText(children || '');
navigator.clipboard.writeText(copieableValue || children || '');
toast.success('Copied to clipboard');
}}>
{children}

View File

@@ -0,0 +1,11 @@
import React from 'react';
import { Code } from './code';
export default function ShortCommitHash({ children }: { children?: string }) {
const shortHash = children ? children.slice(0, 7) : '';
if (!shortHash) {
return <></>;
}
return (<Code copieableValue={children}>{shortHash}</Code>);
};