forked from kubeflow/notebooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ws): Notebooks 2.0 // Frontend // Workspaces table // Workspace …
…Kind column kubeflow#148 (kubeflow#177) * Merge notebooks-v2 into kind_logo_modification/kubeflow#148 branch Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com> * feat(ws): Notebooks 2.0 // Frontend // Workspaces table // Workspace Kind column kubeflow#148 Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com> * feat(ws): Notebooks 2.0 // Frontend // Workspaces table // Workspace Kind column kubeflow#148 Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com> * feat(ws): Notebooks 2.0 // Frontend // Workspaces table // Workspace Kind column kubeflow#148 Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com> * feat(ws): Notebooks 2.0 // Frontend // Workspaces table // Workspace Kind column kubeflow#148 Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com> * feat(ws): Notebooks 2.0 // Frontend // Workspaces table // Workspace Kind column kubeflow#148 Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com> * feat(ws): Notebooks 2.0 // Frontend // Workspaces table // Workspace Kind column kubeflow#148 Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com> --------- Signed-off-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com> Co-authored-by: Liav Weiss (EXT-Nokia) <liav.weiss.ext@nokia.com>
- Loading branch information
Showing
11 changed files
with
283 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
65 changes: 65 additions & 0 deletions
65
workspaces/frontend/src/__tests__/cypress/cypress/tests/e2e/workspaceKind.cy.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,65 @@ | ||
import { | ||
mockWorkspaceKindsInValid, | ||
mockWorkspaceKindsValid, | ||
} from '~/__tests__/cypress/cypress/tests/mocked/workspaceKinds.mock'; | ||
|
||
describe('Test buildKindLogoDictionary Functionality', () => { | ||
// Mock valid workspace kinds | ||
context('With Valid Data', () => { | ||
before(() => { | ||
// Mock the API response | ||
cy.intercept('GET', '/api/v1/workspacekinds', { | ||
statusCode: 200, | ||
body: mockWorkspaceKindsValid, | ||
}); | ||
|
||
// Visit the page | ||
cy.visit('/'); | ||
}); | ||
|
||
it('should fetch and populate kind logos', () => { | ||
// Check that the logos are rendered in the table | ||
cy.get('tbody tr').each(($row) => { | ||
cy.wrap($row) | ||
.find('td[data-label="Kind"]') | ||
.within(() => { | ||
cy.get('img') | ||
.should('exist') | ||
.then(($img) => { | ||
// Ensure the image is fully loaded | ||
cy.wrap($img[0]).should('have.prop', 'complete', true); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
// Mock invalid workspace kinds | ||
context('With Invalid Data', () => { | ||
before(() => { | ||
// Mock the API response for invalid workspace kinds | ||
cy.intercept('GET', '/api/v1/workspacekinds', { | ||
statusCode: 200, | ||
body: mockWorkspaceKindsInValid, | ||
}); | ||
|
||
// Visit the page | ||
cy.visit('/'); | ||
}); | ||
|
||
it('should show a fallback icon when the logo URL is missing', () => { | ||
cy.get('tbody tr').each(($row) => { | ||
cy.wrap($row) | ||
.find('td[data-label="Kind"]') | ||
.within(() => { | ||
// Ensure that the image is NOT rendered (because it's invalid or missing) | ||
cy.get('img').should('not.exist'); // No images should be displayed | ||
|
||
// Check if the fallback icon (TimesCircleIcon) is displayed | ||
cy.get('svg').should('exist'); // Look for the SVG (TimesCircleIcon) | ||
cy.get('svg').should('have.class', 'pf-v6-svg'); // Ensure the correct fallback icon class is applied (update the class name based on your icon library) | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
74 changes: 74 additions & 0 deletions
74
workspaces/frontend/src/__tests__/cypress/cypress/tests/mocked/workspaceKinds.mock.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,74 @@ | ||
import type { WorkspaceKind } from '~/shared/types'; | ||
|
||
// Factory function to create a valid WorkspaceKind | ||
function createMockWorkspaceKind(overrides: Partial<WorkspaceKind> = {}): WorkspaceKind { | ||
return { | ||
name: 'jupyter-lab', | ||
displayName: 'JupyterLab Notebook', | ||
description: 'A Workspace which runs JupyterLab in a Pod', | ||
deprecated: false, | ||
deprecationMessage: '', | ||
hidden: false, | ||
icon: { | ||
url: 'https://jupyter.org/assets/favicons/apple-touch-icon-152x152.png', | ||
}, | ||
logo: { | ||
url: 'https://upload.wikimedia.org/wikipedia/commons/3/38/Jupyter_logo.svg', | ||
}, | ||
podTemplate: { | ||
podMetadata: { | ||
labels: { myWorkspaceKindLabel: 'my-value' }, | ||
annotations: { myWorkspaceKindAnnotation: 'my-value' }, | ||
}, | ||
volumeMounts: { home: '/home/jovyan' }, | ||
options: { | ||
imageConfig: { | ||
default: 'jupyterlab_scipy_190', | ||
values: [ | ||
{ | ||
id: 'jupyterlab_scipy_180', | ||
displayName: 'jupyter-scipy:v1.8.0', | ||
labels: { pythonVersion: '3.11' }, | ||
hidden: true, | ||
redirect: { | ||
to: 'jupyterlab_scipy_190', | ||
message: { | ||
text: 'This update will change...', | ||
level: 'Info', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
podConfig: { | ||
default: 'tiny_cpu', | ||
values: [ | ||
{ | ||
id: 'tiny_cpu', | ||
displayName: 'Tiny CPU', | ||
description: 'Pod with 0.1 CPU, 128 Mb RAM', | ||
labels: { cpu: '100m', memory: '128Mi' }, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
...overrides, // Allows customization | ||
}; | ||
} | ||
|
||
// Generate valid mock data with "data" property | ||
export const mockWorkspaceKindsValid = { | ||
data: [createMockWorkspaceKind()], | ||
}; | ||
|
||
// Generate invalid mock data with "data" property | ||
export const mockWorkspaceKindsInValid = { | ||
data: [ | ||
createMockWorkspaceKind({ | ||
logo: { | ||
url: '', | ||
}, | ||
}), | ||
], | ||
}; |
21 changes: 21 additions & 0 deletions
21
workspaces/frontend/src/app/actions/WorkspaceKindsActions.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,21 @@ | ||
import { WorkspaceKind } from '~/shared/types'; | ||
|
||
type KindLogoDict = Record<string, string>; | ||
|
||
/** | ||
* Builds a dictionary of kind names to logos, and returns it. | ||
* @param {WorkspaceKind[]} workspaceKinds - The list of workspace kinds. | ||
* @returns {KindLogoDict} A dictionary with kind names as keys and logo URLs as values. | ||
*/ | ||
export function buildKindLogoDictionary(workspaceKinds: WorkspaceKind[] | []): KindLogoDict { | ||
const kindLogoDict: KindLogoDict = {}; | ||
|
||
for (const workspaceKind of workspaceKinds) { | ||
try { | ||
kindLogoDict[workspaceKind.name] = workspaceKind.logo.url; | ||
} catch { | ||
kindLogoDict[workspaceKind.name] = ''; | ||
} | ||
} | ||
return kindLogoDict; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as React from 'react'; | ||
import useFetchState, { | ||
FetchState, | ||
FetchStateCallbackPromise, | ||
} from '~/shared/utilities/useFetchState'; | ||
import { WorkspaceKind } from '~/shared/types'; | ||
import { useNotebookAPI } from '~/app/hooks/useNotebookAPI'; | ||
|
||
const useWorkspaceKinds = (): FetchState<WorkspaceKind[]> => { | ||
const { api, apiAvailable } = useNotebookAPI(); | ||
const call = React.useCallback<FetchStateCallbackPromise<WorkspaceKind[]>>( | ||
(opts) => { | ||
if (!apiAvailable) { | ||
return Promise.reject(new Error('API not yet available')); | ||
} | ||
return api.getWorkspaceKinds(opts); | ||
}, | ||
[api, apiAvailable], | ||
); | ||
|
||
return useFetchState(call, []); | ||
}; | ||
|
||
export default useWorkspaceKinds; |
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
Oops, something went wrong.