Skip to content

Commit

Permalink
UI: Commit info consistent across screens (#6593)
Browse files Browse the repository at this point in the history
  • Loading branch information
ozkatz authored Sep 14, 2023
1 parent aa755c0 commit a2f0ed4
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 207 deletions.
158 changes: 158 additions & 0 deletions webui/src/lib/components/repository/commits.jsx
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>
)
}
65 changes: 2 additions & 63 deletions webui/src/lib/components/repository/tree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Modal from "react-bootstrap/Modal";
import { useAPI } from "../../hooks/api";
import noop from "lodash/noop";
import {FaDownload} from "react-icons/fa";
import {CommitInfoCard} from "./commits";

export const humanSize = (bytes) => {
if (!bytes) return "0.0 B";
Expand Down Expand Up @@ -307,69 +308,7 @@ const OriginModal = ({ show, onHide, entry, repo, reference }) => {
}
if (!loading && !error && commit) {
content = (
<>
<Table hover responsive>
<tbody>
<tr>
<td>
<strong>Path</strong>
</td>
<td>
<code>{entry.path}</code>
</td>
</tr>
<tr>
<td>
<strong>Commit ID</strong>
</td>
<td>
<Link
className="me-2"
href={{
pathname: "/repositories/:repoId/commits/:commitId",
params: { repoId: repo.id, commitId: commit.id },
}}
>
<code>{commit.id}</code>
</Link>
</td>
</tr>
<tr>
<td>
<strong>Commit Message</strong>
</td>
<td>{commit.message}</td>
</tr>
<tr>
<td>
<strong>Committed By</strong>
</td>
<td>{commit.committer}</td>
</tr>
<tr>
<td>
<strong>Created At</strong>
</td>
<td>
<>
{dayjs
.unix(commit.creation_date)
.format("MM/DD/YYYY HH:mm:ss")}
</>{" "}
({dayjs.unix(commit.creation_date).fromNow()})
</td>
</tr>
<tr>
<td>
<strong>Metadata</strong>
</td>
<td>
<CommitMetadata metadata={commit.metadata} />
</td>
</tr>
</tbody>
</Table>
</>
<CommitInfoCard bare={true} repo={repo} commit={commit}/>
);
}

Expand Down
Loading

0 comments on commit a2f0ed4

Please sign in to comment.