-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create BaseComponentCommits component and display it when user …
…hovers over commits
- Loading branch information
1 parent
fa9d15d
commit 65fce22
Showing
5 changed files
with
174 additions
and
91 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,95 @@ | ||
/* eslint-disable react/display-name */ | ||
/** @jsx jsx */ | ||
import { FC, 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 { Commit, Component, dateToLocalString } from '@component-controls/core'; | ||
import { GithubAvatar } from '@component-controls/components'; | ||
|
||
export type BaseComponentCommitsProps = { | ||
component?: Component; | ||
pagination?: TableProps<Commit>['pagination']; | ||
}; | ||
|
||
/** | ||
* Displays commit history for a component | ||
*/ | ||
export const BaseComponentCommits: FC<BaseComponentCommitsProps> = ({ | ||
component, | ||
pagination = true, | ||
}) => { | ||
const config = useConfig(); | ||
const { tokens } = config; | ||
|
||
console.log(component); | ||
|
||
const columns = useMemo( | ||
() => | ||
[ | ||
{ | ||
Header: 'Date', | ||
accessor: 'authorDate', | ||
Cell: ({ | ||
row: { | ||
original: { authorDate }, | ||
}, | ||
}) => ( | ||
<span> | ||
{authorDate ? dateToLocalString(new Date(authorDate)) : 'N/A'} | ||
</span> | ||
), | ||
}, | ||
{ | ||
Header: 'Author', | ||
accessor: 'authorName', | ||
Cell: ({ | ||
row: { | ||
original: { authorName }, | ||
}, | ||
}) => { | ||
return authorName ? ( | ||
<div style={{ display: 'flex' }}> | ||
<p style={{ paddingRight: '10px' }}>{authorName}</p> | ||
<GithubAvatar | ||
username={authorName} | ||
size={22} | ||
githubAccessToken={tokens?.githubAccessToken} | ||
/> | ||
</div> | ||
) : null; | ||
}, | ||
}, | ||
{ | ||
Header: 'Commit Message', | ||
accessor: 'subject', | ||
Cell: ({ | ||
row: { | ||
original: { subject }, | ||
}, | ||
}) => <p>{subject}</p>, | ||
}, | ||
] as Column<Commit>[], | ||
[], | ||
); | ||
|
||
if (!component?.fileInfo?.commits) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Table<Commit> | ||
sorting={true} | ||
data={component.fileInfo.commits} | ||
columns={columns} | ||
sortBy={[ | ||
{ | ||
id: 'authorDate', | ||
desc: true, | ||
}, | ||
]} | ||
pagination={pagination} | ||
/> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,122 +1,43 @@ | ||
/* eslint-disable react/display-name */ | ||
/** @jsx jsx */ | ||
import { FC, useMemo } from 'react'; | ||
import { FC } from 'react'; | ||
import { jsx } from 'theme-ui'; | ||
import { Column } from 'react-table'; | ||
import { | ||
BlockContainer, | ||
BlockContainerProps, | ||
Table, | ||
} from '@component-controls/components'; | ||
import { StoryInputProps, useStoryComponent } from '@component-controls/store'; | ||
import { | ||
StoryInputProps, | ||
useConfig, | ||
useStoryComponent, | ||
} from '@component-controls/store'; | ||
import { Commit, Component, dateToLocalString } from '@component-controls/core'; | ||
import { GithubAvatar } from '@component-controls/components'; | ||
BaseComponentCommits, | ||
BaseComponentCommitsProps, | ||
} from './BaseComponentCommits'; | ||
import { useCustomProps } from '../context'; | ||
|
||
export type ComponentCommitsProps = BlockContainerProps & | ||
StoryInputProps & { storeComponent?: Component }; | ||
StoryInputProps & | ||
Pick<BaseComponentCommitsProps, 'pagination'>; | ||
|
||
/** | ||
* Displays commit history for a component | ||
*/ | ||
export const ComponentCommits: FC<ComponentCommitsProps> = ({ | ||
id, | ||
name, | ||
storeComponent, | ||
pagination, | ||
...rest | ||
}) => { | ||
const props = useCustomProps<ComponentCommitsProps>('commits', rest); | ||
const component = storeComponent | ||
? storeComponent | ||
: useStoryComponent({ id, name }); | ||
|
||
const config = useConfig(); | ||
const { tokens } = config; | ||
const component = useStoryComponent({ id, name }); | ||
|
||
console.log(component); | ||
|
||
const columns = useMemo( | ||
() => | ||
[ | ||
{ | ||
Header: 'Date', | ||
accessor: 'authorDate', | ||
Cell: ({ | ||
row: { | ||
original: { authorDate }, | ||
}, | ||
}) => ( | ||
<span> | ||
{authorDate ? dateToLocalString(new Date(authorDate)) : 'N/A'} | ||
</span> | ||
), | ||
}, | ||
{ | ||
Header: 'Author', | ||
accessor: 'authorName', | ||
Cell: ({ | ||
row: { | ||
original: { authorName }, | ||
}, | ||
}) => { | ||
return authorName ? ( | ||
<div style={{ display: 'flex' }}> | ||
<p style={{ paddingRight: '10px' }}>{authorName}</p> | ||
<GithubAvatar | ||
username={authorName} | ||
size={22} | ||
githubAccessToken={tokens?.githubAccessToken} | ||
/> | ||
</div> | ||
) : null; | ||
}, | ||
}, | ||
{ | ||
Header: 'Commit Message', | ||
accessor: 'subject', | ||
Cell: ({ | ||
row: { | ||
original: { subject }, | ||
}, | ||
}) => <p>{subject}</p>, | ||
}, | ||
] as Column<Commit>[], | ||
[], | ||
); | ||
|
||
if (!component?.fileInfo?.commits) { | ||
return null; | ||
} | ||
|
||
const paginationProps = { | ||
pageIndex: 0, | ||
pageSize: 10, | ||
pageTemplate: 'Page ${pageIndex} of ${pageLength}', | ||
pageVisible: true, | ||
pageSizeTemplate: '${pageSize} rows', | ||
pageSizeVisible: true, | ||
goToPageVisible: true, | ||
goToPageTemplate: 'Go to page:', | ||
}; | ||
|
||
return ( | ||
<BlockContainer {...props}> | ||
<Table<Commit> | ||
sorting={true} | ||
data={component.fileInfo.commits} | ||
columns={columns} | ||
sortBy={[ | ||
{ | ||
id: 'authorDate', | ||
desc: true, | ||
}, | ||
]} | ||
pagination={paginationProps} | ||
/> | ||
<BaseComponentCommits component={component} pagination={pagination} /> | ||
</BlockContainer> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './BaseComponentCommits'; | ||
export * from './ComponentCommits'; |
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
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