@@ -16,6 +16,11 @@ import styles from './DataSearch.module.scss';
1616import { OptionRowInfo } from './SlotMenu' ;
1717
1818import Icon from '@/components/atoms/Icon/Icon' ;
19+ import {
20+ definitionMembersReader ,
21+ type MemberSpec ,
22+ type MembersRead ,
23+ } from '@/lib/search/definitionMembers' ;
1924import { graphReader } from '@/lib/search/graphReads' ;
2025import { graphNodeDescription } from '@/lib/search/measureMenu' ;
2126import { notePosition , noteShown } from '@/lib/search/notePosition' ;
@@ -28,6 +33,8 @@ const readNoNote = () => null;
2833
2934const graph = graphReader ( { fetchImpl : ( url , init ) => fetch ( url , init ) } ) ;
3035
36+ const readMembers = definitionMembersReader ( ) ;
37+
3138// The graph's own documentation for a source (the same door the Sources
3239// pages read), shared by every row that asks. A source with no page (the
3340// catalogue excludes it, or the read failed) resolves to null.
@@ -336,6 +343,27 @@ export const useNodeDescriptions = (dcids: string[]): (string | null)[] => {
336343 return useSettled ( pending ) ?? dcids . map ( ( ) => null ) ;
337344} ;
338345
346+ // Settles to null, so a hook given no Spec reads nothing.
347+ const NO_MEMBERS : Promise < MembersRead | null > = Promise . resolve ( null ) ;
348+
349+ /** The StatVars `spec` serves, from the Datasets members door, null while
350+ * unread and for a null `spec`. A caller passes the Spec only once its
351+ * panel is open, so a closed panel asks nothing. */
352+ export const useDefinitionMembers = ( spec : MemberSpec | null ) : MembersRead | null => {
353+ const specId = spec ?. spec_id ?? null ;
354+ const definition = spec ?. definition ;
355+ const digest = spec ?. shape ?. member_digest ?? null ;
356+ const pending = useMemo (
357+ ( ) =>
358+ specId
359+ ? readMembers ( { spec_id : specId , definition, shape : { member_digest : digest } } )
360+ : NO_MEMBERS ,
361+ [ specId , definition , digest ] ,
362+ ) ;
363+
364+ return useSettled ( pending ) ;
365+ } ;
366+
339367/** Each source's description from its documentation page, and whether the
340368 * catalogue has that page to link to, in order. Each reads null and false
341369 * until the reads settle. */
0 commit comments