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

fix: poll kernelSpec after serverManager ready #81

Merged
merged 3 commits into from
Feb 28, 2024
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
11 changes: 7 additions & 4 deletions packages/libro-jupyter/src/file/file-create-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const FileCreateModalComponent: React.FC<ModalItemProps<ModalItemType>> =
}: ModalItemProps<ModalItemType>) => {
const fileService = useInject(JupyterFileService);
const viewManager = useInject(ViewManager);
const [fileType, setFileType] = useState<FileType>(data.fileType);
const [fileType, setFileType] = useState<FileType>(data?.fileType);
const [fileView, setFileView] = useState<FileView>();
const inputRef = useRef<InputRef>(null);
const [form] = Form.useForm();
Expand All @@ -37,7 +37,10 @@ export const FileCreateModalComponent: React.FC<ModalItemProps<ModalItemType>> =
await form.validateFields();
close();
try {
await fileService.newFile(values.fileName + (fileType || ''), new URI(data.path));
await fileService.newFile(
values.fileName + (fileType || ''),
new URI(data?.path),
);
if (fileView) {
fileView.model.refresh();
}
Expand All @@ -50,7 +53,7 @@ export const FileCreateModalComponent: React.FC<ModalItemProps<ModalItemType>> =
if (!value || !value.length) {
throw new Error('请输入文件名');
} else {
const targetURI = new URI(data.path + value + (fileType || ''));
const targetURI = new URI(data?.path + value + (fileType || ''));
const fileRes = await fileService.resolve(targetURI);
if (fileRes.isFile) {
throw new Error('文件名称已存在,请重新输入');
Expand Down Expand Up @@ -86,7 +89,7 @@ export const FileCreateModalComponent: React.FC<ModalItemProps<ModalItemType>> =
>
<div className="libro-create-file-path-container">
<div className="libro-create-file-des">创建位置:</div>
<span className="libro-create-file-path">{data.path}</span>
<span className="libro-create-file-path">{data?.path}</span>
</div>
<div className="libro-create-file-des">文件类型:</div>
<Row>
Expand Down
6 changes: 3 additions & 3 deletions packages/libro-jupyter/src/file/file-createdir-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const FileCreateDirModalComponent: React.FC<
await form.validateFields();
close();
try {
await fileService.newFileDir(values.dirName, new URI(data.path));
await fileService.newFileDir(values.dirName, new URI(data?.path));
if (fileView) {
fileView.model.refresh();
}
Expand All @@ -40,7 +40,7 @@ export const FileCreateDirModalComponent: React.FC<
if (!value || !value.length) {
throw new Error('请输入文件夹名');
} else {
const targetURI = new URI(data.path + value);
const targetURI = new URI(data?.path + value);
const fileRes = await fileService.resolve(targetURI);
if (fileRes.isDirectory) {
throw new Error('文件夹名称已存在,请重新输入');
Expand Down Expand Up @@ -75,7 +75,7 @@ export const FileCreateDirModalComponent: React.FC<
width={524}
>
<div className="libro-create-file-des">创建位置:</div>
<span className="libro-create-file-path">{data.path}</span>
<span className="libro-create-file-path">{data?.path}</span>
<Form
layout="vertical"
autoComplete="off"
Expand Down
13 changes: 7 additions & 6 deletions packages/libro-jupyter/src/file/file-rename-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ export const FileRenameModalComponent: React.FC<ModalItemProps<ModalItemType>> =
await form.validateFields();
close();
try {
await fileService.rename(data.resource, values.rename);

if (fileView) {
fileView.model.refresh();
if (data && data.resource) {
await fileService.rename(data.resource, values.rename);
if (fileView) {
fileView.model.refresh();
}
}
} catch {
message.error('重命名文件/文件夹失败');
Expand All @@ -54,7 +55,7 @@ export const FileRenameModalComponent: React.FC<ModalItemProps<ModalItemType>> =
if (!value || !value.length) {
throw new Error('请输入文件夹名');
} else {
if (value === data.fileName) {
if (value === data?.fileName) {
throw new Error('文件/文件夹名称已存在,请重新输入');
}
}
Expand All @@ -81,7 +82,7 @@ export const FileRenameModalComponent: React.FC<ModalItemProps<ModalItemType>> =
name="rename"
label="文件/文件夹名称"
rules={[{ required: true, validator: validateRename }]}
initialValue={data.fileName}
initialValue={data?.fileName}
>
<Input
ref={inputRef}
Expand Down
11 changes: 11 additions & 0 deletions packages/libro-jupyter/src/toolbar/kernel-selector-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ function getKernelListItems(
key: 'divider1',
type: 'divider', // Must have
},
{
key: 'RestartKernel',
label: 'Restart the Kernel',
},
{
key: 'ShutDownKernel',
label: 'Shut Down the Kernel',
Expand Down Expand Up @@ -130,6 +134,13 @@ export const KernelSelector: React.FC = () => {
}
}

if (selectValue === 'RestartKernel') {
libroView.model.kernelConnecting = false;
if (libroView.model.restart) {
libroView.model.restart();
}
}

const kernelInfoFromOtherKernelList = otherKernelList.filter(
(k) => k.name === selectValue,
);
Expand Down
27 changes: 8 additions & 19 deletions packages/libro-kernel/src/kernelspec/manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { deepEqual, Poll } from '@difizen/libro-common';
import type { Event as ManaEvent } from '@difizen/mana-app';
import { getOrigin } from '@difizen/mana-app';
import { Emitter, Deferred } from '@difizen/mana-app';
import { inject, singleton } from '@difizen/mana-app';
import { prop } from '@difizen/mana-app';
Expand Down Expand Up @@ -28,21 +29,6 @@ export class KernelSpecManager extends BaseManager implements KernelSpec.IManage
*/
constructor() {
super();

// Initialize internal data.
this._ready = Promise.all([this.requestSpecs()])
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.then((_) => undefined)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.catch((_) => undefined)
.then(() => {
if (this.isDisposed) {
return;
}
this._isReady = true;
return;
});

this._pollSpecs = new Poll({
auto: false,
factory: () => this.requestSpecs(),
Expand All @@ -55,10 +41,13 @@ export class KernelSpecManager extends BaseManager implements KernelSpec.IManage
standby: 'when-hidden',
// standby: options.standby ?? 'when-hidden',
});
void this.ready.then(() => {
void this._pollSpecs.start();
return;
});
// Initialize internal data.
this._ready = (async () => {
await this.serverManager.ready;
await getOrigin(this._pollSpecs).start();
await getOrigin(this._pollSpecs).tick;
this._isReady = true;
})();
}

/**
Expand Down
Loading