Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Commit info consistent across screens #6593

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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()})
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is not knew but we should use localized date/time formats.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we should. Feel free to open an issue :)

</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 { 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 @@ -259,7 +260,7 @@
};


const CommitMetadata = ({ metadata }) => {

Check warning on line 263 in webui/src/lib/components/repository/tree.jsx

View workflow job for this annotation

GitHub Actions / Analyze

'CommitMetadata' is assigned a value but never used

Check warning on line 263 in webui/src/lib/components/repository/tree.jsx

View workflow job for this annotation

GitHub Actions / Test React App

'CommitMetadata' is assigned a value but never used
const entries = Object.entries(metadata);
if (entries.length === 0) {
// empty state
Expand Down Expand Up @@ -307,69 +308,7 @@
}
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
Loading