@@ -7,7 +7,9 @@ import { SpinContainer } from "../Common";
77import FeedTree from "./FeedTree" ;
88import type { TreeNodeDatum } from "./data" ;
99import type { PaginatedTreeQueryReturn } from "../Feeds/usePaginatedTreeQuery" ;
10- import type { Feed } from "@fnndsc/chrisapi" ;
10+ import type { Feed , PluginInstance } from "@fnndsc/chrisapi" ;
11+ import { collectionJsonToJson } from "../../api/api" ;
12+ import type { PluginInstance as PluginInstanceType } from "../../api/types" ;
1113
1214interface ParentComponentProps {
1315 changeLayout : ( ) => void ;
@@ -44,14 +46,43 @@ const ParentComponent: React.FC<ParentComponentProps> = ({
4446
4547 const stableRootNode = useMemo ( ( ) => rootNode , [ rootNode ] ) ;
4648
49+ const lastPluginInstance = pluginInstances . reduce (
50+ ( r : PluginInstance | null , x , i ) => {
51+ if ( r === null ) {
52+ return x ;
53+ }
54+ const rJson = collectionJsonToJson ( r ) ;
55+ const xJson = collectionJsonToJson ( x ) ;
56+
57+ return rJson . id <= xJson . id ? x : r ;
58+ } ,
59+ null ,
60+ ) ;
61+
62+ console . info (
63+ "ParentComponent: pluginInstances:" ,
64+ pluginInstances ,
65+ "lastPluginInstance:" ,
66+ lastPluginInstance ,
67+ ) ;
68+
4769 useEffect ( ( ) => {
48- if ( stableRootNode ?. item && ! selectedPlugin ) {
49- dispatch ( getSelectedPlugin ( stableRootNode . item ) ) ;
70+ if ( ! stableRootNode ?. item || selectedPlugin || ! lastPluginInstance ) {
71+ return ;
5072 }
51- } , [ stableRootNode , dispatch , selectedPlugin ] ) ;
73+
74+ console . info (
75+ "ParentComponent: stableRootNode:" ,
76+ stableRootNode ,
77+ "lastPluginInstance:" ,
78+ lastPluginInstance ,
79+ ) ;
80+ dispatch ( getSelectedPlugin ( lastPluginInstance ) ) ;
81+ } , [ stableRootNode , dispatch , selectedPlugin , lastPluginInstance ] ) ;
5282
5383 const onNodeClick = useCallback (
5484 ( node : TreeNodeDatum ) => {
85+ console . info ( "ParentComponent: onNodeClick: node:" , node . item ) ;
5586 node . item && dispatch ( getSelectedPlugin ( node . item ) ) ;
5687 } ,
5788 [ dispatch ] ,
0 commit comments