-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Commit info consistent across screens
- Loading branch information
Showing
3 changed files
with
165 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
import ButtonGroup from "react-bootstrap/ButtonGroup"; | ||
import {ClipboardButton, LinkButton} from "../controls"; | ||
import {BrowserIcon, LinkIcon, PackageIcon, PlayIcon} from "@primer/octicons-react"; | ||
import Table from "react-bootstrap/Table"; | ||
import {MetadataRow, MetadataUIButton} from "../../../pages/repositories/repository/commits/commit/metadata"; | ||
import {Link} from "../nav"; | ||
import dayjs from "dayjs"; | ||
import Card from "react-bootstrap/Card"; | ||
import React from "react"; | ||
|
||
|
||
const CommitActions = ({ repo, commit }) => { | ||
|
||
const buttonVariant = "outline-dark"; | ||
|
||
return ( | ||
<div> | ||
<ButtonGroup className="commit-actions"> | ||
<LinkButton | ||
buttonVariant="outline-dark" | ||
href={{pathname: '/repositories/:repoId/objects', params: {repoId: repo.id}, query: {ref: commit.id}}} | ||
tooltip="Browse commit objects"> | ||
<BrowserIcon/> | ||
</LinkButton> | ||
<LinkButton | ||
buttonVariant={buttonVariant} | ||
href={{pathname: '/repositories/:repoId/actions', params: {repoId: repo.id}, query: {commit: commit.id}}} | ||
tooltip="View Commit Action runs"> | ||
<PlayIcon/> | ||
</LinkButton> | ||
<ClipboardButton variant={buttonVariant} text={commit.id} tooltip="Copy ID to clipboard"/> | ||
<ClipboardButton variant={buttonVariant} text={`lakefs://${repo.id}/${commit.id}`} tooltip="Copy URI to clipboard" icon={<LinkIcon/>}/> | ||
<ClipboardButton variant={buttonVariant} text={`s3://${repo.id}/${commit.id}`} tooltip="Copy S3 URI to clipboard" icon={<PackageIcon/>}/> | ||
</ButtonGroup> | ||
</div> | ||
); | ||
}; | ||
|
||
const getKeysOrNull = (metadata) => { | ||
if (!metadata) return null; | ||
const keys = Object.getOwnPropertyNames(metadata); | ||
if (keys.length === 0) return null; | ||
return keys; | ||
}; | ||
|
||
const CommitMetadataTable = ({ commit }) => { | ||
const keys = getKeysOrNull(commit.metadata); | ||
if (!keys) return null; | ||
|
||
return ( | ||
<> | ||
<Table> | ||
<thead> | ||
<tr> | ||
<th>Metadata Key</th> | ||
<th>Value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{keys.map(key => | ||
<MetadataRow metadata_key={key} metadata_value={commit.metadata[key]}/>)} | ||
</tbody> | ||
</Table> | ||
</> | ||
); | ||
}; | ||
|
||
const CommitMetadataUIButtons = ({ commit }) => { | ||
const keys = getKeysOrNull(commit.metadata); | ||
if (!keys) return null; | ||
|
||
return ( | ||
<>{ | ||
keys.map((key) => <MetadataUIButton metadata_key={key} metadata_value={commit.metadata[key]}/>) | ||
}</> | ||
); | ||
}; | ||
|
||
const CommitLink = ({ repoId, commitId }) => { | ||
return ( | ||
<> | ||
<Link href={{ | ||
pathname: '/repositories/:repoId/commits/:commitId', | ||
params: {repoId, commitId} | ||
}}> | ||
<code>{commitId}</code> | ||
</Link> | ||
<br/> | ||
</> | ||
); | ||
} | ||
|
||
const CommitInfo = ({ repo, commit }) => { | ||
return ( | ||
<Table size="sm" borderless hover> | ||
<tbody> | ||
<tr> | ||
<td><strong>ID</strong></td> | ||
<td> | ||
<CommitLink repoId={repo.id} commitId={commit.id}/> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><strong>Committer</strong></td> | ||
<td>{commit.committer}</td> | ||
</tr> | ||
<tr> | ||
<td><strong>Creation Date</strong></td> | ||
<td> | ||
{dayjs.unix(commit.creation_date).format("MM/DD/YYYY HH:mm:ss")} ({dayjs.unix(commit.creation_date).fromNow()}) | ||
</td> | ||
</tr> | ||
{(commit.parents) ? ( | ||
<tr> | ||
<td> | ||
<strong>Parents</strong></td> | ||
<td> | ||
{commit.parents.map(cid => ( | ||
<CommitLink key={cid} repoId={repo.id} commitId={cid}/> | ||
))} | ||
</td> | ||
</tr> | ||
) : <></>} | ||
</tbody> | ||
</Table> | ||
); | ||
}; | ||
|
||
export const CommitInfoCard = ({ repo, commit, bare = false }) => { | ||
const content = ( | ||
<> | ||
<div className="d-flex"> | ||
<div className="flex-grow-1"> | ||
<h4>{commit.message}</h4> | ||
</div> | ||
<div> | ||
<CommitActions repo={repo} commit={commit}/> | ||
</div> | ||
</div> | ||
|
||
<div className="mt-4"> | ||
<CommitInfo repo={repo} commit={commit}/> | ||
<CommitMetadataUIButtons commit={commit}/> | ||
<div className="mt-3"> | ||
<CommitMetadataTable commit={commit}/> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
if (bare) return content; | ||
return ( | ||
<Card> | ||
<Card.Body> | ||
{content} | ||
</Card.Body> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.