Skip to content

Commit

Permalink
Selection of leaf datanode in datanode selector tree lov (#1406)
Browse files Browse the repository at this point in the history
* Selection of leaf datanode in datanode selctor tree lov
resolves #1388

* ?... : null is better than &&

---------

Co-authored-by: Fred Lefévère-Laoide <[email protected]>
  • Loading branch information
FredLL-Avaiga and Fred Lefévère-Laoide authored Jun 13, 2024
1 parent 198a4da commit 4e5424a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 61 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

0 comments on commit 4e5424a

Please sign in to comment.