diff --git a/src/components/NavigationTree/NavigationTree.tsx b/src/components/NavigationTree/NavigationTree.tsx index 7c3a737..76451e0 100644 --- a/src/components/NavigationTree/NavigationTree.tsx +++ b/src/components/NavigationTree/NavigationTree.tsx @@ -30,7 +30,7 @@ const renderServiceNode = (node: NavigationTreeServiceNode) => { return ; }; -export function NavigationTree({ +export function NavigationTree({ rootState: partialRootState, fetchPath, getActions, @@ -40,7 +40,7 @@ export function NavigationTree({ onActivePathUpdate, cache = true, virtualize = false, -}: NavigationTreeProps) { +}: NavigationTreeProps) { const [state, dispatch] = React.useReducer(reducer, { [partialRootState.path]: getNodeState(partialRootState), }); diff --git a/src/components/NavigationTree/NavigationTreeNode.tsx b/src/components/NavigationTree/NavigationTreeNode.tsx index 68e763e..a255320 100644 --- a/src/components/NavigationTree/NavigationTreeNode.tsx +++ b/src/components/NavigationTree/NavigationTreeNode.tsx @@ -118,7 +118,16 @@ export function NavigationTreeNode({ payload: {path, error}, }); }); - }, [nodeState.collapsed]); + }, [ + activePath, + cache, + dispatch, + fetchPath, + nodeState.collapsed, + nodeState.loaded, + nodeState.loading, + path, + ]); const handleClick = React.useCallback(() => { if (onActivate) { @@ -131,11 +140,11 @@ export function NavigationTreeNode({ }, [dispatch, path]); const additionalNodeElements = React.useMemo(() => { - return renderAdditionalNodeElements?.(nodeState.path, nodeState.type); + return renderAdditionalNodeElements?.(nodeState.path, nodeState.type, nodeState.meta); }, [renderAdditionalNodeElements, nodeState]); const actions = React.useMemo(() => { - return getActions?.(nodeState.path, nodeState.type); + return getActions?.(nodeState.path, nodeState.type, nodeState.meta); }, [getActions, nodeState]); const handleActionsOpenToggle = React.useCallback( diff --git a/src/components/NavigationTree/types.ts b/src/components/NavigationTree/types.ts index 3cb43f5..0a15a28 100644 --- a/src/components/NavigationTree/types.ts +++ b/src/components/NavigationTree/types.ts @@ -16,11 +16,12 @@ export type NavigationTreeNodeType = | 'transfer' | 'view'; -export interface NavigationTreeDataItem { +export interface NavigationTreeDataItem { name: string; type: NavigationTreeNodeType; /** determined by type by default */ expandable?: boolean; + meta?: M; } export interface NavigationTreeState { @@ -39,6 +40,7 @@ export interface NavigationTreeNodeState { error: boolean; children: string[]; level?: number; + meta?: unknown; } export interface NavigationTreeServiceNode { @@ -52,18 +54,23 @@ export type NavigationTreeNodePartialState = Omit< 'loading' | 'loaded' | 'error' | 'children' >; -export interface NavigationTreeProps { +export interface NavigationTreeProps { rootState: NavigationTreeNodePartialState; - fetchPath: (path: string) => Promise; + fetchPath: (path: string) => Promise[]>; onActionsOpenToggle?: (args: { path: string; type: NavigationTreeNodeType; isOpen: boolean; }) => void; - getActions?: (path: string, type: NavigationTreeNodeType) => DropdownMenuItemMixed[]; + getActions?: ( + path: string, + type: NavigationTreeNodeType, + meta: M, + ) => DropdownMenuItemMixed[]; renderAdditionalNodeElements?: ( path: string, type: NavigationTreeNodeType, + meta: M, ) => JSX.Element | undefined; activePath?: string; onActivePathUpdate?: (activePath: string) => void;