Skip to content

Commit

Permalink
Merge branch '1396-discussion-adding-color_range_step-property-to-met…
Browse files Browse the repository at this point in the history
…ric-component' of github.com:Avaiga/taipy into 1396-discussion-adding-color_range_step-property-to-metric-component
  • Loading branch information
namnguyen20999 committed Jun 17, 2024
2 parents 5f6de86 + bc62632 commit 8ae2f22
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 90 deletions.
117 changes: 63 additions & 54 deletions frontend/taipy/src/CoreSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import {
BadgePos,
BadgeSx,
BaseTreeViewSx,
EmptyArray,
FlagSx,
ParentItemSx,
getUpdateVarNames,
Expand Down Expand Up @@ -126,7 +125,7 @@ const tinyPinIconButtonSx = (theme: Theme) => ({

const switchBoxSx = { ml: 2, width: (theme: Theme) => `calc(100% - ${theme.spacing(2)})` };
const iconInRowSx = { fontSize: "body2.fontSize" };
const labelInRowSx = {"& .MuiFormControlLabel-label": iconInRowSx};
const labelInRowSx = { "& .MuiFormControlLabel-label": iconInRowSx };

const CoreItem = (props: {
item: Entity;
Expand All @@ -139,25 +138,27 @@ const CoreItem = (props: {
hideNonPinned: boolean;
active: boolean;
}) => {
const [id, label, items = EmptyArray, nodeType, primary] = props.item;
const [id, label, items, nodeType, primary] = props.item;
const isPinned = props.pins[0][id];
const isShown = props.hideNonPinned ? props.pins[1][id] : true;

return !props.displayCycles && nodeType === NodeType.CYCLE ? (
<>
{items.map((item) => (
<CoreItem
key={item[0]}
item={item}
displayCycles={false}
showPrimaryFlag={props.showPrimaryFlag}
leafType={props.leafType}
pins={props.pins}
onPin={props.onPin}
hideNonPinned={props.hideNonPinned}
active={props.active}
/>
))}
{items
? items.map((item) => (
<CoreItem
key={item[0]}
item={item}
displayCycles={false}
showPrimaryFlag={props.showPrimaryFlag}
leafType={props.leafType}
pins={props.pins}
onPin={props.onPin}
hideNonPinned={props.hideNonPinned}
active={props.active}
/>
))
: null}
</>
) : isShown ? (
<TreeItem
Expand Down Expand Up @@ -213,20 +214,21 @@ const CoreItem = (props: {
}
sx={nodeType === NodeType.NODE ? undefined : ParentItemSx}
>
{items.map((item) => (
<CoreItem
key={item[0]}
item={item}
displayCycles={true}
showPrimaryFlag={props.showPrimaryFlag}
leafType={props.leafType}
editComponent={props.editComponent}
pins={props.pins}
onPin={props.onPin}
hideNonPinned={props.hideNonPinned}
active={props.active}
/>
))}
{items ?
items.map((item) => (
<CoreItem
key={item[0]}
item={item}
displayCycles={true}
showPrimaryFlag={props.showPrimaryFlag}
leafType={props.leafType}
editComponent={props.editComponent}
pins={props.pins}
onPin={props.onPin}
hideNonPinned={props.hideNonPinned}
active={props.active}
/>
)) : null}
</TreeItem>
) : null;
};
Expand Down Expand Up @@ -374,7 +376,8 @@ const CoreSelector = (props: CoreSelectorProps) => {
setSelectedItems(() => {
const lovVar = getUpdateVar(updateVars, lovPropertyName);
const val = multiple ? nodeId : isSelectable ? nodeId : "";
setTimeout( // to avoid set state while render react errors
setTimeout(
// to avoid set state while render react errors
() => dispatch(createSendUpdateAction(updateVarName, val, module, onChange, propagate, lovVar)),
1
);
Expand Down Expand Up @@ -526,15 +529,19 @@ const CoreSelector = (props: CoreSelectorProps) => {
localStoreSet(jsonFilters, id, lovPropertyName, "filter");
const filterVar = getUpdateVar(updateCoreVars, "filter");
const lovVar = getUpdateVarNames(updateVars, lovPropertyName);
setTimeout(() => dispatch(
createRequestUpdateAction(
id,
module,
lovVar,
true,
filterVar ? { [filterVar]: filters } : undefined
)
), 1);
setTimeout(
() =>
dispatch(
createRequestUpdateAction(
id,
module,
lovVar,
true,
filterVar ? { [filterVar]: filters } : undefined
)
),
1
);
return filters;
}
return old;
Expand Down Expand Up @@ -674,20 +681,22 @@ const CoreSelector = (props: CoreSelectorProps) => {
onItemExpansionToggle={onItemExpand}
>
{foundEntities
? foundEntities.map((item) => (
<CoreItem
key={item ? item[0] : ""}
item={item}
displayCycles={displayCycles}
showPrimaryFlag={showPrimaryFlag}
leafType={leafType}
editComponent={props.editComponent}
onPin={showPins ? onPin : undefined}
pins={pins}
hideNonPinned={hideNonPinned}
active={!!active}
/>
))
? foundEntities.map((item) =>
item ? (
<CoreItem
key={item[0]}
item={item}
displayCycles={displayCycles}
showPrimaryFlag={showPrimaryFlag}
leafType={leafType}
editComponent={props.editComponent}
onPin={showPins ? onPin : undefined}
pins={pins}
hideNonPinned={hideNonPinned}
active={!!active}
/>
) : null
)
: null}
</SimpleTreeView>
</>
Expand Down
18 changes: 15 additions & 3 deletions taipy/gui/utils/_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,21 @@ def __get_label(self, value: t.Any, dig=True) -> t.Union[str, t.Dict, None]:

def __get_children(self, value: t.Any) -> t.Optional[t.List[t.Any]]:
if isinstance(value, (tuple, list)) and len(value) > 2:
return value[2] if isinstance(value[2], list) else [value[2]]
return value[2] if isinstance(value[2], list) else None if value[2] is None else [value[2]]
elif hasattr(value, "children"):
return value.children if isinstance(value.children, list) else [value.children]
return (
value.children
if isinstance(value.children, list)
else None
if value.children is None
else [value.children]
)
elif hasattr(value, "__getitem__") and "children" in value:
return value["children"] if isinstance(value["children"], list) else [value["children"]]
return (
value["children"]
if isinstance(value["children"], list)
else None
if value["children"] is None
else [value["children"]]
)
return None
8 changes: 4 additions & 4 deletions taipy/gui_core/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def data_node_adapter(
raise NotImplementedError
if isinstance(data, list):
if data[2] and isinstance(data[2][0], (Cycle, Scenario, Sequence, DataNode)):
data[2] = self.get_sorted_datanode_list(data[2], sorts, adapt_dn)
data[2] = self.get_sorted_datanode_list(data[2], sorts, False)
return data
try:
if hasattr(data, "id") and is_readable(data.id) and core_get(data.id) is not None:
Expand All @@ -715,7 +715,7 @@ def data_node_adapter(
self.data_nodes_by_owner.get(data.id, [])
+ (self.scenario_by_cycle or {}).get(data, []),
sorts,
adapt_dn,
False,
),
_EntityType.CYCLE.value,
False,
Expand All @@ -727,7 +727,7 @@ def data_node_adapter(
self.get_sorted_datanode_list(
self.data_nodes_by_owner.get(data.id, []) + list(data.sequences.values()),
sorts,
adapt_dn,
False,
),
_EntityType.SCENARIO.value,
data.is_primary,
Expand All @@ -737,7 +737,7 @@ def data_node_adapter(
return [
data.id,
data.get_simple_label(),
self.get_sorted_datanode_list(datanodes, sorts, adapt_dn),
self.get_sorted_datanode_list(datanodes, sorts, False),
_EntityType.SEQUENCE.value,
]
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,40 @@
# 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 taipy.gui.builder as tgb


# build partial content for a specific data node
def build_dn_partial(dn, dn_label):
partial_content = "<|part|render={selected_scenario}|\n\n"

# ##################################################################################################################
# PLACEHOLDER: data node specific content before automatic content #
# #
# Example: #
if dn_label == "replacement_type":
partial_content += "All missing values will be replaced by the data node value."
# Comment, remove or replace the previous lines with your own use case #
# ##################################################################################################################

# Automatic data node content
partial_content += (
"<|{selected_scenario.data_nodes['" + dn.config_id + "']}|data_node|scenario={" "selected_scenario}|>\n\n "
)

# ##################################################################################################################
# PLACEHOLDER: data node specific content after automatic content #
# #
# Example: #
if dn_label == "initial_dataset":
partial_content += (
"Select your CSV file: <|{selected_data_node.path}|file_selector|extensions=.csv|on_action"
"={lambda s: s.refresh('selected_scenario')}|>\n\n "
)
# Comment, remove or replace the previous lines with your own use case #
# ##################################################################################################################

partial_content += "|>\n\n"
with tgb.Page() as partial_content:
with tgb.part(render="{selected_scenario}"):
# ##########################################################################################################
# PLACEHOLDER: data node specific content before automatic content #
# #
# Example: #
if dn_label == "replacement_type":
tgb.text("All missing values will be replaced by the data node value.")
# Comment, remove or replace the previous lines with your own use case #
# ##########################################################################################################

# Automatic data node content
tgb.data_node("{selected_scenario.data_nodes['" + dn.config_id + "']}", scenario="{selected_scenario}")

# ##########################################################################################################
# PLACEHOLDER: data node specific content after automatic content #
# #
# Example: #
if dn_label == "initial_dataset":
tgb.text("Select your CSV file:")
tgb.file_selector(
"{selected_data_node.path}",
extensions=".csv",
on_action="{lambda s: s.refresh('selected_scenario')}",
)

# Comment, remove or replace the previous lines with your own use case #
# ##########################################################################################################

return partial_content


Expand Down

0 comments on commit 8ae2f22

Please sign in to comment.