Skip to content
Open
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
4 changes: 3 additions & 1 deletion nicegui_tabulator/core/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
)


def import_luxon(shared: bool = True, script_url: str = LUXON_DEFAULT_SCRIPT_URL):
def import_luxon(
shared: bool = True, script_url: str = LUXON_DEFAULT_SCRIPT_URL
) -> None:
"""Inject Luxon into the page so Tabulator date/time features can work.

Tabulator's date/time formatters and sorters require Luxon to be available in the
Expand Down
2 changes: 0 additions & 2 deletions nicegui_tabulator/core/events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from dataclasses import dataclass
from typing import (
Any,
Expand Down
184 changes: 92 additions & 92 deletions nicegui_tabulator/core/tabulator.py

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions nicegui_tabulator/core/themes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import annotations
from pathlib import Path
from typing import Literal, Optional
from nicegui import ui, app, Client
Expand Down Expand Up @@ -33,7 +32,7 @@ def use_theme(theme_name: _T_THEME_NAME, shared: Optional[bool] = None) -> None:

Args:
theme_name (_T_THEME_NAME): name of the theme to use.
shared (Optional[bool], optional): Whether to use the theme for all clients or only the current client.
shared (bool | None, optional): Whether to use the theme for all clients or only the current client.
`None`(default): use the theme for all clients if there is no client context (e.g. at startup), otherwise use it only for the current client.
`True`: use the theme for all clients.
`False`: use the theme only for the current client.
Expand Down
11 changes: 5 additions & 6 deletions nicegui_tabulator/core/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations
from dataclasses import dataclass, field as dc_field
from typing import Any, Dict, Literal
from typing import Any, Literal

from typing import TYPE_CHECKING

Expand All @@ -14,22 +13,22 @@ class CellSlotProps:
"""The name of the field in the row data."""
value: Any
"""The value of the field in the row data."""
row: Dict
row: dict
"""The row data."""
row_number: int
"""The position(starting from 1) of the row in the table data."""
row_index: int
"""The index of the row in the table data."""
table: Tabulator = dc_field(init=True, repr=False)
table: "Tabulator" = dc_field(init=True, repr=False)
"""The parent Tabulator instance."""

def update_value(self, value):
def update_value(self, value: Any) -> None:
"""Updates the value of the field in the row data only on the server side."""
index_field = self.table.index_field
data = [{index_field: self.row[index_field], self.field: value}]
self.table._update_data_on_server(data)

def update_to_client(self):
def update_to_client(self) -> None:
"""Updates the value of the field in the row data on the client side."""

index_field = self.table.index_field
Expand Down
13 changes: 7 additions & 6 deletions nicegui_tabulator/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from typing import Union, Callable
from nicegui import ui, Client as ng_client
from nicegui.awaitable_response import AwaitableResponse
from typing import Callable, List, Union
import asyncio
import uuid

from nicegui import ui, Client as ng_client
from nicegui.awaitable_response import AwaitableResponse

_TTask = Union[Callable[..., None], Callable[..., AwaitableResponse]]


class DeferredTask:
def __init__(self):
self._tasks: list[_TTask] = []
self._tasks: List[_TTask] = []
self.component_connected = False

async def on_client_connect(
Expand All @@ -33,11 +34,11 @@ def flush(self):

self._tasks.clear()

def _execute_task(self, task):
def _execute_task(self, task: _TTask) -> None:
result = task()
if asyncio.iscoroutine(result):
asyncio.create_task(result)


def generate_dataframe_unique_id_column_name():
def generate_dataframe_unique_id_column_name() -> str:
return f"__{uuid.uuid4().hex}"
29 changes: 0 additions & 29 deletions tests/test_tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,35 +586,6 @@ def _():
server_data_checker.expect_server_data(page)


def test_replace_data(browser: BrowserManager, page_path: str):
server_data_checker = ServerDataChecker()

@ui.page(page_path)
def _():
table = tabulator(create_table_options()).classes("target")

label_server_data = server_data_checker.create_elements(table)

ui.button(
"replace data",
on_click=lambda: (
table.replace_data(
[{"id": 1, "name": "bar-replace-data", "age": "12"}]
),
label_server_data.set_text(str(table.data)),
),
)

page = browser.open(page_path)
table_locator = page.locator(".target")

# set data
page.get_by_role("button").filter(has_text="replace data").click()
check_table_rows(table_locator, [["bar-replace-data", "12"]])

server_data_checker.expect_server_data(page)


def test_update_data(browser: BrowserManager, page_path: str):
server_data_checker = ServerDataChecker()

Expand Down
Loading