Skip to content

Commit

Permalink
Merge branch 'develop' into bug/#1911-current-page-menu
Browse files Browse the repository at this point in the history
  • Loading branch information
namnguyen20999 authored Oct 30, 2024
2 parents 82b911c + 867b0e1 commit c2b6175
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 116 deletions.
14 changes: 12 additions & 2 deletions frontend/taipy-gui/src/components/Taipy/Metric.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,18 @@ describe("Metric Component", () => {
});
});

it("processes type prop correctly when type is none", async () => {
const { container } = render(<Metric type="none" />);
it("processes type prop correctly when type is none (string)", async () => {
const { container } = render(<Metric type="none" />);
await waitFor(() => {
const angularElm = container.querySelector(".angular");
const angularAxis = container.querySelector(".angularaxis");
expect(angularElm).not.toBeInTheDocument();
expect(angularAxis).not.toBeInTheDocument();
});
});

it("processes type prop correctly when type is None", async () => {
const { container } = render(<Metric type="None" />);
await waitFor(() => {
const angularElm = container.querySelector(".angular");
const angularAxis = container.querySelector(".angularaxis");
Expand Down
2 changes: 1 addition & 1 deletion frontend/taipy-gui/src/components/Taipy/Metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const Metric = (props: MetricProps) => {
}, [props.colorMap, props.max]);

const data = useMemo(() => {
const mode = props.type === "none" ? [] : ["gauge"];
const mode = typeof props.type === "string" && props.type.toLowerCase() === "none" ? [] : ["gauge"];
showValue && mode.push("number");
delta !== undefined && mode.push("delta");
const deltaIncreasing = props.deltaColor
Expand Down
7 changes: 5 additions & 2 deletions taipy/gui/_renderers/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _Builder:

__BLOCK_CONTROLS = ["dialog", "expandable", "pane", "part"]

__TABLE_COLUMNS_DEPS = [
__TABLE_COLUMNS_DEPS = {
"data",
"columns",
"date_format",
Expand All @@ -75,7 +75,10 @@ class _Builder:
"style",
"tooltip",
"lov",
]
"row_class_name",
"cell_class_name",
"format_fn"
}

def __init__(
self,
Expand Down
10 changes: 7 additions & 3 deletions taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
from .page import Page
from .partial import Partial
from .server import _Server
from .state import State
from .state import State, _GuiState
from .types import _WsType
from .utils import (
_delscopeattr,
Expand Down Expand Up @@ -2292,7 +2292,9 @@ def _hold_actions(
if isinstance(callback, str)
else _get_lambda_id(t.cast(LambdaType, callback))
if _is_unnamed_function(callback)
else callback.__name__ if callback is not None else None
else callback.__name__
if callback is not None
else None
)
func = self.__get_on_cancel_block_ui(action_name)
def_action_name = func.__name__
Expand Down Expand Up @@ -2809,7 +2811,9 @@ def run(
self.__var_dir.set_default(self.__frame)

if self.__state is None or is_reloading:
self.__state = State(self, self.__locals_context.get_all_keys(), self.__locals_context.get_all_context())
self.__state = _GuiState(
self, self.__locals_context.get_all_keys(), self.__locals_context.get_all_context()
)

if _is_in_notebook():
# Allow gui.state.x in notebook mode
Expand Down
10 changes: 10 additions & 0 deletions taipy/gui/mock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
62 changes: 62 additions & 0 deletions taipy/gui/mock/mock_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2021-2024 Avaiga Private Limited
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
import typing as t

from .. import Gui, State
from ..utils import _MapDict


class MockState(State):
"""A Mock implementation for `State`.
TODO
example of use:
```py
def test_callback():
ms = MockState(Gui(""), a = 1)
on_action(ms) # function to test
assert ms.a == 2
```
"""

__VARS = "vars"

def __init__(self, gui: Gui, **kwargs) -> None:
super().__setattr__(MockState.__VARS, {k: _MapDict(v) if isinstance(v, dict) else v for k, v in kwargs.items()})
self._gui = gui
super().__init__()

def get_gui(self) -> Gui:
return self._gui

def __getattribute__(self, name: str) -> t.Any:
if (attr := t.cast(dict, super().__getattribute__(MockState.__VARS)).get(name, None)) is not None:
return attr
try:
return super().__getattribute__(name)
except Exception:
return None

def __setattr__(self, name: str, value: t.Any) -> None:
t.cast(dict, super().__getattribute__(MockState.__VARS))[name] = (
_MapDict(value) if isinstance(value, dict) else value
)

def __getitem__(self, key: str):
return self

def __enter__(self):
return self

def __exit__(self, exc_type, exc_value, traceback):
return True

def broadcast(self, name: str, value: t.Any):
pass
Loading

0 comments on commit c2b6175

Please sign in to comment.