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

vdk-jupyter: convert job operation #2406

Merged
merged 17 commits into from
Jul 24, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
const jestJupyterLab = require('@jupyterlab/testutils/lib/jest-config');

const esModules = [
'@jupyterlab/',
'.*@jupyterlab/',
'@jupyter/ydoc',
'lib0',
'y\\-protocols',
'y\\-websocket',
Expand All @@ -20,7 +21,6 @@ const {
moduleNameMapper,
preset,
setupFilesAfterEnv,
setupFiles,
testPathIgnorePatterns,
transform
} = jlabConfig;
Expand All @@ -30,7 +30,7 @@ module.exports = {
moduleNameMapper,
preset,
setupFilesAfterEnv,
setupFiles,
setupFiles: ['<rootDir>/testutils/jest-setup-files.js'],
testPathIgnorePatterns,
transform,
automock: false,
Expand Down
12,644 changes: 30 additions & 12,614 deletions projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
"stylelint-config-recommended": "6.0.0",
"stylelint-config-standard": "24.0.0",
"stylelint-prettier": "2.0.0",
"ts-jest": "27.1.4"
"ts-jest": "27.1.4",
"jest-fetch-mock": "^3.0.0"
},
"sideEffects": [
"style/*.css",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright 2023-2023 VMware, Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import ConvertJobToNotebookDialog from '../components/ConvertJobToNotebook';
import ConvertJobToNotebookDialog, {
initializeNotebookContent
} from '../components/ConvertJobToNotebook';
import { render, fireEvent } from '@testing-library/react';
import { jobData } from '../jobData';
import { VdkOption } from '../vdkOptions/vdk_options';
Expand Down Expand Up @@ -36,3 +38,65 @@ describe('#onPathChange', () => {
expect(jobData.get(VdkOption.PATH)).toEqual('other/path');
});
});

describe('initializeNotebookContent', () => {
it('should create a notebook content correctly', () => {
const codeStructure = [
'def run(job_input: IJobInput)',
'print("Hello, world!")'
];
const fileNames = ['file1', 'file2'];

const expectedNotebookContent = [
{ source: '#### file1', type: 'markdown' },
{ source: codeStructure[0], type: 'code' },
{ source: 'run(job_input)', type: 'code' },
{ source: '#### file2', type: 'markdown' },
{ source: codeStructure[1], type: 'code' }
];

const result = initializeNotebookContent(codeStructure, fileNames);
expect(result).toEqual(expectedNotebookContent);
});

it('should not add a run cell when there is no run function', () => {
const codeStructure = ['print("Hello, world!")'];
const fileNames = ['file1'];

const expectedNotebookContent = [
{ source: '#### file1', type: 'markdown' },
{ source: codeStructure[0], type: 'code' }
];

const result = initializeNotebookContent(codeStructure, fileNames);
expect(result).toEqual(expectedNotebookContent);
});

it('should return an empty array when codeStructure and fileNames are empty', () => {
const codeStructure: string[] = [];
const fileNames: string[] = [];

const result = initializeNotebookContent(codeStructure, fileNames);
expect(result).toEqual([]);
});

it('should add a run cell for each run function in codeStructure', () => {
const codeStructure = [
'def run(job_input: IJobInput)',
'def run(job_input: IJobInput)'
];
const fileNames = ['file1', 'file2'];

const expectedNotebookContent = [
{ source: '#### file1', type: 'markdown' },
{ source: codeStructure[0], type: 'code' },
{ source: 'run(job_input)', type: 'code' },
{ source: '#### file2', type: 'markdown' },
{ source: codeStructure[1], type: 'code' },
{ source: 'run(job_input)', type: 'code' }
];

const result = initializeNotebookContent(codeStructure, fileNames);
expect(result).toEqual(expectedNotebookContent);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ import { jobdDataRequest } from './serverRequests';
import { VdkOption } from './vdkOptions/vdk_options';
import { workingDirectory } from '.';
import { IDocumentManager } from '@jupyterlab/docmanager';
import { FileBrowser } from '@jupyterlab/filebrowser';
import { INotebookTracker } from '@jupyterlab/notebook';

var runningVdkOperation = false;
export var runningVdkOperation = '';

export function updateVDKMenu(commands: CommandRegistry, docManager: IDocumentManager) {
export function updateVDKMenu(commands: CommandRegistry, docManager: IDocumentManager, fileBrowser: FileBrowser, notebookTracker: INotebookTracker) {
// Add Run job command
add_command(commands, 'jp-vdk:menu-run','Run','Execute VDK Run Command', showRunJobDialog, docManager);
add_command(commands, 'jp-vdk:menu-run', 'Run', 'Execute VDK Run Command', showRunJobDialog, docManager);

// Add Create job command
add_command(commands, 'jp-vdk:menu-create','Create','Execute VDK Create Command', showCreateJobDialog);
add_command(commands, 'jp-vdk:menu-create', 'Create', 'Execute VDK Create Command', showCreateJobDialog);

// Add Download job command
add_command(commands, 'jp-vdk:menu-download','Download','Execute VDK Download Command', showDownloadJobDialog);
add_command(commands, 'jp-vdk:menu-download', 'Download', 'Execute VDK Download Command', showDownloadJobDialog);

// Add Convert Job To Notebook command
add_command(commands, 'jp-vdk:menu-convert-job-to-notebook', 'Convert Job To Notebook', 'Convert Data Job To Jupyter Notebook', showConvertJobToNotebookDialog);
add_command(commands, 'jp-vdk:menu-convert-job-to-notebook', 'Convert Job To Notebook', 'Convert Data Job To Jupyter Notebook', showConvertJobToNotebookDialog, undefined,
fileBrowser, notebookTracker);

// Add Create Deployment command
add_command(commands, 'jp-vdk:menu-create-deployment','Deploy','Create deployment of a VDK job', showCreateDeploymentDialog);
add_command(commands, 'jp-vdk:menu-create-deployment', 'Deploy', 'Create deployment of a VDK job', showCreateDeploymentDialog);
}


Expand All @@ -38,20 +41,23 @@ export function updateVDKMenu(commands: CommandRegistry, docManager: IDocumentMa
*@param getOperationDialog - function that will load the dialog for the command
*/
function add_command(commands: CommandRegistry, schemaNaming: string, label: string, caption: string, getOperationDialog: Function,
docManager?: IDocumentManager){
docManager?: IDocumentManager, fileBrowser?: FileBrowser, notebookTracker?: INotebookTracker) {
commands.addCommand(schemaNaming, {
label: label,
caption: caption,
execute: async () => {
try {
if (!runningVdkOperation) {
runningVdkOperation = true;
runningVdkOperation = schemaNaming;
jobData.set(VdkOption.PATH, workingDirectory);
await jobdDataRequest();
duyguHsnHsn marked this conversation as resolved.
Show resolved Hide resolved
if(docManager) await getOperationDialog(docManager);
else await getOperationDialog();
if (label == 'Convert Job To Notebook') await getOperationDialog(commands, fileBrowser, notebookTracker);
else if (docManager) {
await getOperationDialog(docManager);
}
else await getOperationDialog();
setJobDataToDefault();
runningVdkOperation = false;
runningVdkOperation = '';
} else {
showErrorMessage(
'Another VDK operation is currently running!',
Expand Down
Loading
Loading