-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TreeView] New instance and publicAPI method: getItem
#12251
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import * as React from 'react'; | ||
import { TreeViewAnyPluginSignature, TreeViewUsedPublicAPI } from '../internals/models'; | ||
import { TreeViewAnyPluginSignature, TreeViewPublicAPI } from '../internals/models'; | ||
import { DefaultTreeViewPlugins } from '../internals'; | ||
|
||
/** | ||
* Hook that instantiates a [[TreeViewApiRef]]. | ||
*/ | ||
export const useTreeViewApiRef = < | ||
T extends TreeViewAnyPluginSignature, | ||
Api extends TreeViewUsedPublicAPI<T>, | ||
>() => React.useRef(undefined) as React.MutableRefObject<Api>; | ||
TPlugins extends readonly TreeViewAnyPluginSignature[] = DefaultTreeViewPlugins, | ||
>() => React.useRef(undefined) as React.MutableRefObject<TreeViewPublicAPI<TPlugins> | undefined>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,8 @@ export interface UseTreeViewFocusInstance { | |
focusDefaultNode: (event: React.SyntheticEvent) => void; | ||
focusRoot: () => void; | ||
} | ||
export interface UseTreeViewFocusPublicAPI { | ||
focusNode: (event: React.SyntheticEvent, nodeId: string | null) => void; | ||
} | ||
|
||
export interface UseTreeViewFocusPublicAPI extends Pick<UseTreeViewFocusInstance, 'focusNode'> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ensure the public API is always a subset of the private one |
||
|
||
export interface UseTreeViewFocusParameters { | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,14 +8,18 @@ interface TreeViewNodeProps { | |
children?: TreeViewNodeProps[]; | ||
} | ||
|
||
export interface UseTreeViewNodesInstance { | ||
export interface UseTreeViewNodesInstance<R extends {}> { | ||
getNode: (nodeId: string) => TreeViewNode; | ||
getItem: (nodeId: string) => R; | ||
getNodesToRender: () => TreeViewNodeProps[]; | ||
getChildrenIds: (nodeId: string | null) => string[]; | ||
getNavigableChildrenIds: (nodeId: string | null) => string[]; | ||
isNodeDisabled: (nodeId: string | null) => nodeId is string; | ||
} | ||
|
||
export interface UseTreeViewNodesPublicAPI<R extends {}> | ||
extends Pick<UseTreeViewNodesInstance<R>, 'getItem'> {} | ||
|
||
export interface UseTreeViewNodesParameters<R extends {}> { | ||
/** | ||
* If `true`, will allow focus on disabled items. | ||
|
@@ -66,9 +70,12 @@ export interface TreeViewNodeIdAndChildren { | |
children?: TreeViewNodeIdAndChildren[]; | ||
} | ||
|
||
export interface UseTreeViewNodesState { | ||
nodeTree: TreeViewNodeIdAndChildren[]; | ||
nodeMap: TreeViewNodeMap; | ||
export interface UseTreeViewNodesState<R extends {}> { | ||
nodes: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I scoped the node state because having 3 elements at the root was starting to be messy |
||
nodeTree: TreeViewNodeIdAndChildren[]; | ||
nodeMap: TreeViewNodeMap; | ||
itemMap: TreeViewItemMap<R>; | ||
}; | ||
} | ||
|
||
interface UseTreeViewNodesContextValue | ||
|
@@ -77,10 +84,13 @@ interface UseTreeViewNodesContextValue | |
export type UseTreeViewNodesSignature = TreeViewPluginSignature<{ | ||
params: UseTreeViewNodesParameters<any>; | ||
defaultizedParams: UseTreeViewNodesDefaultizedParameters<any>; | ||
instance: UseTreeViewNodesInstance; | ||
instance: UseTreeViewNodesInstance<any>; | ||
publicAPI: UseTreeViewNodesPublicAPI<any>; | ||
events: UseTreeViewNodesEventLookup; | ||
state: UseTreeViewNodesState; | ||
state: UseTreeViewNodesState<any>; | ||
contextValue: UseTreeViewNodesContextValue; | ||
}>; | ||
|
||
export type TreeViewNodeMap = { [nodeId: string]: TreeViewNode }; | ||
|
||
export type TreeViewItemMap<R extends {}> = { [nodeId: string]: R }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typing was weird, it was only taking a single plugin
Now by default the type is the one of the default plugins (which are used by both the rich and the simple tree view)
but you can pass a generic to support more plugins (not useful for now, will become useful with RichTreeView-only plugins if they end up having public methods)