diff --git a/jupysql_plugin/_widgets.py b/jupysql_plugin/_widgets.py deleted file mode 100644 index 6e99b7e9..00000000 --- a/jupysql_plugin/_widgets.py +++ /dev/null @@ -1,67 +0,0 @@ -from jupysql_plugin import __version__, _module_name - -from ipywidgets import DOMWidget -from traitlets import Unicode - - -class FormWidget(DOMWidget): - """ - A sample widget that displays a form and process it. This widget is an example, - not intended for end-users - """ - - _model_name = Unicode("FormModel").tag(sync=True) - _model_module = Unicode(_module_name).tag(sync=True) - _model_module_version = Unicode(__version__).tag(sync=True) - _view_name = Unicode("FormView").tag(sync=True) - _view_module = Unicode(_module_name).tag(sync=True) - _view_module_version = Unicode(__version__).tag(sync=True) - - value = Unicode("Hello World").tag(sync=True) - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.on_msg(self._handle_message) - - def _handle_message(self, widget, content, buffers): - if "method" in content: - method = content["method"] - if method == "submit_form": - form_data = content["data"] - self._process_form_data(form_data) - - def _process_form_data(self, form_data): - # Process the form data received from the frontend - protocol = form_data.get("protocol") - port_raw = form_data.get("port") - - if port_raw == "": - self.send_confirmation_message("Please select a port") - - port = int(port_raw) - - if port < 0: - self.send_confirmation_message("Select a valid port value") - else: - self.send_confirmation_message( - f"You selected protocol: {protocol} and port: {port}" - ) - - def send_confirmation_message(self, message): - self.send({"method": "display_confirmation_message", "message": message}) - - -class TableWidget(DOMWidget): - """Example widget showing how to display a tooltip""" - - _model_name = Unicode("TableModel").tag(sync=True) - _model_module = Unicode(_module_name).tag(sync=True) - _model_module_version = Unicode(__version__).tag(sync=True) - _view_name = Unicode("TableView").tag(sync=True) - _view_module = Unicode(_module_name).tag(sync=True) - _view_module_version = Unicode(__version__).tag(sync=True) - - def __init__(self, data=None, **kwargs): - if data is not None: - self.data = data - super().__init__(**kwargs) diff --git a/package.json b/package.json index 74b0f2be..bfbfe066 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,6 @@ "@mui/material": "^5.13.4", "@types/codemirror": "^5.60.7", "@types/underscore": "^1.11.4", - "bootstrap": "^5.2.3", "clean": "^4.0.2", "react": "^17.0.2", "sql-formatter": "^12.2.0", @@ -98,7 +97,6 @@ "@jupyterlab/testutils": "^4.0.5", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^12.1.2", - "@types/bootstrap": "^5.2.6", "@types/jest": "^29.0.0", "@types/jest-when": "^3.5.2", "@typescript-eslint/eslint-plugin": "^4.8.1", diff --git a/src/index-widgets.ts b/src/index-widgets.ts deleted file mode 100644 index 9f66793b..00000000 --- a/src/index-widgets.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as widget from './widgets/form'; -import * as widget_table from './widgets/table'; -import * as connector_widget from './widgets/connector'; - -export const widgetExports = { - ...widget, - ...widget_table, - ...connector_widget -}; diff --git a/src/widgets/form.ts b/src/widgets/form.ts deleted file mode 100644 index a572ed88..00000000 --- a/src/widgets/form.ts +++ /dev/null @@ -1,109 +0,0 @@ -// Form widget. Python backend is implemented in FormWidget -import { - DOMWidgetModel, - DOMWidgetView, - ISerializers, -} from '@jupyter-widgets/base'; - -import { MODULE_NAME, MODULE_VERSION } from '../version'; - -// Import the CSS -import '../../style/widget.css'; - -export class FormModel extends DOMWidgetModel { - defaults() { - return { - ...super.defaults(), - _model_name: FormModel.model_name, - _model_module: FormModel.model_module, - _model_module_version: FormModel.model_module_version, - _view_name: FormModel.view_name, - _view_module: FormModel.view_module, - _view_module_version: FormModel.view_module_version, - value: 'Hello World', - }; - } - - static serializers: ISerializers = { - ...DOMWidgetModel.serializers, - // Add any extra serializers here - }; - - static model_name = 'FormModel'; - static model_module = MODULE_NAME; - static model_module_version = MODULE_VERSION; - static view_name = 'FormView'; // Set to null if no view - static view_module = MODULE_NAME; // Set to null if no view - static view_module_version = MODULE_VERSION; -} - -export class FormView extends DOMWidgetView { - render() { - this.el.classList.add('custom-widget'); - - const template = ` -
- -` - - this.el.innerHTML = template; - - // Add event listener for form submission - const form = this.el.querySelector('#myForm'); - form.addEventListener('submit', this.handleFormSubmit.bind(this)); - - // Listen for messages from the Python backend - this.model.on('msg:custom', this.handleMessage.bind(this)); - - } - handleFormSubmit(event: Event) { - event.preventDefault(); - - // Extract form data - const form = event.target as HTMLFormElement; - const formData = new FormData(form); - - // Convert form data to a plain object - const formValues: { [key: string]: string } = {}; - for (const [key, value] of formData.entries()) { - formValues[key] = value.toString(); - } - - // Call the function to send form data to the Python backend - this.sendFormData(formValues); - } - sendFormData(formData: { [key: string]: string }) { - // Create a message to send to the Python backend - const message = { - method: 'submit_form', - data: formData - }; - - // Send the message to the Python backend - this.send(message); - } - - handleMessage(content: any) { - if (content.method === 'display_confirmation_message') { - const confirmationMessage = this.el.querySelector('#confirmationMessage'); - if (confirmationMessage) { - confirmationMessage.textContent = content.message; - } - } - } - -} - diff --git a/src/widgets/index.ts b/src/widgets/index.ts index b790ad3e..b2d3fbf8 100644 --- a/src/widgets/index.ts +++ b/src/widgets/index.ts @@ -2,7 +2,7 @@ import { Application, IPlugin } from '@lumino/application'; import { Widget } from '@lumino/widgets'; import { IJupyterWidgetRegistry } from '@jupyter-widgets/base'; -import { widgetExports } from '../index-widgets'; +import * as connectorWidget from './connector'; import { MODULE_NAME, MODULE_VERSION } from '../version'; @@ -29,7 +29,7 @@ function activateWidgetExtension( registry.registerWidget({ name: MODULE_NAME, version: MODULE_VERSION, - exports: widgetExports, + exports: connectorWidget, }); } diff --git a/src/widgets/table.ts b/src/widgets/table.ts deleted file mode 100644 index 25929e1c..00000000 --- a/src/widgets/table.ts +++ /dev/null @@ -1,86 +0,0 @@ -// Table widget. Python backend is implemented in TableWidget -import { MODULE_NAME, MODULE_VERSION } from '../version'; - -import 'bootstrap/dist/css/bootstrap.min.css'; - -import { - DOMWidgetModel, - DOMWidgetView, - ISerializers, -} from '@jupyter-widgets/base'; -import { Tooltip } from 'bootstrap'; - -export class TableModel extends DOMWidgetModel { - defaults() { - return { - ...super.defaults(), - _model_name: TableModel.model_name, - _model_module: TableModel.model_module, - _model_module_version: TableModel.model_module_version, - _view_name: TableModel.view_name, - _view_module: TableModel.view_module, - _view_module_version: TableModel.view_module_version, - value: 'Hello World', - }; - } - - static serializers: ISerializers = { - ...DOMWidgetModel.serializers, - // Add any extra serializers here - }; - - static model_name = 'TableModel'; - static model_module = MODULE_NAME; - static model_module_version = MODULE_VERSION; - static view_name = 'TableView'; // Set to null if no view - static view_module = MODULE_NAME; // Set to null if no view - static view_module_version = MODULE_VERSION; -} - -interface StockData { - symbol: string; - price: number; - change: number; -} - -export class TableView extends DOMWidgetView { - render() { - const stockData: StockData[] = [ - { symbol: 'AAPL', price: 142.34, change: 1.25 }, - { symbol: 'GOOGL', price: 2725.45, change: -4.56 }, - { symbol: 'MSFT', price: 259.43, change: 2.78 }, - { symbol: 'AMZN', price: 3310.98, change: -7.92 }, - ]; - - this.el.innerHTML = ` -Symbol | -Price | -Change | -
---|---|---|
${stock.symbol} | -${stock.price} | -${stock.change} | -