Skip to content

Commit

Permalink
Merge branch 'develop' into feature/datanode-selector-filter-sort-and…
Browse files Browse the repository at this point in the history
…-search
  • Loading branch information
FredLL-Avaiga authored Jun 7, 2024
2 parents 426db0b + 6cda06e commit 78be002
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions frontend/taipy/src/CoreSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ interface CoreSelectorProps {
leafType: NodeType;
editComponent?: ComponentType<EditProps>;
showPins?: boolean;
onSelect?: (id: string | string[]) => void;
onSelect?: (id: string | string[] | null) => void;
updateCoreVars: string;
filter?: string;
sort?: string;
Expand Down Expand Up @@ -295,7 +295,7 @@ const filterTree = (entities: Entities, search: string, leafType: NodeType, coun
};

const localStoreSet = (val: string, ...ids: string[]) => {
const id = ids.filter(i => !!i).join(" ");
const id = ids.filter((i) => !!i).join(" ");
if (!id) {
return;
}
Expand All @@ -307,7 +307,7 @@ const localStoreSet = (val: string, ...ids: string[]) => {
};

const localStoreGet = (...ids: string[]) => {
const id = ids.filter(i => !!i).join(" ");
const id = ids.filter((i) => !!i).join(" ");
if (!id) {
return undefined;
}
Expand Down Expand Up @@ -365,23 +365,21 @@ const CoreSelector = (props: CoreSelectorProps) => {
}, []);

const onNodeSelect = useCallback(
(e: SyntheticEvent, nodeId: string, isSelected: boolean) => {
(e: SyntheticEvent, nodeId: string | string[] | null) => {
const { selectable = "false" } = e.currentTarget.parentElement?.dataset || {};
const isSelectable = selectable === "true";
if (!isSelectable && multiple) {
return;
}
setSelectedItems((old) => {
const res = isSelected ? [...old, nodeId] : old.filter((id) => id !== nodeId);
const scenariosVar = getUpdateVar(updateVars, lovPropertyName);
const val = multiple ? res : isSelectable ? nodeId : "";
setSelectedItems(() => {
const lovVar = getUpdateVar(updateVars, lovPropertyName);
const val = multiple ? nodeId : isSelectable ? nodeId : "";
setTimeout(
() =>
dispatch(createSendUpdateAction(updateVarName, val, module, onChange, propagate, scenariosVar)),
() => dispatch(createSendUpdateAction(updateVarName, val, module, onChange, propagate, lovVar)),
1
);
onSelect && isSelectable && onSelect(val);
return res;
return Array.isArray(nodeId) ? nodeId : nodeId ? [nodeId] : [];
});
},
[updateVarName, updateVars, onChange, onSelect, multiple, propagate, dispatch, module, lovPropertyName]
Expand Down Expand Up @@ -669,7 +667,7 @@ const CoreSelector = (props: CoreSelectorProps) => {
<SimpleTreeView
slots={treeSlots}
sx={treeViewSx}
onItemSelectionToggle={onNodeSelect}
onSelectedItemsChange={onNodeSelect}
selectedItems={selectedItems}
multiSelect={multiple}
expandedItems={expandedItems}
Expand Down

0 comments on commit 78be002

Please sign in to comment.