Skip to content

Commit 311220d

Browse files
committed
Add has-changes indicator for specs in PR branches
Show a visual indicator (orange dot with tooltip) on specs that have been modified in the current PR. Only specs whose filenames appear in the PR's changed files list will display the indicator. - Fetch changed files from PR via GraphQL - Add changedFiles to GitHubRepositoryRef type - Only set diffURL on specs in changedFiles - Display subtle orange dot with "Has changes" tooltip
1 parent 0d907a2 commit 311220d

File tree

4 files changed

+55
-20
lines changed

4 files changed

+55
-20
lines changed

src/features/projects/data/GitHubProjectDataSource.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
122122
const specifications = ref.files.filter(file => {
123123
return this.isOpenAPISpecification(file.name)
124124
}).map(file => {
125+
const isFileChanged = ref.changedFiles?.includes(file.name) ?? false
125126
return {
126127
id: file.name,
127128
name: file.name,
@@ -132,16 +133,16 @@ export default class GitHubProjectDataSource implements IProjectDataSource {
132133
ref: ref.id
133134
}),
134135
editURL: `https://github.com/${ownerName}/${repositoryName}/edit/${ref.name}/${encodeURIComponent(file.name)}`,
135-
diffURL: this.getGitHubDiffURL({
136+
diffURL: isFileChanged ? this.getGitHubDiffURL({
136137
ownerName,
137138
repositoryName,
138139
path: file.name,
139140
baseRefOid: ref.baseRefOid,
140141
headRefOid: ref.id
141-
}),
142-
diffBaseBranch: ref.baseRef,
143-
diffBaseOid: ref.baseRefOid,
144-
diffPrUrl: ref.prNumber ? `https://github.com/${ownerName}/${repositoryName}/pull/${ref.prNumber}` : undefined,
142+
}) : undefined,
143+
diffBaseBranch: isFileChanged ? ref.baseRef : undefined,
144+
diffBaseOid: isFileChanged ? ref.baseRefOid : undefined,
145+
diffPrUrl: isFileChanged && ref.prNumber ? `https://github.com/${ownerName}/${repositoryName}/pull/${ref.prNumber}` : undefined,
145146
isDefault: false // initial value
146147
}
147148
}).sort((a, b) => a.name.localeCompare(b.name))

src/features/projects/data/GitHubRepositoryDataSource.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type GraphQLPullRequest = {
5151
readonly headRefName: string
5252
readonly baseRefName: string
5353
readonly baseRefOid: string
54+
readonly changedFiles: string[]
5455
}
5556

5657
export default class GitHubProjectDataSource implements IGitHubRepositoryDataSource {
@@ -129,7 +130,8 @@ export default class GitHubProjectDataSource implements IGitHubRepositoryDataSou
129130
baseRef: pr?.baseRefName,
130131
baseRefOid: pr?.baseRefOid,
131132
prNumber: pr?.number,
132-
files: branch.node.target.tree.entries
133+
files: branch.node.target.tree.entries,
134+
changedFiles: pr?.changedFiles
133135
}
134136
})
135137

@@ -174,6 +176,11 @@ export default class GitHubProjectDataSource implements IGitHubRepositoryDataSou
174176
headRefName
175177
baseRefName
176178
baseRefOid
179+
files(first: 100) {
180+
nodes {
181+
path
182+
}
183+
}
177184
}
178185
}
179186
}
@@ -199,15 +206,26 @@ export default class GitHubProjectDataSource implements IGitHubRepositoryDataSou
199206
const pullRequests = new Map<string, GraphQLPullRequest>()
200207

201208
if (repoData?.pullRequests?.edges) {
202-
const pullRequestEdges = repoData.pullRequests.edges as Edge<GraphQLPullRequest>[]
209+
type RawGraphQLPullRequest = {
210+
number: number
211+
headRefName: string
212+
baseRefName: string
213+
baseRefOid: string
214+
files?: {
215+
nodes?: { path: string }[]
216+
}
217+
}
218+
const pullRequestEdges = repoData.pullRequests.edges as Edge<RawGraphQLPullRequest>[]
203219

204220
pullRequestEdges.forEach(edge => {
205221
const pr = edge.node
222+
const changedFiles = pr.files?.nodes?.map(f => f.path) || []
206223
pullRequests.set(pr.headRefName, {
207224
number: pr.number,
208225
headRefName: pr.headRefName,
209226
baseRefName: pr.baseRefName,
210-
baseRefOid: pr.baseRefOid
227+
baseRefOid: pr.baseRefOid,
228+
changedFiles
211229
})
212230
})
213231
}

src/features/projects/domain/IGitHubRepositoryDataSource.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ export type GitHubRepositoryRef = {
2424
readonly files: {
2525
readonly name: string
2626
}[]
27-
}
28-
29-
export default interface IGitHubRepositoryDataSource {
30-
getRepositories(): Promise<GitHubRepository[]>
27+
readonly changedFiles?: string[]
3128
}
3229

3330
export default interface IGitHubRepositoryDataSource {

src/features/projects/view/toolbar/Selector.tsx

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import {
44
MenuItem,
55
SelectChangeEvent,
66
FormControl,
7-
Typography
7+
Typography,
8+
Box,
9+
Tooltip
810
} from "@mui/material"
911
import MenuItemHover from "@/common/ui/MenuItemHover"
1012

1113
interface SelectorItem {
1214
readonly id: string
1315
readonly name: string
16+
readonly hasChanges?: boolean
1417
}
1518

1619
const Selector = ({
@@ -45,13 +48,29 @@ const Selector = ({
4548
{items.map(item => (
4649
<MenuItem key={item.id} value={item.id}>
4750
<MenuItemHover>
48-
<Typography sx={{
49-
overflow: "hidden",
50-
whiteSpace: "nowrap",
51-
textOverflow: "ellipsis"
52-
}}>
53-
{item.name}
54-
</Typography>
51+
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
52+
<Typography sx={{
53+
overflow: "hidden",
54+
whiteSpace: "nowrap",
55+
textOverflow: "ellipsis"
56+
}}>
57+
{item.name}
58+
</Typography>
59+
{item.hasChanges && (
60+
<Tooltip title="Has changes" arrow>
61+
<Box
62+
component="span"
63+
sx={{
64+
width: 6,
65+
height: 6,
66+
borderRadius: "50%",
67+
backgroundColor: "warning.main",
68+
flexShrink: 0
69+
}}
70+
/>
71+
</Tooltip>
72+
)}
73+
</Box>
5574
</MenuItemHover>
5675
</MenuItem>
5776
))}

0 commit comments

Comments
 (0)