Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed May 22, 2024
1 parent ef9b149 commit 7bd49d9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ repos:
rev: v8.56.0
hooks:
- id: eslint
args: ['-c', 'panel/.eslintrc.js', 'panel/*.ts', 'panel/models/**/*.ts']
args: ['-c', 'panel/.eslintrc.js', 'panel/*.ts', 'panel/models/**/*.ts', '--fix']
additional_dependencies:
- 'eslint@8.57.0'
- '@stylistic/eslint-plugin@1.6.3'
Expand Down
109 changes: 53 additions & 56 deletions panel/models/jstree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as p from "@bokehjs/core/properties"
import type * as p from "@bokehjs/core/properties"
import type {StyleSheetLike} from "@bokehjs/core/dom"
import { div } from "@bokehjs/core/dom"
import {div} from "@bokehjs/core/dom"
import {ModelEvent} from "@bokehjs/core/bokeh_events"
import type {Attrs} from "@bokehjs/core/types"
import {LayoutDOM, LayoutDOMView} from "@bokehjs/models/layouts/layout_dom"
Expand All @@ -9,8 +9,8 @@ import {ID} from "./util"
import jstree_css from "styles/models/jstree.css"

type Node = {
[key: string]: any;
};
[key: string]: any
}

declare function jQuery(...args: any[]): any

