mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 18:51:59 +00:00
svelte: Add link to code-graph page to repo navigation (#62899)
This adds a link to the repository's code-graph page to the repo navigation. Additional changes: - added a flag to each menu item that specifies whether or not show the entry for non-admin users (defaults to `false`) - updated vite's proxy configuration to properly load React repo pages from the server
This commit is contained in:
parent
d4a6b27403
commit
4497bba9ad
@ -22,22 +22,42 @@
|
||||
import type { LayoutData } from './$types'
|
||||
import RepoSearchInput from './RepoSearchInput.svelte'
|
||||
|
||||
interface MenuEntry {
|
||||
/**
|
||||
* The (URL) path to the page.
|
||||
*/
|
||||
path: string
|
||||
/**
|
||||
* The visible name of the menu entry.
|
||||
*/
|
||||
label: string
|
||||
/**
|
||||
* The icon to display next to the title.
|
||||
*/
|
||||
icon?: string
|
||||
/**
|
||||
* Who can see this entry.
|
||||
*/
|
||||
visibility: 'admin' | 'user'
|
||||
}
|
||||
|
||||
export let data: LayoutData
|
||||
|
||||
const menuOpen = writable(false)
|
||||
const navEntries: { path: string; icon: string; title: string }[] = [
|
||||
{ path: '', icon: mdiCodeTags, title: 'Code' },
|
||||
{ path: '/-/commits', icon: mdiSourceCommit, title: 'Commits' },
|
||||
{ path: '/-/branches', icon: mdiSourceBranch, title: 'Branches' },
|
||||
{ path: '/-/tags', icon: mdiTag, title: 'Tags' },
|
||||
{ path: '/-/stats/contributors', icon: mdiAccount, title: 'Contributors' },
|
||||
const navEntries: MenuEntry[] = [
|
||||
{ path: '', icon: mdiCodeTags, label: 'Code', visibility: 'user' },
|
||||
{ path: '/-/commits', icon: mdiSourceCommit, label: 'Commits', visibility: 'user' },
|
||||
{ path: '/-/branches', icon: mdiSourceBranch, label: 'Branches', visibility: 'user' },
|
||||
{ path: '/-/tags', icon: mdiTag, label: 'Tags', visibility: 'user' },
|
||||
{ path: '/-/stats/contributors', icon: mdiAccount, label: 'Contributors', visibility: 'user' },
|
||||
]
|
||||
const menuEntries: { path: string; icon: string; title: string }[] = [
|
||||
{ path: '/-/compare', icon: mdiHistory, title: 'Compare' },
|
||||
{ path: '/-/own', icon: mdiAccount, title: 'Ownership' },
|
||||
{ path: '/-/embeddings', icon: '', title: 'Embeddings' },
|
||||
{ path: '/-/batch-changes', icon: '', title: 'Batch changes' },
|
||||
{ path: '/-/settings', icon: mdiCog, title: 'Settings' },
|
||||
const menuEntries: MenuEntry[] = [
|
||||
{ path: '/-/compare', icon: mdiHistory, label: 'Compare', visibility: 'user' },
|
||||
{ path: '/-/own', icon: mdiAccount, label: 'Ownership', visibility: 'admin' },
|
||||
{ path: '/-/embeddings', label: 'Embeddings', visibility: 'admin' },
|
||||
{ path: '/-/code-graph', label: 'Code graph data', visibility: 'admin' },
|
||||
{ path: '/-/batch-changes', label: 'Batch changes', visibility: 'admin' },
|
||||
{ path: '/-/settings', icon: mdiCog, label: 'Settings', visibility: 'admin' },
|
||||
]
|
||||
|
||||
let visibleNavEntries = navEntries.length
|
||||
@ -64,15 +84,17 @@
|
||||
|
||||
<ul use:computeFit on:fit={event => (visibleNavEntries = event.detail.itemCount)}>
|
||||
{#each navEntriesToShow as entry}
|
||||
{@const href = data.repoURL + entry.path}
|
||||
<li>
|
||||
<a {href} aria-current={isActive(href, $page.url) ? 'page' : undefined}>
|
||||
{#if entry.icon}
|
||||
<Icon svgPath={entry.icon} inline />
|
||||
{/if}
|
||||
<span>{entry.title}</span>
|
||||
</a>
|
||||
</li>
|
||||
{#if entry.visibility === 'user' || (entry.visibility === 'admin' && data.user?.siteAdmin)}
|
||||
{@const href = data.repoURL + entry.path}
|
||||
<li>
|
||||
<a {href} aria-current={isActive(href, $page.url) ? 'page' : undefined}>
|
||||
{#if entry.icon}
|
||||
<Icon svgPath={entry.icon} inline />
|
||||
{/if}
|
||||
<span>{entry.label}</span>
|
||||
</a>
|
||||
</li>
|
||||
{/if}
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
@ -85,15 +107,17 @@
|
||||
<Icon svgPath={mdiDotsHorizontal} aria-label="More repo navigation items" />
|
||||
</svelte:fragment>
|
||||
{#each allMenuEntries as entry}
|
||||
{@const href = data.repoURL + entry.path}
|
||||
<MenuLink {href}>
|
||||
<span class="overflow-entry" class:active={isActive(href, $page.url)}>
|
||||
{#if entry.icon}
|
||||
<Icon svgPath={entry.icon} inline />
|
||||
{/if}
|
||||
<span>{entry.title}</span>
|
||||
</span>
|
||||
</MenuLink>
|
||||
{#if entry.visibility === 'user' || (entry.visibility === 'admin' && data.user?.siteAdmin)}
|
||||
{@const href = data.repoURL + entry.path}
|
||||
<MenuLink {href}>
|
||||
<span class="overflow-entry" class:active={isActive(href, $page.url)}>
|
||||
{#if entry.icon}
|
||||
<Icon svgPath={entry.icon} inline />
|
||||
{/if}
|
||||
<span>{entry.label}</span>
|
||||
</span>
|
||||
</MenuLink>
|
||||
{/if}
|
||||
{/each}
|
||||
</DropdownMenu>
|
||||
<RepoSearchInput repoName={data.repoName} revision={data.displayRevision} />
|
||||
|
||||
@ -52,11 +52,12 @@ export default defineConfig(({ mode }) => {
|
||||
proxy: {
|
||||
// Proxy requests to specific endpoints to a real Sourcegraph
|
||||
// instance.
|
||||
'^(/sign-in|/.assets|/-|/.api|/search/stream|/users|/notebooks|/insights)|(/-/raw/)': {
|
||||
target: process.env.SOURCEGRAPH_API_URL || 'https://sourcegraph.com',
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
},
|
||||
'^(/sign-in|/.assets|/-|/.api|/search/stream|/users|/notebooks|/insights|/batch-changes)|/-/(raw|compare|own|embeddings|code-graph|batch-changes|settings)(/|$)':
|
||||
{
|
||||
target: process.env.SOURCEGRAPH_API_URL || 'https://sourcegraph.com',
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user