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

Use format SQL settings when creating new notebook #115

Merged
merged 3 commits into from
Jun 14, 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
7 changes: 6 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ jobs:

- name: Lint
run: |
python3 -m venv env
source env/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pkgmt nox
pkgmt lint
pkgmt lint --exclude env

- name: Setup node
uses: actions/setup-node@v3
Expand All @@ -48,6 +50,7 @@ jobs:

- name: Test
run: |
source env/bin/activate
nox --session test --verbose

ui-test:
Expand Down Expand Up @@ -81,6 +84,8 @@ jobs:

- name: Install and test
run: |
python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade nox
SHARD=${{ matrix.shard }}
Expand Down
18 changes: 18 additions & 0 deletions jupysql_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,21 @@

def _jupyter_labextension_paths():
return [{"src": "labextension", "dest": "jupysql-plugin"}]


def _jupyter_server_extension_points():
return [{"module": "jupysql_plugin"}]


def _load_jupyter_server_extension(serverapp):
"""
This function is called when the extension is loaded.
Parameters
----------
server_app: jupyterlab.labapp.LabApp
JupyterLab application instance
"""
serverapp.log.info(f"Registered {_module_name} server extension")


load_jupyter_server_extension = _load_jupyter_server_extension
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jupyterlab>=4,<4.0.12
jupyterlab>=4
build
twine
hatch
Expand Down
10 changes: 9 additions & 1 deletion src/formatter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class FormattingExtension
private notebookCodeFormatter: JupyterlabNotebookCodeFormatter;
private formatSQLButton: ToolbarButton;
private panel: NotebookPanel;
private extensionSettings: boolean;


constructor(
tracker: INotebookTracker
Expand All @@ -39,6 +41,7 @@ export class FormattingExtension
}

private _onSettingsChanged = (sender: any, settings: JupySQLSettings) => {
this.extensionSettings = settings.showFormatSQL;
if (!settings.showFormatSQL) {
this.formatSQLButton.parent = null;
} else {
Expand All @@ -65,6 +68,11 @@ export class FormattingExtension
this.formatSQLButton.node.setAttribute("data-testid", "format-btn");

panel.toolbar.insertItem(10, 'formatSQL', this.formatSQLButton);
if (!this.extensionSettings) {
this.formatSQLButton.parent = null;
} else {
this.panel.toolbar.insertItem(10, 'formatSQL', this.formatSQLButton);
}

return new DisposableDelegate(() => {
this.formatSQLButton.dispose();
Expand Down Expand Up @@ -97,4 +105,4 @@ const plugin_formatting: JupyterFrontEndPlugin<void> = {
};


export { plugin_formatting }
export { plugin_formatting }
2 changes: 1 addition & 1 deletion ui-tests/tests/format_sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('test format SQL', async ({ page }) => {
await page.notebook.openByPath("sample.ipynb");
await page.notebook.activate("sample.ipynb");
await page.notebook.addCell("code", "%%sql\nselect * from table")
await page.getByTestId('format-btn').locator('button').click();
await page.getByTestId('format-btn').locator('button').click({ force: true });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I faced this issue in the CI on the main branch as well as the current branch:

waiting 500ms
      -   waiting for element to be visible, enabled and stable
      -   element is visible, enabled and stable
      -   scrolling into view if needed
      -   done scrolling
      -   <span class="jp-ToolbarButtonComponent-label">Format SQL</span> intercepts pointer events
      - retrying click action, attempt #93 

Fixed using this solution

await page.waitForTimeout(2000);

await expect(page.locator('body')).toContainText('SELECT');
Expand Down
Loading
Loading