Expand All @@ -37,10 +37,10 @@ export class jsTreeView extends LayoutDOMView {
override connect_signals(): void {
super.connect_signals()
const {nodes, value, checkbox, show_icons, show_dots, multiple} = this.model.properties
this.on_change(nodes, () => this._jstree.jstree(true).load_node('#', () => {
this.on_change(nodes, () => this._jstree.jstree(true).load_node("#", () => {
this._jstree.jstree(true).refresh({
"skip_loading": false,
"forget_state": true,
skip_loading: false,
forget_state: true,
})
this._update_selection_from_value()
}))
Expand Down Expand Up @@ -77,62 +77,62 @@ export class jsTreeView extends LayoutDOMView {
override render(): void {
super.render()
this._id = ID()
this._container = div({id: this._id, style: "overflow: auto; minHeight: 200px; minWidth: 200px;"},)
this.shadow_el.appendChild(this._container);
this._container = div({id: this._id, style: "overflow: auto; minHeight: 200px; minWidth: 200px;"})
this.shadow_el.appendChild(this._container)
this._jstree = jQuery(this._container).jstree({
"checkbox": {
"three_state": this.model.cascade,
"cascade": this.model.cascade ? "undetermined" : "down+undetermined",
checkbox: {
three_state: this.model.cascade,
cascade: this.model.cascade ? "undetermined" : "down+undetermined",
},
"core": {
"data": (obj: Node, callback: (nodes: Node[]) => void) => {
if (obj.id == '#') {
core: {
data: (obj: Node, callback: (nodes: Node[]) => void) => {
if (obj.id == "#") {
callback(this.model.nodes)
} else {
this.model.trigger_event(new NodeEvent({type: 'open', node: obj}))
this.model.trigger_event(new NodeEvent({type: "open", node: obj}))
new Promise((resolve) => {
const loop = () => {
const nodes = this.model._new_nodes
if (nodes != null) {
const nodes = this.model._new_nodes
if (nodes != null) {
obj.new_nodes = nodes
callback(obj.children_nodes)
this.model._new_nodes = null
resolve(this.model.nodes)
} else {
} else {
setTimeout(loop, 10)
}
}
}
loop();
}).catch(() => console.warn('Failed to fetch nodes'))
loop()
}).catch(() => console.warn("Failed to fetch nodes"))
}
},
"check_callback": true,
"multiple": this.model.multiple,
"themes": {
"dots": this.model.show_dots,
"icons": this.model.show_icons,
"stripes": this.model.show_stripes,
}
},
check_callback: true,
multiple: this.model.multiple,
themes: {
dots: this.model.show_dots,
icons: this.model.show_icons,
stripes: this.model.show_stripes,
},
},
"plugins": this.plugins,
"sort": (n1: string, n2: string) => {
const n1_folder = n1.endsWith('/')
const n2_folder = n2.endsWith('/')
if (n1_folder && !n2_folder) {
plugins: this.plugins,
sort: (n1: string, n2: string) => {
const n1_folder = n1.endsWith("/")
const n2_folder = n2.endsWith("/")
if (n1_folder && !n2_folder) {
return -1
} else if (!n1_folder && n2_folder) {
} else if (!n1_folder && n2_folder) {
return 1
}
return n1 > n2 ? 1 : -1
}
return n1 > n2 ? 1 : -1
},
});
})
this.init_callbacks()
}

init_callbacks(): void {
this._jstree.on('activate_node.jstree', ({}, data: any) => this.selectNodeFromEditor({}, data));
this._jstree.on('refresh.jstree', ({}, {}) => this._update_selection_from_value());
this._jstree.on('before_open.jstree', (_: any, data: any) => this._listen_for_node_open(data));
this._jstree.on("activate_node.jstree", ({}, data: any) => this.selectNodeFromEditor({}, data))
this._jstree.on("refresh.jstree", ({}, {}) => this._update_selection_from_value())
this._jstree.on("before_open.jstree", (_: any, data: any) => this._listen_for_node_open(data))
}

selectNodeFromEditor({}, data: any): void {
Expand All @@ -146,28 +146,25 @@ export class jsTreeView extends LayoutDOMView {

_setShowIcons(): void {
if (this.model.show_icons) {
this._jstree.jstree(true).show_icons();
}
else {
this._jstree.jstree(true).hide_icons();
this._jstree.jstree(true).show_icons()
} else {
this._jstree.jstree(true).hide_icons()
}
}

_setShowDots(): void {
// console.log("setShowDots")
if (this.model.show_dots) {
this._jstree.jstree(true).show_dots()
}
else {
} else {
this._jstree.jstree(true).hide_dots()
}
}

setCheckboxes(): void {
if (this.model.checkbox) {
this._jstree.jstree(true).show_checkboxes()
}
else {
} else {
this._jstree.jstree(true).hide_checkboxes()
}
}
Expand All @@ -181,17 +178,17 @@ export class jsTreeView extends LayoutDOMView {
let request_load = false
for (const child of data.node.children) {
const child_node = data.instance.get_node(child)
if (child_node.original.type === 'folder' && !child_node.children.length) {
request_load = true
if (child_node.original.type === "folder" && !child_node.children.length) {
request_load = true
}
data.node.children_nodes.push(child_node)
}
if (request_load) {
data.instance.load_node(data.node.id, (node: Node) => {
for (const new_node of node.new_nodes) {
this._jstree.jstree(true).create_node(new_node["parent"], new_node)
}
delete node.new_nodes
for (const new_node of node.new_nodes) {
this._jstree.jstree(true).create_node(new_node.parent, new_node)
}
delete node.new_nodes
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion panel/models/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ export function ID() {
// Math.random should be unique because of its seeding algorithm.
// Convert it to base 36 (numbers + letters), and grab the first 9 characters
// after the decimal.
return '_' + Math.random().toString(36).substring(2, 11);
return `_${ Math.random().toString(36).substring(2, 11)}`
}
2 changes: 1 addition & 1 deletion panel/models/vtk/vtkvolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class VTKVolumePlotView extends AbstractVTKView {
this._create_orientation_widget()
this._set_axes()
this._vtk_renwin.getRenderer().resetCamera()
if (Object.keys(this.model.camera).length) {
if (Object.keys(this.model.camera).length > 0) {
this._set_camera_state()
}
this._get_camera_state()
Expand Down

0 comments on commit 7bd49d9

Please sign in to comment.