Skip to content

Commit

Permalink
feat(ai.notebooks): fix types issue
Browse files Browse the repository at this point in the history
REF:DATATR-1641
Signed-off-by: Arthur Bullet <[email protected]>
  • Loading branch information
abullet33 committed Dec 12, 2024
1 parent 8a6f803 commit 1db7679
Show file tree
Hide file tree
Showing 21 changed files with 127 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as ai from '@/types/cloud/project/ai';

export const mockedDataSyncSpec: ai.volume.DataSyncSpec = {
direction: ai.volume.DataSyncEnum.pull,
manual: true,
volume: '1934e1d3-2ba0-4000-8fd3-6f11081e4401',
};

Expand All @@ -10,7 +11,35 @@ export const mockedDataSync: ai.volume.DataSync = {
id: 'idDuDataSync',
spec: {
direction: ai.volume.DataSyncEnum.pull,
manual: true,
volume: '1934e1d3-2ba0-4000-8fd3-6f11081e4401',
},
status: {
endedAt: 'endedAT',
info: {
code: ai.InfoCodeEnum.APP_ERROR,
message: 'error_message',
},
progress: [
{
completed: 1,
createdAt: 'createdAt',
deleted: 1,
direction: ai.volume.DataSyncEnum.pull,
failed: 3,
id: 'id',
info: 'info',
processed: 1,
skipped: 1,
state: ai.volume.DataSyncProgressStateEnum.DONE,
total: 1,
transferredBytes: 1,
updatedAt: 'updatedAt',
},
],
queuedAt: 'queudAt',
startedAt: 'startedAt',
state: ai.volume.DataSyncStateEnum.DONE,
},
updatedAt: 'updatedAt',
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,37 @@ export const mockedJobStatus: ai.job.JobStatus = {
dataSync: [
{
createdAt: 'createdAt',
id: 'datasyncId',
id: 'idDuDataSync',
spec: {
direction: ai.volume.DataSyncEnum.pull,
manual: true,
volume: '1934e1d3-2ba0-4000-8fd3-6f11081e4401',
},
status: {
endedAt: 'endedAT',
info: {
code: ai.InfoCodeEnum.APP_RUNNING,
message: 'message',
code: ai.InfoCodeEnum.APP_ERROR,
message: 'error_message',
},
progress: [
{
completed: 1,
createdAt: 'createdAt',
deleted: 0,
direction: ai.volume.DataSyncEnum.push,
failed: 0,
id: 'progressId',
deleted: 1,
direction: ai.volume.DataSyncEnum.pull,
failed: 3,
id: 'id',
info: 'info',
processed: 3,
processed: 1,
skipped: 1,
state: ai.volume.DataSyncProgressStateEnum.DONE,
total: 2,
transferredBytes: 30,
total: 1,
transferredBytes: 1,
updatedAt: 'updatedAt',
},
],
queuedAt: 'queuedAt',
queuedAt: 'queudAt',
startedAt: 'startedAt',
state: ai.volume.DataSyncStateEnum.DONE,
},
updatedAt: 'updatedAt',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,37 @@ export const mockedNotebookStatus: ai.notebook.NotebookStatus = {
dataSync: [
{
createdAt: 'createdAt',
id: 'datasyncId',
id: 'idDuDataSync',
spec: {
direction: ai.volume.DataSyncEnum.pull,
manual: true,
volume: '1934e1d3-2ba0-4000-8fd3-6f11081e4401',
},
status: {
endedAt: 'endedAT',
info: {
code: ai.InfoCodeEnum.APP_RUNNING,
message: 'message',
code: ai.InfoCodeEnum.APP_ERROR,
message: 'error_message',
},
progress: [
{
completed: 1,
createdAt: 'createdAt',
deleted: 0,
direction: ai.volume.DataSyncEnum.push,
failed: 0,
id: 'progressId',
deleted: 1,
direction: ai.volume.DataSyncEnum.pull,
failed: 3,
id: 'id',
info: 'info',
processed: 3,
processed: 1,
skipped: 1,
state: ai.volume.DataSyncProgressStateEnum.DONE,
total: 2,
transferredBytes: 30,
total: 1,
transferredBytes: 1,
updatedAt: 'updatedAt',
},
],
queuedAt: 'queuedAt',
queuedAt: 'queudAt',
startedAt: 'startedAt',
state: ai.volume.DataSyncStateEnum.DONE,
},
updatedAt: 'updatedAt',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as ai from '@/types/cloud/project/ai';

export const mockedEditor: ai.notebook.Editor = {
export const mockedEditor: ai.capabilities.notebook.Editor = {
description: 'description',
docUrl: 'docURl',
id: 'editorId',
logoUrl: 'logo',
name: 'EditorName',
version: 'version',
versions: ['version'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ export const mockedSshKey: sshkey.SshKey = {
publicKey: 'publicKey',
regions: ['GRA'],
};

export const mockedSshKeyDetail: sshkey.SshKeyDetail = {
fingerPrint: 'fingerPrint',
id: 'id',
name: 'name',
publicKey: 'publicKey',
regions: ['GRA', 'BHS'],
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export const getEditor = async ({ projectId }: PCIAi) =>
'X-Pagination-Size': '50000',
},
})
.then((res) => res.data as ai.notebook.Editor[]);
.then((res) => res.data as ai.capabilities.notebook.Editor[]);
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export const getFramework = async ({ projectId }: PCIAi) =>
'X-Pagination-Size': '50000',
},
})
.then((res) => res.data as ai.notebook.Framework[]);
.then((res) => res.data as ai.capabilities.notebook.Framework[]);
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getNotebook = async ({ projectId, notebookId }: NotebookData) =>
.then((res) => res.data as ai.notebook.Notebook);

export interface AddNotebook extends PCIAi {
notebookInfo: ai.notebook.NotebookSpec;
notebookInfo: ai.notebook.NotebookSpecInput;
}
export const addNotebook = async ({ projectId, notebookInfo }: AddNotebook) =>
apiClient.v6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function useGetEditor(
queryKey,
queryFn: () => getEditor({ projectId }),
...options,
}) as UseQueryResult<ai.notebook.Editor[], Error>;
}) as UseQueryResult<ai.capabilities.notebook.Editor[], Error>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function useGetFramework(
queryKey,
queryFn: () => getFramework({ projectId }),
...options,
}) as UseQueryResult<ai.notebook.Editor[], Error>;
}) as UseQueryResult<ai.capabilities.notebook.Framework[], Error>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useAddNotebook({ onError, onSuccess }: AddNotebookProps) {
const queryClient = useQueryClient();
const { projectId } = useParams();
const mutation = useMutation({
mutationFn: (notebookInfo: ai.notebook.NotebookSpec) => {
mutationFn: (notebookInfo: ai.notebook.NotebookSpecInput) => {
return addNotebook({ projectId, notebookInfo });
},
onError,
Expand All @@ -30,7 +30,7 @@ export function useAddNotebook({ onError, onSuccess }: AddNotebookProps) {
});

return {
addNotebook: (notebookInfo: ai.notebook.NotebookSpec) => {
addNotebook: (notebookInfo: ai.notebook.NotebookSpecInput) => {
return mutation.mutate(notebookInfo);
},
...mutation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useGetCommand({ onError, onSuccess }: GetCommandProps) {
const queryClient = useQueryClient();
const { projectId } = useParams();
const mutation = useMutation({
mutationFn: (notebookInfo: ai.notebook.NotebookSpec) => {
mutationFn: (notebookInfo: ai.notebook.NotebookSpecInput) => {
return getCommand({ projectId, notebookInfo });
},
onError,
Expand All @@ -30,7 +30,7 @@ export function useGetCommand({ onError, onSuccess }: GetCommandProps) {
});

return {
getCommand: (notebookInfo: ai.notebook.NotebookSpec) => {
getCommand: (notebookInfo: ai.notebook.NotebookSpecInput) => {
return mutation.mutate(notebookInfo);
},
...mutation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useAddSshKey({ onError, onAddKeySuccess }: UseAddSshKey) {
const mutation = useMutation({
mutationFn: (sshKey: AddSSHKey) => addSSHKey(sshKey),
onError,
onSuccess: (data: sshkey.SshKey) => {
onSuccess: (data: sshkey.SshKeyDetail) => {
onAddKeySuccess(data);
// Invalidate service list query to get the latest data
queryClient.invalidateQueries({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { renderHook, waitFor } from '@testing-library/react';
import { vi } from 'vitest';
import { QueryClientWrapper } from '@/__tests__/helpers/wrappers/QueryClientWrapper';
import * as sshkeyApi from '@/data/api/sshkey/sshkey.api';
import { mockedSshKey } from '@/__tests__/helpers/mocks/sshkey';
import {
mockedSshKey,
mockedSshKeyDetail,
} from '@/__tests__/helpers/mocks/sshkey';
import { useAddSshKey } from './useAddSshKey.hook';

vi.mock('@/data/api/sshkey/sshkey.api', () => ({
Expand All @@ -14,7 +17,7 @@ describe('useAddSshKey', () => {
const onAddKeySuccess = vi.fn();
const onError = vi.fn();

vi.mocked(sshkeyApi.addSSHKey).mockResolvedValue(mockedSshKey);
vi.mocked(sshkeyApi.addSSHKey).mockResolvedValue(mockedSshKeyDetail);

const { result } = renderHook(
() => useAddSshKey({ onError, onAddKeySuccess }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,32 @@ export function humanizeFramework(
}

export function getNotebookSpec(formResult: NotebookOrderResult) {
const notebookInfos: ai.notebook.NotebookSpec = {
env: {
frameworkId: formResult.framework.id,
frameworkVersion: formResult.version,
editorId: formResult.editor.id,
},
const notebookEnv: ai.notebook.NotebookEnv = {
frameworkId: formResult.framework.id,
frameworkVersion: formResult.version,
editorId: formResult.editor.id,
};
const notebookResource: ai.ResourcesInput =
formResult.flavor.type === ai.capabilities.FlavorTypeEnum.cpu
? {
flavor: formResult.flavor.id,
cpu: Number(formResult.resourcesQuantity),
}
: {
flavor: formResult.flavor.id,
gpu: Number(formResult.resourcesQuantity),
};

const notebookInfos: ai.notebook.NotebookSpecInput = {
env: notebookEnv,
resources: notebookResource,
name: formResult.notebookName,
region: formResult.region.id,
unsecureHttp: formResult.unsecureHttp,
sshPublicKeys: formResult.sshKey,
labels: formResult.labels,
};

if (formResult.flavor.type === ai.capabilities.FlavorTypeEnum.cpu) {
notebookInfos.resources = {
flavor: formResult.flavor.id,
cpu: Number(formResult.resourcesQuantity),
};
} else {
notebookInfos.resources = {
flavor: formResult.flavor.id,
gpu: Number(formResult.resourcesQuantity),
};
}

if (formResult.volumes.length > 0) {
notebookInfos.volumes = formResult.volumes.map((volume: OrderVolumes) => ({
cache: volume.cache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const DataSync = ({
const onSubmit = form.handleSubmit((formValues) => {
const dataSyncFormValues: ai.volume.DataSyncSpec = {
direction: formValues.type,
manual: true,
};
if (volume)
dataSyncFormValues.volume = notebook.status.volumes.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const Dashboard = () => {
const { notebook, projectId } = useNotebookData();
const { t } = useTranslation('pci-ai-notebooks/notebooks/notebook/dashboard');
const { toast } = useToast();
const [command, setCommand] = useState<ai.Command>({});
const [command, setCommand] = useState<ai.Command>();

const { getCommand } = useGetCommand({
onError: (err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const OrderFunnel = ({
const navigate = useNavigate();

const { toast } = useToast();
const [command, setCommand] = useState<ai.Command>({});
const [command, setCommand] = useState<ai.Command>({ command: '' });

const addSshKeyModale = useModale('addSshKey');
const { addNotebook, isPending: isPendingAddNotebook } = useAddNotebook({
Expand Down Expand Up @@ -122,15 +122,15 @@ const OrderFunnel = ({
});

const getCliCommand = () => {
const notebookInfos: ai.notebook.NotebookSpec = getNotebookSpec(
const notebookInfos: ai.notebook.NotebookSpecInput = getNotebookSpec(
model.result,
);
getCommand(notebookInfos);
};

const onSubmit = model.form.handleSubmit(
() => {
const notebookInfos: ai.notebook.NotebookSpec = getNotebookSpec(
const notebookInfos: ai.notebook.NotebookSpecInput = getNotebookSpec(
model.result,
);
addNotebook(notebookInfos);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface Guide {
section: string;
lang: string;
slug: string;
title: string;
excerpt: string;
url: string;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import exp from 'constants';
import * as app from './app/index';
import * as capabilities from './capabilities/index';
import * as job from './job/index';
Expand All @@ -19,6 +20,7 @@ export * from './DataStoreTypeEnum';
export * from './Env';
export * from './GenericResponse';
export * from './GitCredentialsInput';
export * from './Guide';
export * from './Info';
export * from './InfoCodeEnum';
export * from './Label';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** SshKey */
export interface SshKey {
/** SSH key id */
id: string;
id?: string;
/** SSH key name */
name: string;
/** SSH public key */
publicKey: string;
/** SSH key regions */
regions: string[];
regions?: string[];
}

0 comments on commit 1db7679

Please sign in to comment.