Skip to content

Commit

Permalink
Fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix616 committed Oct 7, 2024
1 parent 44f2eb7 commit 3e79165
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
34 changes: 20 additions & 14 deletions packages/blockly/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,36 +169,42 @@ export class BlocklyManager {
private _filterContents(contents: ToolboxItemInfo[]): number {
let visible = 0;
contents.forEach(itemInfo => {
if ("kind" in itemInfo) {
if (itemInfo.kind.toUpperCase() === "CATEGORY") {
if ("contents" in itemInfo) {
if ('kind' in itemInfo) {
if (itemInfo.kind.toUpperCase() === 'CATEGORY') {
if ('contents' in itemInfo) {
const categoryInfo = itemInfo as StaticCategoryInfo;
if (this._filterContents(categoryInfo.contents) > 0) {
visible++;
categoryInfo.hidden = "false";
categoryInfo.hidden = 'false';
} else {
categoryInfo.hidden = "true";
categoryInfo.hidden = 'true';
}
} else if ("custom" in itemInfo) {
} else if ('custom' in itemInfo) {
const categoryInfo = itemInfo as DynamicCategoryInfo;
if (this._allowedBlocks === undefined || this._allowedBlocks.includes(categoryInfo.custom.toLowerCase())) {
categoryInfo.hidden = "false";
if (
this._allowedBlocks === undefined ||
this._allowedBlocks.includes(categoryInfo.custom.toLowerCase())
) {
categoryInfo.hidden = 'false';
visible++;
console.log("Category " + categoryInfo.custom + " is allowed");
console.log(`Category ${categoryInfo.custom} is allowed`);
} else {
categoryInfo.hidden = "true";
console.log("Category " + categoryInfo.custom + " is not allowed");
categoryInfo.hidden = 'true';
console.log(`Category ${categoryInfo.custom} is not allowed`);
}
}
} else if (itemInfo.kind.toUpperCase() === "BLOCK") {
} else if (itemInfo.kind.toUpperCase() === 'BLOCK') {
const blockInfo = itemInfo as BlockInfo;
if (this._allowedBlocks === undefined || this._allowedBlocks.includes(blockInfo.type.toLowerCase())) {
if (
this._allowedBlocks === undefined ||
this._allowedBlocks.includes(blockInfo.type.toLowerCase())
) {
blockInfo.disabled = false;
blockInfo.disabledReasons = [];
visible++;
} else {
blockInfo.disabled = true;
blockInfo.disabledReasons = ["This block is not allowed"];
blockInfo.disabledReasons = ['This block is not allowed'];
}
}
}
Expand Down
30 changes: 19 additions & 11 deletions packages/blockly/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
} from '@jupyterlab/docregistry';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { runIcon } from '@jupyterlab/ui-components';
import { showErrorMessage } from "@jupyterlab/apputils";
import { showErrorMessage } from '@jupyterlab/apputils';

import { PartialJSONObject } from "@lumino/coreutils";
import { PartialJSONObject } from '@lumino/coreutils';
import { SplitPanel } from '@lumino/widgets';
import { Signal } from '@lumino/signaling';

Expand Down Expand Up @@ -148,30 +148,37 @@ export class BlocklyPanel extends SplitPanel {
// Check if format is set or if we have legacy content
if (fileFormat === undefined && fileContent['blocks']) {
// Load legacy content
(this.layout as BlocklyLayout).workspace = fileContent as any as Blockly.Workspace;
(this.layout as BlocklyLayout).workspace =
fileContent as any as Blockly.Workspace;
} else if (fileFormat === 2) {
// Load the content from the "workspace" key
(this.layout as BlocklyLayout).workspace = fileContent['workspace'] as any as Blockly.Workspace;
const workspace = fileContent['workspace'] as any as Blockly.Workspace;
(this.layout as BlocklyLayout).workspace = workspace;
const metadata = fileContent['metadata'];
if (metadata) {
if (metadata['toolbox']) {
const toolbox = metadata['toolbox'];
if (this._manager.listToolboxes().find(value => value.value === toolbox)) {
if (
this._manager.listToolboxes().find(value => value.value === toolbox)
) {
this._manager.setToolbox(metadata['toolbox']);
} else {
// Unknown toolbox
showErrorMessage(`Unknown toolbox`,
`The toolbox '` + toolbox + `' is not available. Using default toolbox.`
showErrorMessage(
'Unknown toolbox',
`The toolbox '${toolbox}' is not available. Using default toolbox.`
);
}
}
if (metadata['kernel'] && metadata['kernel'] !== 'No kernel') {
const kernel = metadata['kernel'];
if (this._manager.listKernels().find(value => value.value === kernel)) {
if (
this._manager.listKernels().find(value => value.value === kernel)
) {
this._manager.selectKernel(metadata['kernel']);
} else {
// Unknown kernel
console.warn(`Unknown kernel in blockly file: ` + kernel);
console.warn(`Unknown kernel in blockly file: ${kernel}`);
}
}
if (metadata['allowed_blocks']) {
Expand All @@ -180,8 +187,9 @@ export class BlocklyPanel extends SplitPanel {
}
} else {
// Unsupported format
showErrorMessage(`Unsupported file format`,
`The file format '` + fileFormat + `' is not supported by the Blockly editor.`
showErrorMessage(
'Unsupported file format',
`The file format '${fileFormat}' is not supported by the Blockly editor.`
);
}
}
Expand Down

0 comments on commit 3e79165

Please sign in to comment.