Skip to content

Commit 7a9828d

Browse files
FindHaofacebook-github-bot
authored andcommitted
Enhance App component with wiki link functionality (#23)
Summary: - Added a utility function `checkFbDirectoryExists` to detect the existence of the fb directory. - Integrated the check into the App component to conditionally display an internal wiki link based on the directory's existence. - Updated the header to include GitHub and Wiki links, along with the new internal wiki link, improving navigation options for users. - Enhanced comments for clarity and added new state variables to manage the internal wiki URL. This update improves user experience by providing access to internal documentation when available. Pull Request resolved: #23 Reviewed By: davidberard98 Differential Revision: D77885091 Pulled By: FindHao fbshipit-source-id: ff44962ac0930db2a9ad336290d30783b3b54ca4
1 parent f009d79 commit 7a9828d

File tree

4 files changed

+124
-16
lines changed

4 files changed

+124
-16
lines changed

website/src/App.tsx

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import {
77
processKernelData,
88
getIRType,
99
} from "./utils/dataLoader";
10+
import { checkFbDirectoryExists } from "./utils/fbDetection";
1011
import CodeView from "./pages/CodeView";
1112
import SingleCodeViewer from "./components/SingleCodeViewer";
1213
import KernelOverview from "./pages/KernelOverview";
1314
import DataSourceSelector from "./components/DataSourceSelector";
1415
import WelcomeScreen from "./components/WelcomeScreen";
16+
import ExternalLink from "./components/ExternalLink";
1517
import { mapLanguageToHighlighter } from "./components/CodeViewer";
1618

1719
/**
@@ -35,6 +37,11 @@ function App() {
3537
const [dataLoaded, setDataLoaded] = useState<boolean>(false);
3638
// Track the loaded data source URL
3739
const [loadedUrl, setLoadedUrl] = useState<string | null>(null);
40+
// Track if fb directory exists for internal wiki link
41+
const [fbDirectoryExists, setFbDirectoryExists] = useState<boolean>(false);
42+
43+
// Internal wiki URL - will be loaded dynamically if fb directory exists
44+
const [internalWikiUrl, setInternalWikiUrl] = useState<string>('');
3845

3946
/**
4047
* Helper function to find a kernel by its hash
@@ -45,7 +52,7 @@ function App() {
4552
);
4653
};
4754

48-
// Check URL parameters when component mounts
55+
// Check URL parameters and fb directory when component mounts
4956
useEffect(() => {
5057
// Parse URL parameters
5158
const params = new URLSearchParams(window.location.search);
@@ -61,6 +68,21 @@ function App() {
6168
newUrl.searchParams.set("json_url", jsonUrl);
6269
window.history.replaceState({}, "", newUrl.toString());
6370
}
71+
72+
// Check if fb directory exists and load internal utils if available
73+
checkFbDirectoryExists().then(async (exists) => {
74+
setFbDirectoryExists(exists);
75+
if (exists) {
76+
try {
77+
// Dynamically import internal utils only if fb directory exists
78+
const { getInternalWikiUrl } = await import('./utils/fb/internal_utils');
79+
const url = getInternalWikiUrl();
80+
setInternalWikiUrl(url);
81+
} catch (error) {
82+
console.warn('Failed to load internal utils:', error);
83+
}
84+
}
85+
});
6486
}, []); // Empty dependency array means this runs once on mount
6587

6688
/**
@@ -340,21 +362,62 @@ function App() {
340362
<header className="bg-white border-b border-gray-200">
341363
<div className="w-full px-6 py-4">
342364
<div className="flex justify-between items-center">
343-
<h1
344-
className="text-gray-800 text-2xl font-bold cursor-pointer hover:text-indigo-600 transition-colors"
345-
onClick={() => {
346-
// Reset app state to show welcome page
347-
if (dataLoaded) {
348-
setDataLoaded(false);
349-
setSelectedIR(null);
350-
setSelectedKernel(-1);
351-
setError(null);
352-
}
353-
}}
354-
title="Back to home"
355-
>
356-
TritonParse
357-
</h1>
365+
<div className="flex items-center space-x-6">
366+
<h1
367+
className="text-gray-800 text-2xl font-bold cursor-pointer hover:text-indigo-600 transition-colors"
368+
onClick={() => {
369+
// Reset app state to show welcome page
370+
if (dataLoaded) {
371+
setDataLoaded(false);
372+
setSelectedIR(null);
373+
setSelectedKernel(-1);
374+
setError(null);
375+
}
376+
}}
377+
title="Back to home"
378+
>
379+
TritonParse
380+
</h1>
381+
382+
{/* GitHub and Wiki Links */}
383+
<div className="flex items-center space-x-4">
384+
<ExternalLink
385+
href="https://github.com/pytorch-labs/tritonparse"
386+
title="View on GitHub"
387+
text="GitHub"
388+
icon={
389+
<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
390+
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
391+
</svg>
392+
}
393+
/>
394+
395+
<ExternalLink
396+
href="https://github.com/pytorch-labs/tritonparse/wiki"
397+
title="View Wiki"
398+
text="Wiki"
399+
icon={
400+
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
401+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.746 0 3.332.477 4.5 1.253v13C19.832 18.477 18.246 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />
402+
</svg>
403+
}
404+
/>
405+
406+
{/* Internal Wiki Link - only show if fb directory exists */}
407+
{fbDirectoryExists && (
408+
<ExternalLink
409+
href={internalWikiUrl}
410+
title="View Internal Wiki"
411+
text="Internal Wiki"
412+
icon={
413+
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
414+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.746 0 3.332.477 4.5 1.253v13C19.832 18.477 18.246 18 16.5 18c-1.746 0-3.332.477-4.5 1.253" />
415+
</svg>
416+
}
417+
/>
418+
)}
419+
</div>
420+
</div>
358421

359422
{/* Data source selector (only show when data is loaded or when on the welcome screen) */}
360423
<DataSourceSelector
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
3+
interface ExternalLinkProps {
4+
href: string;
5+
title: string;
6+
text: string;
7+
icon: React.ReactNode;
8+
}
9+
10+
/**
11+
* A reusable external link component with consistent styling.
12+
* Used for navigation links in the header (GitHub, Wiki, Internal Wiki, etc.)
13+
*/
14+
const ExternalLink: React.FC<ExternalLinkProps> = ({ href, title, text, icon }) => {
15+
return (
16+
<a
17+
href={href}
18+
target="_blank"
19+
rel="noopener noreferrer"
20+
className="text-gray-600 hover:text-gray-800 transition-colors flex items-center space-x-1"
21+
title={title}
22+
>
23+
{icon}
24+
<span className="text-sm font-medium">{text}</span>
25+
</a>
26+
);
27+
};
28+
29+
export default ExternalLink;

website/src/utils/fbDetection.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Utility to detect if the fb directory exists
3+
* This checks for the existence of the exists marker file in the fb directory
4+
*/
5+
6+
export const checkFbDirectoryExists = async (): Promise<boolean> => {
7+
try {
8+
// Try to fetch the exists marker file in the fb directory
9+
const response = await fetch('/fb/exists', { method: 'HEAD' });
10+
return response.ok;
11+
} catch (error) {
12+
// If the request fails, the directory likely doesn't exist
13+
return false;
14+
}
15+
};

website/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default defineConfig({
1313
{
1414
name: 'strip-module-attr',
1515
enforce: 'post',
16+
apply: 'build', // only apply this plugin during build
1617
transformIndexHtml(html) {
1718
return html.replace(
1819
/<script\s+type=["']module["']\s+([^>]*?)src=/g,

0 commit comments

Comments
 (0)