Skip to content

Commit 967acc3

Browse files
authored
Merge pull request #43 from TomPlum/develop
Added showGitIndex prop
2 parents 39ce052 + 35fe4bd commit 967acc3

11 files changed

Lines changed: 57997 additions & 197 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ All components have optional props to further configure the log.
223223
| `onSelectCommit` | `(commit?: Commit) => void` | Callback function when a commit is selected. `commit` is `undefined` if unselected. |
224224
| `classes` | `GitLogStylingProps` | CSS classes for various elements to enable custom styling. |
225225
| `indexStatus` | `GitLogIndexStatus` | Renders information about added, deleted and modified files to the index pseudo-commit entry. |
226+
| `showGitIndex` | `boolean` | Enables the Git index "pseudo-commit' entry above the HEAD commit. |
226227
227228
228229
#### GitLogStylingProps
@@ -325,7 +326,6 @@ All components have optional props to further configure the log.
325326
- Mobile responsiveness for the demo site
326327
- Add graph render strategy with a second option to use 2d rendering context (html canvas)
327328
- Add eslint to pipeline
328-
- Add in prop to show-hide the index pseudo commit
329329
- Tags should be independent. Add a new optional field to the log entry / commit objects.
330330
- Branch / Tags column is fixed. Dynamically floor it to match the max tag size currently being rendered?
331331
- Is the SS paginated log gonna accept data from multiple branches? Because then we need the HEAD commits of each branch

packages/demo/src/GitLog.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const meta: Meta<StoryProps> = {
2727
showCommitNodeHashes: false,
2828
showCommitNodeTooltips: false,
2929
showHeaders: true,
30+
showGitIndex: true,
3031
enableResize: false,
3132
nodeTheme: 'default',
3233
nodeSize: 20,
@@ -100,6 +101,12 @@ const meta: Meta<StoryProps> = {
100101
Plain: 'plain'
101102
}
102103
},
104+
showGitIndex: {
105+
name: 'Show Git Index',
106+
table: {
107+
category: 'Visibility'
108+
}
109+
},
103110
pageSize: {
104111
name: 'Page Size',
105112
table: {

packages/demo/src/GitLogPaged.stories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const meta: Meta<StoryProps> = {
2727
showHeaders: true,
2828
enableResize: false,
2929
nodeTheme: 'default',
30+
showGitIndex: true,
3031
nodeSize: 20,
3132
orientation: 'normal',
3233
onSelectCommit: (commit?: Commit) => {
@@ -90,6 +91,12 @@ const meta: Meta<StoryProps> = {
9091
Plain: 'plain'
9192
}
9293
},
94+
showGitIndex: {
95+
name: 'Show Git Index',
96+
table: {
97+
category: 'Visibility'
98+
}
99+
},
93100
enableResize: {
94101
name: 'Enable Resize',
95102
table: {

packages/demo/src/hooks/useStoryState/useStoryState.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,26 @@ const getRepositoryConfig = (name: string) => {
1212
branchName: 'release',
1313
fileNameEntireHistory: 'sleep.txt',
1414
fileNameCheckedOutBranch: 'sleep-release.txt',
15-
headCommitHash: '1352f4c'
15+
headCommitHash: '1352f4c',
16+
headCommitCheckoutOutBranch: 'e059c28'
1617
}
1718
}
1819
case 'TomPlum/advent-of-code-2019': {
1920
return {
2021
branchName: 'master',
2122
fileNameEntireHistory: 'advent-of-code-2019.txt',
2223
fileNameCheckedOutBranch: 'advent-of-code-2019-master.txt',
23-
headCommitHash: 'c88f0b9'
24+
headCommitHash: 'c88f0b9',
25+
headCommitCheckoutOutBranch: '12d47cc'
2426
}
2527
}
2628
case 'TomPlum/learn-japanese': {
2729
return {
2830
branchName: 'feature/JPUI-51',
2931
fileNameEntireHistory: 'learn-japanese.txt',
3032
fileNameCheckedOutBranch: 'learn-japanese-feature.txt',
31-
headCommitHash: 'de80ee8'
33+
headCommitHash: 'de80ee8',
34+
headCommitCheckoutOutBranch: 'de80ee8d'
3235
}
3336
}
3437
default: {
@@ -39,7 +42,13 @@ const getRepositoryConfig = (name: string) => {
3942

4043
export const useStoryState = ({ isServerSidePaginated, onChangeRepository }: StoryStateProps = {}) => {
4144
const [repository, setRepository] = useState('TomPlum/sleep')
42-
const { branchName, fileNameEntireHistory, fileNameCheckedOutBranch, headCommitHash } = getRepositoryConfig(repository)
45+
const {
46+
branchName,
47+
fileNameEntireHistory,
48+
fileNameCheckedOutBranch,
49+
headCommitHash,
50+
headCommitCheckoutOutBranch
51+
} = getRepositoryConfig(repository)
4352

4453
const { data, isLoading } = useGitLogEntries({
4554
fileName: isServerSidePaginated ? fileNameCheckedOutBranch : fileNameEntireHistory
@@ -68,7 +77,7 @@ export const useStoryState = ({ isServerSidePaginated, onChangeRepository }: Sto
6877
return {
6978
loading: isLoading,
7079
branch: branchName,
71-
headCommitHash,
80+
headCommitHash: isServerSidePaginated ? headCommitCheckoutOutBranch : headCommitHash,
7281
entries: data,
7382
theme,
7483
colours,

packages/library/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ All components have optional props to further configure the log.
181181
| `onSelectCommit` | `(commit?: Commit) => void` | Callback function when a commit is selected. `commit` is `undefined` if unselected. |
182182
| `classes` | `GitLogStylingProps` | CSS classes for various elements to enable custom styling. |
183183
| `indexStatus` | `GitLogIndexStatus` | Renders information about added, deleted and modified files to the index pseudo-commit entry. |
184+
| `showGitIndex` | `boolean` | Enables the Git index "pseudo-commit' entry above the HEAD commit. |
184185
185186
186187
#### GitLogStylingProps

packages/library/src/GitLog.spec.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ describe('GitLog', () => {
6767
currentBranch='release'
6868
entries={gitLogEntries}
6969
githubRepositoryUrl='https://github.com/TomPlum/sleep'
70+
indexStatus={{
71+
added: 2,
72+
deleted: 1,
73+
modified: 10
74+
}}
7075
>
7176
<GitLog.Tags />
7277
<GitLog.Graph />
@@ -133,6 +138,26 @@ describe('GitLog', () => {
133138
expect(asFragment()).toMatchSnapshot()
134139
})
135140

141+
it('should render correctly and match the snapshot of the GitLog component when the index is disabled', { timeout: 1000 * 10 } ,() => {
142+
const gitLogEntries = parseGitLogOutput(sleepRepositoryData)
143+
144+
const { asFragment } = render(
145+
<GitLog
146+
showHeaders
147+
showGitIndex={false}
148+
currentBranch='release'
149+
entries={gitLogEntries}
150+
githubRepositoryUrl='https://github.com/TomPlum/sleep'
151+
>
152+
<GitLog.Tags />
153+
<GitLog.Graph />
154+
<GitLog.Table />
155+
</GitLog>
156+
)
157+
158+
expect(asFragment()).toMatchSnapshot()
159+
})
160+
136161
it('should log a warning if the graph subcomponent is not rendered', () => {
137162
const consoleWarn = vi.spyOn(console, 'warn')
138163

0 commit comments

Comments
 (0)