New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Svelte: Implement and instantiate FilePopover #62498
Conversation
b95b8d0
to
73a02dd
Compare
client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/FileTree.svelte
Outdated
Show resolved
Hide resolved
client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/FileTree.svelte
Outdated
Show resolved
Hide resolved
client/web-sveltekit/src/lib/repo/RepoPopover/RepoPopover.svelte
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of general comments about the design we should follow up on.
The top line is almost always going to get cut off because we're trying to fit a full repo name and a large path into a small space:
Long commit summaries should be wrapped, not truncated. And we should linkify the PR number.
The radius of the popover background does not match the border radius of its border.
client/web-sveltekit/src/lib/repo/RepoPopover/RepoPopover.svelte
Outdated
Show resolved
Hide resolved
client/web-sveltekit/src/lib/repo/RepoPopover/RepoPopover.svelte
Outdated
Show resolved
Hide resolved
client/web-sveltekit/src/lib/repo/RepoPopover/RepoPopover.svelte
Outdated
Show resolved
Hide resolved
client/web-sveltekit/src/lib/repo/filePopover/FilePopover.svelte
Outdated
Show resolved
Hide resolved
client/web-sveltekit/src/lib/repo/filePopover/FilePopover.svelte
Outdated
Show resolved
Hide resolved
client/web-sveltekit/src/lib/repo/filePopover/FilePopover.svelte
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Viewing this in storybook fails for me with can't access property "split", filePath2 is undefined
@camdencheek Do we actually need the repository name? I feel like the file path should suffice, since by the time the user gets to a file tree view, they'll more than likely know what repo they're in. Right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
73a02dd
to
de4ab15
Compare
This was part of the original design. I have to say, I like it better in dark mode. It does look a little awkward in light mode. |
1e6174b
to
d14df94
Compare
client/web-sveltekit/src/routes/[...repo=reporev]/(validrev)/(code)/FileTree.svelte
Outdated
Show resolved
Hide resolved
border-radius: var(--popover-border-radius); | ||
border-radius: var(--border-radius); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change? Other components may be depending on being able to set --popover-border-radius
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two values. --popover-border-radius (equal to 5px) and --border-radius (equal to 3px).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, why did you change the Popover
component to use --border-radius
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh... I see what you're saying. I'll change it.
const fetchPopoverData = async () => { | ||
const client = getGraphQLClient() | ||
const result = await client.query(FileOrDirPopoverQuery, { | ||
repoName, | ||
revspec, | ||
filePath, | ||
}) | ||
|
||
if (result.error || result.data === undefined) { | ||
console.error('could not fetch file or dir popover', result.error) | ||
throw new Error('could not fetch file or dir popover', result.error) | ||
} | ||
|
||
if (result?.data?.repository?.commit?.path?.__typename === 'GitBlob') { | ||
if (result?.data.repository?.commit?.path?.blame.length > 0) { | ||
filePopover = result?.data?.repository?.commit?.path | ||
} | ||
return filePopover | ||
} else if (result?.data?.repository?.commit?.path?.__typename === 'GitTree') { | ||
dirPopover = result?.data?.repository?.commit?.path | ||
return dirPopover | ||
} | ||
|
||
return null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we depart from the pattern established for RepoPopover
and do the data fetching in the component rather than in the +page.ts
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@camdencheek Long story short, I tried to implement it around 3 or 4 times and it was a giant pain each time, always with many bugs to work through. Why does it matter if we do it here? It seems to be better here because it's contained directly in the component that calls it. It also only mounts on hover, so we're only calling it when we need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we want to separate data fetching from rendering because the source of the data might be different when we use the component in different places. e.g., we may want to batch these calls, or cancel a call if you hover over something different, or preload the data for some locations.
Another more concrete reason is that this is now much harder to test because, rather than just passing in the data it needs to render, you now need to mock out the API call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another concrete example is, if you re-hover, we now re-fetch because the component is re-created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, with the little time I have left, I think I need to cry "uncle" here and pass this along to someone else. I don't see me getting this done today. I've tried a number of times and failed to reproduce what we did with RepoPopover.
client/web-sveltekit/src/lib/repo/filePopover/FilePopover.svelte
Outdated
Show resolved
Hide resolved
d14df94
to
dcf1465
Compare
With @jasonhawkharris on leave, any chance this gets merged anytime soon? @camdencheek |
Yep, this is first on my list tomorrow |
f9423a3
to
f2a3f88
Compare
d967621
to
30706d8
Compare
@camdencheek @jasonhawkharris As a follow up to this:
|
This PR Implements and instantiates the file popover on the SvelteKit web app.
Dark Mode:
https://github.com/sourcegraph/sourcegraph/assets/62355966/f1405cc2-54e0-49ba-aa26-7ddf2d258970
Light Mode:
https://github.com/sourcegraph/sourcegraph/assets/62355966/a8eb53ed-2a38-4574-a76a-5f5559ded015
Questions:
Test plan
Added a storybook test and a playwright test