-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ai.notebooks): header tabs and dashboard page
ref:DATATR-1636, DATATR-1638 Signed-off-by: Arthur Bullet <[email protected]>
- Loading branch information
Showing
24 changed files
with
743 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...-ai-notebooks/public/translations/pci-ai-notebooks/notebooks/notebook/Messages_fr_FR.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...oks/public/translations/pci-ai-notebooks/notebooks/notebook/dashboard/Messages_fr_FR.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"dashboardTitle": "Dashboard", | ||
"resourcesTitle": "Ressources", | ||
"powerTitleSection": "Power", | ||
"computeTitleSection": "Compute", | ||
"storageTitleSection": "Stockage", | ||
"gpuMemoryField": "{{ gpu }} x {{ memory }} RAM", | ||
"gcuComputeField": "CPU: {{ cpu }} vCores ", | ||
"memoryField": "RAM: {{ memory }}", | ||
"publicNetworkField": "Réseau public: {{ network }}/s", | ||
"temporaryLocalStorageField": "Stockage local éphémère: {{ storage }} SSD", | ||
"temporaryLocalStorageHelper": "Not that much for now", | ||
"workspaceStorage": "Espace de travail {{ storage }} SSD inclus", | ||
"workspaceStorageHelper": "Nothing for now", | ||
"sliderInfo": "{{ usedStorage }} / {{ totalStorage }}", | ||
"notebookIdLabel": "Id du notebook", | ||
"notebookIdCopyToast": "L'identifiant du notebook a été copié", | ||
"billingLink": "Gérer la facturation", | ||
"supportLink": "Contacter le support", | ||
"deleteNotebookButton": "Supprimer" | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/manager/apps/pci-ai-notebooks/src/__tests__/helpers/mocks/label.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as ai from '@/types/cloud/project/ai'; | ||
|
||
export const mockedLabel: ai.Label = { | ||
name: 'labelName', | ||
value: 'labelValue', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/manager/apps/pci-ai-notebooks/src/data/api/ai/notebook/label/label.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { apiClient } from '@ovh-ux/manager-core-api'; | ||
import { NotebookData } from '@/data/api'; | ||
import * as ai from '@/types/cloud/project/ai'; | ||
|
||
export interface EditLabelProps extends NotebookData { | ||
label: ai.Label; | ||
} | ||
|
||
export const editLabel = async ({ | ||
projectId, | ||
notebookId, | ||
label, | ||
}: EditLabelProps) => | ||
apiClient.v6 | ||
.put(`/cloud/project/${projectId}/ai/notebook/${notebookId}/label`, label) | ||
.then((res) => res.data); |
36 changes: 36 additions & 0 deletions
36
packages/manager/apps/pci-ai-notebooks/src/data/api/ai/notebook/label/label.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { apiClient } from '@ovh-ux/manager-core-api'; | ||
import { describe, expect, vi } from 'vitest'; | ||
import { editLabel } from './label.api'; | ||
import { mockedLabel } from '@/__tests__/helpers/mocks/label'; | ||
|
||
vi.mock('@ovh-ux/manager-core-api', () => { | ||
const put = vi.fn(() => { | ||
return Promise.resolve({ data: null }); | ||
}); | ||
return { | ||
apiClient: { | ||
v6: { | ||
put, | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
describe('label functions', () => { | ||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should call editLabel with labelInput', async () => { | ||
expect(apiClient.v6.put).not.toHaveBeenCalled(); | ||
await editLabel({ | ||
projectId: 'projectId', | ||
notebookId: 'notebookId', | ||
label: mockedLabel, | ||
}); | ||
expect(apiClient.v6.put).toHaveBeenCalledWith( | ||
'/cloud/project/projectId/ai/notebook/notebookId/label', | ||
mockedLabel, | ||
); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/manager/apps/pci-ai-notebooks/src/hooks/api/ai/notebook/label/useEditLabel.hook.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { AIError } from '@/data/api'; | ||
import { | ||
EditLabelProps, | ||
editLabel, | ||
} from '@/data/api/ai/notebook/label/label.api'; | ||
|
||
export interface MutateLabelProps { | ||
onError: (cause: AIError) => void; | ||
onSuccess: () => void; | ||
} | ||
|
||
export function useEditLabel({ onError, onSuccess }: MutateLabelProps) { | ||
const mutation = useMutation({ | ||
mutationFn: (labelInfo: EditLabelProps) => { | ||
return editLabel(labelInfo); | ||
}, | ||
onError, | ||
onSuccess, | ||
}); | ||
|
||
return { | ||
editLabel: (labelInfo: EditLabelProps) => { | ||
return mutation.mutate(labelInfo); | ||
}, | ||
...mutation, | ||
}; | ||
} |
40 changes: 40 additions & 0 deletions
40
packages/manager/apps/pci-ai-notebooks/src/hooks/api/ai/notebook/label/useEditLabel.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { renderHook, waitFor } from '@testing-library/react'; | ||
import { vi } from 'vitest'; | ||
import { QueryClientWrapper } from '@/__tests__/helpers/wrappers/QueryClientWrapper'; | ||
import * as labelApi from '@/data/api/ai/notebook/label/label.api'; | ||
import { useEditLabel } from './useEditLabel.hook'; | ||
import { mockedLabel } from '@/__tests__/helpers/mocks/label'; | ||
|
||
vi.mock('@/data/api/ai/notebook/label/label.api', () => ({ | ||
editLabel: vi.fn(), | ||
})); | ||
|
||
describe('useEditLabel', () => { | ||
it('should call useEditLabel on mutation with data', async () => { | ||
const projectId = 'projectId'; | ||
const notebookId = 'notebookId'; | ||
const onSuccess = vi.fn(); | ||
const onError = vi.fn(); | ||
|
||
vi.mocked(labelApi.editLabel).mockResolvedValue(mockedLabel); | ||
const { result } = renderHook(() => useEditLabel({ onError, onSuccess }), { | ||
wrapper: QueryClientWrapper, | ||
}); | ||
|
||
const editLabelProps = { | ||
projectId, | ||
notebookId, | ||
label: mockedLabel, | ||
}; | ||
result.current.editLabel(editLabelProps); | ||
|
||
await waitFor(() => { | ||
expect(labelApi.editLabel).toHaveBeenCalledWith(editLabelProps); | ||
expect(onSuccess).toHaveBeenCalledWith( | ||
mockedLabel, | ||
editLabelProps, | ||
undefined, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ci-ai-notebooks/src/pages/notebooks/[notebookId]/_components/NotebookHeader.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import { | ||
NotebookText, | ||
Play, | ||
PlayCircle, | ||
PlayIcon, | ||
Square, | ||
Trash2, | ||
} from 'lucide-react'; | ||
import { Badge } from '@/components/ui/badge'; | ||
import { Skeleton } from '@/components/ui/skeleton'; | ||
import * as ai from '@/types/cloud/project/ai'; | ||
import NotebookStatusBadge from '../../_components/NotebookStatusBadge.component'; | ||
import { Button } from '@/components/ui/button'; | ||
|
||
export const NotebookHeader = ({ | ||
notebook, | ||
}: { | ||
notebook: ai.notebook.Notebook; | ||
}) => { | ||
const { t } = useTranslation('regions'); | ||
return ( | ||
<div | ||
data-testid="notebook-header-container" | ||
className="flex gap-2 items-center mt-4 mb-6" | ||
> | ||
<div className="rounded-full bg-gradient-to-tr from-primary to-slate-50 text-white p-2"> | ||
<NotebookText width={40} height={40} /> | ||
</div> | ||
<div className="w-full"> | ||
<div className="flex flex-row items-center gap-8"> | ||
<h2>{notebook.spec.name ?? 'Dashboard'}</h2> | ||
<div className="flex flex-row gap-2"> | ||
<Button type="button" size="roundedIcon"> | ||
<PlayIcon className="size-4 ml-1 fill-white" /> | ||
</Button> | ||
<Button type="button" size="roundedIcon" className="bg-red-400"> | ||
<Square className="size-4 fill-white" /> | ||
</Button> | ||
</div> | ||
</div> | ||
<div className="flex gap-2 flex-wrap"> | ||
<NotebookStatusBadge status={notebook.status.state} /> | ||
<Badge variant={'outline'} className="capitalize"> | ||
{notebook.spec.env.frameworkId} | ||
</Badge> | ||
<Badge variant={'outline'}> | ||
{notebook.spec.env.frameworkVersion} | ||
</Badge> | ||
<Badge variant={'outline'} className="capitalize"> | ||
{t(`region_${notebook.spec.region}`)} | ||
</Badge> | ||
<Badge variant={'outline'} className="capitalize"> | ||
{notebook.spec.env.editorId} | ||
</Badge> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
NotebookHeader.Skeleton = function NotebookHeaderSkeleton() { | ||
return ( | ||
<div className="flex gap-2 items-center mt-4 mb-6"> | ||
<Skeleton className="rounded-full h-14 w-14" /> | ||
<div> | ||
<h2>Dashboard</h2> | ||
<div className="flex gap-2"> | ||
<Skeleton className="h-4 w-10" /> | ||
<Skeleton className="h-4 w-10" /> | ||
<Skeleton className="h-4 w-10" /> | ||
<Skeleton className="h-4 w-10" /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
22 changes: 22 additions & 0 deletions
22
.../pci-ai-notebooks/src/pages/notebooks/[notebookId]/_components/NotebookTabs.component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
import TabsMenu from '@/components/tabs-menu/TabsMenu.component'; | ||
import * as ai from '@/types/cloud/project/ai'; | ||
|
||
interface NotebookTabsProps { | ||
notebook: ai.notebook.Notebook; | ||
} | ||
|
||
const NotebookTabs = ({ notebook }: NotebookTabsProps) => { | ||
const { t } = useTranslation('pci-ai-notebooks/notebooks/notebook'); | ||
|
||
const tabs = [ | ||
{ href: '', label: t('dashboardTab'), end: true }, | ||
{ href: 'attach-data', label: t('dataTab') }, | ||
{ href: 'backup', label: t('backupTab') }, | ||
{ href: 'logs', label: t('logsTab') }, | ||
].filter((tab) => tab); | ||
|
||
return <TabsMenu tabs={tabs} />; | ||
}; | ||
|
||
export default NotebookTabs; |
Oops, something went wrong.