Skip to content
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
7 changes: 0 additions & 7 deletions workspaces/frontend/src/__mocks__/utils.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mockModArchResponse } from 'mod-arch-core';
import { pageNotfound } from '~/__tests__/cypress/cypress/pages/pageNotFound';
import { home } from '~/__tests__/cypress/cypress/pages/home';
import { mockNamespaces } from '~/__mocks__/mockNamespaces';
import { mockBFFResponse } from '~/__mocks__/utils';
import { mockWorkspace1 } from '~/shared/mock/mockNotebookServiceData';
import { navBar } from '~/__tests__/cypress/cypress/pages/navBar';

Expand All @@ -12,10 +12,10 @@ describe('Application', () => {

it('Home page should have primary button', () => {
cy.intercept('GET', '/api/v1/namespaces', {
body: mockBFFResponse(mockNamespaces),
body: mockModArchResponse(mockNamespaces),
}).as('getNamespaces');
cy.intercept('GET', `/api/v1/workspaces/${mockNamespaces[0].name}`, {
body: mockBFFResponse([mockWorkspace1]),
body: mockModArchResponse([mockWorkspace1]),
}).as('getWorkspaces');

home.visit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { mockBFFResponse } from '~/__mocks__/utils';
import { mockModArchResponse } from 'mod-arch-core';
import { mockNamespaces } from '~/__mocks__/mockNamespaces';
import { mockWorkspaces } from '~/__tests__/cypress/cypress/tests/mocked/workspace.mock';
import { navBar } from '~/__tests__/cypress/cypress/pages/navBar';

describe('WorkspaceDetailsActivity Component', () => {
beforeEach(() => {
cy.intercept('GET', '/api/v1/namespaces', {
body: mockBFFResponse(mockNamespaces),
body: mockModArchResponse(mockNamespaces),
}).as('getNamespaces');
cy.intercept('GET', '/api/v1/workspaces', {
body: mockBFFResponse(mockWorkspaces),
body: mockModArchResponse(mockWorkspaces),
}).as('getWorkspaces');
cy.intercept('GET', '/api/v1/workspaces/default', {
body: mockBFFResponse(mockWorkspaces),
body: mockModArchResponse(mockWorkspaces),
}).as('getDefaultWorkspaces');
cy.visit('/');
cy.wait('@getNamespaces');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mockModArchResponse } from 'mod-arch-core';
import { mockNamespaces } from '~/__mocks__/mockNamespaces';
import { mockBFFResponse } from '~/__mocks__/utils';
import { home } from '~/__tests__/cypress/cypress/pages/home';
import {
mockWorkspaces,
Expand All @@ -26,11 +26,11 @@ describe('Workspaces Tests', () => {
home.visit();

cy.intercept('GET', '/api/v1/namespaces', {
body: mockBFFResponse(mockNamespaces),
body: mockModArchResponse(mockNamespaces),
}).as('getNamespaces');

cy.intercept('GET', '/api/v1/workspaces', {
body: mockBFFResponse(mockWorkspaces),
body: mockModArchResponse(mockWorkspaces),
}).as('getWorkspaces');
cy.wait('@getWorkspaces');
});
Expand Down Expand Up @@ -65,15 +65,15 @@ describe('Workspace by namespace functionality', () => {
home.visit();

cy.intercept('GET', '/api/v1/namespaces', {
body: mockBFFResponse(mockNamespaces),
body: mockModArchResponse(mockNamespaces),
}).as('getNamespaces');

cy.intercept('GET', '/api/v1/workspaces', { body: mockBFFResponse(mockWorkspaces) }).as(
cy.intercept('GET', '/api/v1/workspaces', { body: mockModArchResponse(mockWorkspaces) }).as(
'getWorkspaces',
);

cy.intercept('GET', '/api/v1/workspaces/kubeflow', {
body: mockBFFResponse(mockWorkspacesByNS),
body: mockModArchResponse(mockWorkspacesByNS),
}).as('getKubeflowWorkspaces');

cy.wait('@getNamespaces');
Expand Down Expand Up @@ -107,14 +107,14 @@ describe('Workspaces Component', () => {

cy.visit('/');
cy.intercept('GET', '/api/v1/namespaces', {
body: mockBFFResponse(mockNamespaces),
body: mockModArchResponse(mockNamespaces),
}).as('getNamespaces');
cy.wait('@getNamespaces');
cy.intercept('GET', '/api/v1/workspaces', {
body: mockBFFResponse(mockWorkspaces),
body: mockModArchResponse(mockWorkspaces),
}).as('getWorkspaces');
cy.intercept('GET', '/api/v1/workspaces/kubeflow', {
body: mockBFFResponse(mockWorkspacesByNS),
body: mockModArchResponse(mockWorkspacesByNS),
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mockModArchResponse } from 'mod-arch-core';
import { mockNamespaces } from '~/__mocks__/mockNamespaces';
import { mockWorkspaces } from '~/__mocks__/mockWorkspaces';
import { mockBFFResponse } from '~/__mocks__/utils';
import { home } from '~/__tests__/cypress/cypress/pages/home';
import { navBar } from '~/__tests__/cypress/cypress/pages/navBar';
import { mockWorkspaceKinds } from '~/shared/mock/mockNotebookServiceData';
Expand All @@ -16,19 +16,19 @@ const useFilter = (filterKey: string, filterName: string, searchValue: string) =
describe('Application', () => {
beforeEach(() => {
cy.intercept('GET', '/api/v1/namespaces', {
body: mockBFFResponse(mockNamespaces),
body: mockModArchResponse(mockNamespaces),
}).as('getNamespaces');
cy.intercept('GET', '/api/v1/workspaces', {
body: mockBFFResponse(mockWorkspaces),
body: mockModArchResponse(mockWorkspaces),
}).as('getWorkspaces');
cy.intercept('GET', '/api/v1/workspaces/default', {
body: mockBFFResponse(mockWorkspaces),
body: mockModArchResponse(mockWorkspaces),
}).as('getDefaultWorkspaces');
cy.intercept('GET', '/api/v1/workspaces/custom-namespace', {
body: mockBFFResponse(mockWorkspaces),
body: mockModArchResponse(mockWorkspaces),
});
cy.intercept('GET', '/api/v1/workspacekinds', {
body: mockBFFResponse(mockWorkspaceKinds),
body: mockModArchResponse(mockWorkspaceKinds),
});
home.visit();
cy.wait('@getNamespaces');
Expand Down
6 changes: 4 additions & 2 deletions workspaces/frontend/src/app/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const useAdminDebugSettings = (): NavDataItem[] => {
return [
{
label: 'Debug',
children: [{ label: 'Notebooks', path: '/notebookDebugSettings' }],
children: [{ label: 'Notebooks', path: AppRoutePaths.notebookDebugSettings }],
},
{
label: 'Workspace kinds',
Expand Down Expand Up @@ -70,8 +70,10 @@ const AppRoutes: React.FC = () => {
path={AppRoutePaths.root}
element={<Navigate to={AppRoutePaths.workspaces} replace />}
/>
{user?.clusterAdmin && (
<Route path={AppRoutePaths.notebookDebugSettings} element={<Debug />} />
)}
<Route path="*" element={<NotFound />} />
{user?.clusterAdmin && <Route path="/notebookDebugSettings/*" element={<Debug />} />}
</Routes>
);
};
Expand Down
3 changes: 1 addition & 2 deletions workspaces/frontend/src/app/context/useNotebookAPIState.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback } from 'react';
import { useAPIState, APIState } from 'mod-arch-core';
import { NotebookApis, notebookApisImpl } from '~/shared/api/notebookApi';
import { APIState } from '~/shared/api/types';
import useAPIState from '~/shared/api/useAPIState';
import { mockNotebookApisImpl } from '~/shared/mock/mockNotebookApis';
import { MOCK_API_ENABLED } from '~/shared/utilities/const';

Expand Down
52 changes: 0 additions & 52 deletions workspaces/frontend/src/app/hooks/__tests__/useNamespaces.spec.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions workspaces/frontend/src/app/hooks/useNamespaces.ts

This file was deleted.

5 changes: 2 additions & 3 deletions workspaces/frontend/src/app/hooks/useWorkspaceCountPerKind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { WorkspaceCountPerOption } from '~/app/types';
import { WorkspacekindsWorkspaceKind, WorkspacesWorkspace } from '~/generated/data-contracts';
import { NotebookApis } from '~/shared/api/notebookApi';

export type WorkspaceCountPerKind = Record<
WorkspacekindsWorkspaceKind['name'],
WorkspaceCountPerOption
export type WorkspaceCountPerKind = Partial<
Record<WorkspacekindsWorkspaceKind['name'], WorkspaceCountPerOption>
>;

export const useWorkspaceCountPerKind = (): WorkspaceCountPerKind => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const WorkspaceKindForm: React.FC = () => {

if (createResult.ok) {
notification.success(
`Workspace kind '${createResult.data.data.name}' created successfully`,
`Workspace kind '${createResult.result.data.name}' created successfully`,
);
navigate('workspaceKinds');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ export const WorkspaceKindDetailsImages: React.FunctionComponent<WorkspaceDetail
workspaceCountRouteState: {
imageId: image.id,
},
workspaceCount:
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
workspaceCountPerKind[workspaceKind.name]
? (workspaceCountPerKind[workspaceKind.name].countByImage[image.id] ?? 0)
: 0,
workspaceCount: workspaceCountPerKind[workspaceKind.name]?.countByImage[image.id] ?? 0,
}))}
tableKind="image"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,17 @@ export const WorkspaceKindDetailsNamespaces: React.FunctionComponent<
WorkspaceDetailsNamespacesProps
> = ({ workspaceKind, workspaceCountPerKind }) => (
<WorkspaceKindDetailsTable
rows={Object.keys(
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
workspaceCountPerKind[workspaceKind.name]
? workspaceCountPerKind[workspaceKind.name].countByNamespace
: [],
).map((namespace, rowIndex) => ({
id: String(rowIndex),
displayName: namespace,
kindName: workspaceKind.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
workspaceCount: workspaceCountPerKind[workspaceKind.name]
? workspaceCountPerKind[workspaceKind.name].countByNamespace[namespace]
: 0,
workspaceCountRouteState: {
namespace,
},
}))}
rows={Object.keys(workspaceCountPerKind[workspaceKind.name]?.countByNamespace ?? {}).map(
(namespace, rowIndex) => ({
id: String(rowIndex),
displayName: namespace,
kindName: workspaceKind.name,
workspaceCount: workspaceCountPerKind[workspaceKind.name]?.countByNamespace[namespace] ?? 0,
workspaceCountRouteState: {
namespace,
},
}),
)}
tableKind="namespace"
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ export const WorkspaceKindDetailsPodConfigs: React.FunctionComponent<
id: podConfig.id,
displayName: podConfig.displayName,
kindName: workspaceKind.name,
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
workspaceCount: workspaceCountPerKind[workspaceKind.name]
? (workspaceCountPerKind[workspaceKind.name].countByPodConfig[podConfig.id] ?? 0)
: 0,
workspaceCount:
workspaceCountPerKind[workspaceKind.name]?.countByPodConfig[podConfig.id] ?? 0,
workspaceCountRouteState: {
podConfigId: podConfig.id,
},
Expand Down
2 changes: 2 additions & 0 deletions workspaces/frontend/src/app/pages/notFound/NotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
import { PageSection } from '@patternfly/react-core/dist/esm/components/Page';
import { useTypedNavigate } from '~/app/routerHelper';

// TODO: replace with mod-arch-shared NotFound component
// Currently, not possible because mod-arch-shared version assumes home route is '/'
const NotFound: React.FunctionComponent = () => {
function GoHomeBtn() {
const navigate = useTypedNavigate();
Expand Down
4 changes: 4 additions & 0 deletions workspaces/frontend/src/app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const AppRoutePaths = {
workspaceKindSummary: '/workspacekinds/:kind/summary',
workspaceKindCreate: '/workspacekinds/create',
workspaceKindEdit: '/workspacekinds/:kind/edit',
notebookDebugSettings: '/notebookDebugSettings',
} satisfies Record<string, `/${string}`>;

export type AppRoute = (typeof AppRoutePaths)[keyof typeof AppRoutePaths];
Expand Down Expand Up @@ -35,6 +36,7 @@ export type RouteParamsMap = {
workspaceKindEdit: {
kind: string;
};
notebookDebugSettings: undefined;
};

/**
Expand Down Expand Up @@ -69,6 +71,7 @@ export type RouteStateMap = {
workspaceKindEdit: {
workspaceKindName: string;
};
notebookDebugSettings: undefined;
};

/**
Expand All @@ -90,4 +93,5 @@ export type RouteSearchParamsMap = {
workspaceKindSummary: undefined;
workspaceKindCreate: undefined;
workspaceKindEdit: undefined;
notebookDebugSettings: undefined;
};
4 changes: 2 additions & 2 deletions workspaces/frontend/src/shared/api/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function isApiErrorEnvelope(data: unknown): data is ApiErrorEnvelope {

export async function safeApiCall<T>(fn: () => Promise<T>): Promise<ApiCallResult<T>> {
try {
const data = await fn();
return { ok: true, data };
const result = await fn();
return { ok: true, result };
} catch (error: unknown) {
if (axios.isAxiosError<ApiErrorEnvelope>(error)) {
const apiError = error.response?.data;
Expand Down
Loading