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 = ` - - - - - - - - - - ${stockData.map((stock) => ` - - - - - - `).join('')} - -
SymbolPriceChange
${stock.symbol}${stock.price}${stock.change}
- `; - - const tooltipTriggerList = Array.from(this.el.querySelectorAll('[data-bs-toggle="tooltip"]')) as HTMLElement[]; - tooltipTriggerList.forEach((tooltipTriggerEl) => { - const column = tooltipTriggerEl.getAttribute('title') as keyof StockData; - const tooltipContent = stockData.map((stock) => stock[column]).join(', '); - - new Tooltip(tooltipTriggerEl, { - title: tooltipContent, - }); - }); - } -} diff --git a/style/widget.css b/style/widget.css deleted file mode 100644 index 33fd7c93..00000000 --- a/style/widget.css +++ /dev/null @@ -1,4 +0,0 @@ -.custom-widget { - background-color: lightseagreen; - padding: 0px 2px; -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e4922d46..cfcb0bed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -28,8 +28,6 @@ "src/utils/*", "src/const/*", "src/completer/keywords.json", - "src/widgets/table.ts", - "src/widgets/form.ts", "src/widgets/connector.ts", "src/widgets/index.ts", "src/formatter/formatter.ts", diff --git a/ui-tests/notebooks/widgets.ipynb b/ui-tests/notebooks/widgets.ipynb deleted file mode 100644 index e700a7a7..00000000 --- a/ui-tests/notebooks/widgets.ipynb +++ /dev/null @@ -1,89 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "08aa1a85-674c-4865-8e06-7d056fb628bf", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "ce215c2c946d4cd3a4e7569afff90be8", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "FormWidget()" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# we're getting a NotOpenSSLWarning warning on github actions\n", - "import warnings\n", - "\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "\n", - "from jupysql_plugin._widgets import FormWidget, TableWidget\n", - "\n", - "FormWidget()" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "0890e3d8-44d0-4a3e-9dff-b1d430ad0832", - "metadata": { - "tags": [] - }, - "outputs": [ - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "d691e28130ab415eae45a532779c5df0", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - "TableWidget()" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "TableWidget()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.4" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/ui-tests/tests/jupysql_plugin.test.ts-snapshots/light-widgets-ipynb-cell-0-darwin.png b/ui-tests/tests/jupysql_plugin.test.ts-snapshots/light-widgets-ipynb-cell-0-darwin.png deleted file mode 100644 index a5c86112..00000000 Binary files a/ui-tests/tests/jupysql_plugin.test.ts-snapshots/light-widgets-ipynb-cell-0-darwin.png and /dev/null differ diff --git a/ui-tests/tests/jupysql_plugin.test.ts-snapshots/light-widgets-ipynb-cell-1-darwin.png b/ui-tests/tests/jupysql_plugin.test.ts-snapshots/light-widgets-ipynb-cell-1-darwin.png deleted file mode 100644 index 4f1f7f38..00000000 Binary files a/ui-tests/tests/jupysql_plugin.test.ts-snapshots/light-widgets-ipynb-cell-1-darwin.png and /dev/null differ diff --git a/yarn.lock b/yarn.lock index 9978b57d..09227884 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4618,7 +4618,7 @@ __metadata: languageName: node linkType: hard -"@popperjs/core@npm:^2.11.8, @popperjs/core@npm:^2.9.2": +"@popperjs/core@npm:^2.11.8": version: 2.11.8 resolution: "@popperjs/core@npm:2.11.8" checksum: e5c69fdebf52a4012f6a1f14817ca8e9599cb1be73dd1387e1785e2ed5e5f0862ff817f420a87c7fc532add1f88a12e25aeb010ffcbdc98eace3d55ce2139cf0 @@ -5197,15 +5197,6 @@ __metadata: languageName: node linkType: hard -"@types/bootstrap@npm:^5.2.6": - version: 5.2.7 - resolution: "@types/bootstrap@npm:5.2.7" - dependencies: - "@popperjs/core": ^2.9.2 - checksum: f808b40e7c5760d9822b3d3d6e6a0adf840616791ec0f4b8a5da0a0d04d60cee20b8004e9c95acc84ddd21de28a1a0dd1d08786094221c99c8f02617a286c2db - languageName: node - linkType: hard - "@types/codemirror@npm:^5.60.7": version: 5.60.10 resolution: "@types/codemirror@npm:5.60.10" @@ -6355,15 +6346,6 @@ __metadata: languageName: node linkType: hard -"bootstrap@npm:^5.2.3": - version: 5.3.2 - resolution: "bootstrap@npm:5.3.2" - peerDependencies: - "@popperjs/core": ^2.11.8 - checksum: d5580b253d121ffc137388d41da58dce8d15f1ccd574e12f28d4a08e7649ca15e95db645b2b677cb8025bccd446bff04138fc0fe64f8cba0ccc5dc004a8644cf - languageName: node - linkType: hard - "brace-expansion@npm:^1.1.7": version: 1.1.11 resolution: "brace-expansion@npm:1.1.11" @@ -9803,14 +9785,12 @@ __metadata: "@mui/material": ^5.13.4 "@testing-library/jest-dom": ^5.16.5 "@testing-library/react": ^12.1.2 - "@types/bootstrap": ^5.2.6 "@types/codemirror": ^5.60.7 "@types/jest": ^29.0.0 "@types/jest-when": ^3.5.2 "@types/underscore": ^1.11.4 "@typescript-eslint/eslint-plugin": ^4.8.1 "@typescript-eslint/parser": ^4.8.1 - bootstrap: ^5.2.3 clean: ^4.0.2 eslint: ^7.14.0 eslint-config-prettier: ^6.15.0