Skip to content

Commit

Permalink
Merge pull request #309 from nerdalert/experimental-flag
Browse files Browse the repository at this point in the history
Add a flag to allow for dynamic loading of experimental features
  • Loading branch information
vishnoianil authored Nov 5, 2024
2 parents 171da8e + ebb1f86 commit 645f11d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ TAXONOMY_DOCUMENTS_REPO=github.com/instructlab-public/taxonomy-knowledge-docs
NEXT_PUBLIC_AUTHENTICATION_ORG=<AUTHENTICATION_ORG>
NEXT_PUBLIC_TAXONOMY_REPO_OWNER=<GITHUB_ACCOUNT>
NEXT_PUBLIC_TAXONOMY_REPO=<REPO_NAME>
NEXT_PUBLIC_EXPERIMENTAL_FEATURES=false
35 changes: 23 additions & 12 deletions src/components/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ interface IAppLayout {
children: React.ReactNode;
}

type Route = {
path: string;
label: string;
children?: Route[];
};

const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
const { theme } = useTheme();
const { data: session, status } = useSession();
Expand All @@ -53,6 +59,14 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
return null; // Return nothing if not authenticated to avoid flicker
}

const isExperimentalEnabled = process.env.NEXT_PUBLIC_EXPERIMENTAL_FEATURES === 'true';

// Only log if experimental features are enabled
if (isExperimentalEnabled) {
console.log('Is Experimental Enabled:', isExperimentalEnabled);
console.log('Environment Variable:', process.env.NEXT_PUBLIC_EXPERIMENTAL_FEATURES);
}

const routes = [
{ path: '/dashboard', label: 'Dashboard' },
{
Expand All @@ -70,8 +84,12 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
{ path: '/playground/chat', label: 'Chat' },
{ path: '/playground/endpoints', label: 'Custom Model Endpoints' }
]
},
isExperimentalEnabled && {
path: '/experimental',
label: 'Experimental Features'
}
];
].filter(Boolean) as Route[];

const Header = (
<Masthead>
Expand All @@ -95,27 +113,20 @@ const AppLayout: React.FunctionComponent<IAppLayout> = ({ children }) => {
</Masthead>
);

const renderNavItem = (route: { path: string; label: string }, index: number) => (
const renderNavItem = (route: Route, index: number) => (
<NavItem key={`${route.label}-${index}`} id={`${route.label}-${index}`} isActive={route.path === pathname}>
<Link href={route.path}>{route.label}</Link>
</NavItem>
);

const renderNavExpandable = (
route: {
path: string;
label: string;
children: { path: string; label: string }[];
},
index: number
) => (
const renderNavExpandable = (route: Route, index: number) => (
<NavExpandable
key={`${route.label}-${index}`}
title={route.label}
isActive={route.path === pathname || route.children.some((child) => child.path === pathname)}
isActive={route.path === pathname || route.children?.some((child) => child.path === pathname)}
isExpanded
>
{route.children.map((child, idx) => renderNavItem(child, idx))}
{route.children?.map((child, idx) => renderNavItem(child, idx))}
</NavExpandable>
);

Expand Down

0 comments on commit 645f11d

Please sign in to comment.