Skip to content

Commit f5292c5

Browse files
committed
Add 'No History Found' fallback
- Covers git-ignored files edge case
1 parent 237f2c0 commit f5292c5

File tree

2 files changed

+48
-32
lines changed

2 files changed

+48
-32
lines changed

src/components/HistorySideBar.tsx

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { GitExtension } from '../model';
77
import { hiddenButtonStyle } from '../style/ActionButtonStyle';
88
import {
99
historySideBarStyle,
10+
noHistoryFoundStyle,
1011
selectedHistoryFileStyle
1112
} from '../style/HistorySideBarStyle';
1213
import { ContextCommandIDs, Git } from '../tokens';
@@ -145,40 +146,46 @@ export const HistorySideBar: React.FunctionComponent<IHistorySideBarProps> = (
145146
onDoubleClick={removeSelectedFile}
146147
/>
147148
)}
148-
{commits.map((commit: Git.ISingleCommitInfo) => {
149-
const commonProps = {
150-
commit,
151-
branches: props.branches,
152-
model: props.model,
153-
commands: props.commands,
154-
trans: props.trans
155-
};
149+
{commits.length ? (
150+
commits.map((commit: Git.ISingleCommitInfo) => {
151+
const commonProps = {
152+
commit,
153+
branches: props.branches,
154+
model: props.model,
155+
commands: props.commands,
156+
trans: props.trans
157+
};
156158

157-
// Only pass down callback when single file history is open
158-
// and its diff is viewable
159-
const onOpenDiff =
160-
props.model.selectedHistoryFile && !commit.is_binary
161-
? openDiff(commit)(
162-
props.model.selectedHistoryFile.to,
163-
!commit.is_binary
164-
)
165-
: undefined;
159+
// Only pass down callback when single file history is open
160+
// and its diff is viewable
161+
const onOpenDiff =
162+
props.model.selectedHistoryFile && !commit.is_binary
163+
? openDiff(commit)(
164+
props.model.selectedHistoryFile.to,
165+
!commit.is_binary
166+
)
167+
: undefined;
166168

167-
return (
168-
<PastCommitNode
169-
key={commit.commit}
170-
{...commonProps}
171-
onOpenDiff={onOpenDiff}
172-
>
173-
{!props.model.selectedHistoryFile && (
174-
<SinglePastCommitInfo
175-
{...commonProps}
176-
onOpenDiff={openDiff(commit)}
177-
/>
178-
)}
179-
</PastCommitNode>
180-
);
181-
})}
169+
return (
170+
<PastCommitNode
171+
key={commit.commit}
172+
{...commonProps}
173+
onOpenDiff={onOpenDiff}
174+
>
175+
{!props.model.selectedHistoryFile && (
176+
<SinglePastCommitInfo
177+
{...commonProps}
178+
onOpenDiff={openDiff(commit)}
179+
/>
180+
)}
181+
</PastCommitNode>
182+
);
183+
})
184+
) : (
185+
<li className={noHistoryFoundStyle}>
186+
{props.trans.__('No history found for the selected file.')}
187+
</li>
188+
)}
182189
</ol>
183190
);
184191
};

src/style/HistorySideBarStyle.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ export const selectedHistoryFileStyle = style({
1414
backgroundColor: 'var(--jp-toolbar-active-background)'
1515
});
1616

17+
export const noHistoryFoundStyle = style({
18+
display: 'flex',
19+
justifyContent: 'center',
20+
21+
padding: '10px 0',
22+
23+
color: 'var(--jp-ui-font-color2)'
24+
});
25+
1726
export const historySideBarStyle = style({
1827
display: 'flex',
1928
flexDirection: 'column',

0 commit comments

Comments
 (0)