Skip to content

Commit

Permalink
feat: use commit hash to link to commit
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-stoyanov committed Mar 6, 2021
1 parent c3a88a8 commit 4c1f2c9
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions ui/blocks/src/ComponentCommits/BaseComponentCommits.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
/* eslint-disable react/display-name */
/** @jsx jsx */
import { FC, useMemo } from 'react';
import { FC, Fragment, useMemo } from 'react';
import { jsx } from 'theme-ui';
import { Column } from 'react-table';
import { Table, TableProps } from '@component-controls/components';
import { useConfig } from '@component-controls/store';
import { GitCommitIcon } from '@primer/octicons-react';
import {
ExternalLink,
Table,
TableProps,
} from '@component-controls/components';
import { useConfig, usePackage } from '@component-controls/store';
import { Commit, Component, dateToLocalString } from '@component-controls/core';
import { GithubAvatar } from '@component-controls/components';

Expand All @@ -23,7 +28,11 @@ export const BaseComponentCommits: FC<BaseComponentCommitsProps> = ({
const config = useConfig();
const { tokens } = config;

console.log(component);
const componentPackage = usePackage(component?.package);
const baseGitURL = componentPackage?.repository?.issues?.replace(
'issues',
'commit',
);

const columns = useMemo(
() =>
Expand Down Expand Up @@ -66,12 +75,26 @@ export const BaseComponentCommits: FC<BaseComponentCommitsProps> = ({
accessor: 'subject',
Cell: ({
row: {
original: { subject },
original: { subject, hash },
},
}) => <p>{subject}</p>,
}) => (
<Fragment>
<span sx={{ mr: 1 }}>{subject}</span>
{baseGitURL && hash && (
<span>
<ExternalLink
href={`${baseGitURL}/${hash}`}
aria-label="View commit on GitHub"
>
<GitCommitIcon size={16} />
</ExternalLink>
</span>
)}
</Fragment>
),
},
] as Column<Commit>[],
[],
[baseGitURL, tokens?.githubAccessToken],
);

if (!component?.fileInfo?.commits) {
Expand Down

0 comments on commit 4c1f2c9

Please sign in to comment.