Skip to content
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

[VC Flow] Support knowledge-base route on VC profile #7480

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/domain/community/virtualContributor/VCRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import { Route, Routes } from 'react-router-dom';
import VCProfilePage from './vcProfilePage/VCProfilePage';
import { PageLayoutHolderWithOutlet } from '@/domain/journey/common/EntityPageLayout';
import TopLevelLayout from '@/main/ui/layout/TopLevelLayout';
import { Error404 } from '@/core/pages/Errors/Error404';
import VCSettingsRoute from '../virtualContributorAdmin/VCSettingsRoute';
import { nameOfUrl } from '@/main/routing/urlParams';

export const VCRoute = () => (
<Routes>
<Route path={`:${nameOfUrl.vcNameId}/*`}>
<Route path="" element={<PageLayoutHolderWithOutlet />}>
<Route index element={<VCProfilePage />} />
</Route>
<Route path={`:${nameOfUrl.vcNameId}/*`} element={<PageLayoutHolderWithOutlet />}>
<Route index element={<VCProfilePage />} />
<Route path="knowledge-base" element={<VCProfilePage />} />
<Route path="settings/*" element={<VCSettingsRoute />} />
<Route path="*" element={<Error404 />} />
</Route>
<Route
path="*"
element={
<TopLevelLayout>
<Error404 />
</TopLevelLayout>
}
/>
</Routes>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import useNavigate from '@/core/routing/useNavigate';
import { Button } from '@mui/material';
import BookIcon from '@mui/icons-material/Book';
import CloudDownloadIcon from '@mui/icons-material/CloudDownload';
Expand All @@ -16,6 +18,9 @@ import { type VCProfilePageViewProps } from './model';
import { AiPersonaBodyOfKnowledgeType } from '@/core/apollo/generated/graphql-schema';
import KnowledgeBaseDialog from '@/domain/community/virtualContributor/knowledgeBase/KnowledgeBaseDialog';

// a temporary Knowledge Base route - `${vcProfileUrl}/${KNOWLEDGE_BASE_PATH}
const KNOWLEDGE_BASE_PATH = 'knowledge-base';

const SectionTitle = ({ children }) => {
return (
<BlockTitle display={'flex'} alignItems={'center'} gap={gutters(0.5)}>
Expand All @@ -31,6 +36,9 @@ const SectionContent = ({ children }) => {
export const VCProfileContentView = ({ bokProfile, virtualContributor }: VCProfilePageViewProps) => {
const { palette } = useTheme();
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const pathname = location.pathname;

const [showKnowledgeBase, setShowKnowledgeBase] = useState(false);

Expand All @@ -49,10 +57,47 @@ export const VCProfileContentView = ({ bokProfile, virtualContributor }: VCProfi
const isExternal = vcType === AiPersonaBodyOfKnowledgeType.None;
const hasSpaceKnowledge = vcType === AiPersonaBodyOfKnowledgeType.AlkemioSpace;

const isKnowledgeBasePath = (pathname: string) => {
const pathParts = pathname.split('/');

return pathParts[pathParts.length - 1] === KNOWLEDGE_BASE_PATH;
};

const removeKnowledgeBaseFromPath = (pathname: string) => {
const pathParts = pathname.split('/');

if (pathParts[pathParts.length - 1] === KNOWLEDGE_BASE_PATH) {
pathParts.pop();

const newPath = pathParts.join('/');
navigate(newPath, { replace: true });
}
};

const addKnowledgeBaseToPath = (pathname: string) => {
if (!isKnowledgeBasePath(pathname)) {
const newPath = `${pathname}/${KNOWLEDGE_BASE_PATH}`;

navigate(newPath, { replace: true });
}
};

const handleKnowledgeBaseClick = () => {
setShowKnowledgeBase(true);
addKnowledgeBaseToPath(pathname);
};

const onCloseKnowledgeBase = () => {
setShowKnowledgeBase(false);
removeKnowledgeBaseFromPath(pathname);
};

useEffect(() => {
if (isKnowledgeBasePath(pathname)) {
setShowKnowledgeBase(true);
}
}, [pathname, virtualContributor]);
bobbykolev marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
<PageContentBlock>
Expand Down Expand Up @@ -133,7 +178,7 @@ export const VCProfileContentView = ({ bokProfile, virtualContributor }: VCProfi
<KnowledgeBaseDialog
id={virtualContributor?.id ?? ''}
title={`${name}: ${t('virtualContributorSpaceSettings.bodyOfKnowledge')}`}
onClose={() => setShowKnowledgeBase(false)}
onClose={onCloseKnowledgeBase}
/>
)}
</>
Expand Down
13 changes: 5 additions & 8 deletions src/domain/community/virtualContributorAdmin/VCSettingsRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { Navigate, Route, Routes } from 'react-router-dom';
import { Error404 } from '@/core/pages/Errors/Error404';
import { PageLayoutHolderWithOutlet } from '@/domain/journey/common/EntityPageLayout';
import VCEditProfilePage from './vcSettingsPage/VCEditProfilePage';
import VCMembershipPage from '../virtualContributor/vcMembershipPage/VCMembershipPage';
import VCAccessibilitySettingsPage from './VCAccessibilitySettings/VCAccessibilitySettingsPage';

const VCSettingsRoute = () => (
<Routes>
<Route path={'/'} element={<PageLayoutHolderWithOutlet />}>
<Route index element={<Navigate to={'profile'} />} />
<Route path="profile" element={<VCEditProfilePage />} />
<Route path="membership" element={<VCMembershipPage />} />
<Route path="settings" element={<VCAccessibilitySettingsPage />} />
<Route path="*" element={<Error404 />} />
</Route>
<Route index element={<Navigate to={'profile'} />} />
<Route path="profile" element={<VCEditProfilePage />} />
<Route path="membership" element={<VCMembershipPage />} />
<Route path="settings" element={<VCAccessibilitySettingsPage />} />
<Route path="*" element={<Error404 />} />
</Routes>
);

Expand Down