@@ -11,6 +11,7 @@ import { useMemo } from "react";
1111import { Mode } from "../../model-editor/shared/mode" ;
1212import { sortMethods } from "../../model-editor/shared/sorting" ;
1313import { InProgressMethods } from "../../model-editor/shared/in-progress-methods" ;
14+ import { HiddenMethodsRow } from "./HiddenMethodsRow" ;
1415
1516export const GRID_TEMPLATE_COLUMNS = "0.5fr 0.125fr 0.125fr 0.125fr 0.125fr" ;
1617
@@ -35,42 +36,73 @@ export const ModeledMethodDataGrid = ({
3536 hideModeledApis,
3637 onChange,
3738} : Props ) => {
38- const sortedMethods = useMemo ( ( ) => sortMethods ( methods ) , [ methods ] ) ;
39+ const [ methodsWithModelability , numHiddenMethods ] : [
40+ Array < { method : Method ; methodCanBeModeled : boolean } > ,
41+ number ,
42+ ] = useMemo ( ( ) => {
43+ const methodsWithModelability = [ ] ;
44+ let numHiddenMethods = 0 ;
45+ for ( const method of sortMethods ( methods ) ) {
46+ const modeledMethod = modeledMethods [ method . signature ] ;
47+ const methodIsUnsaved = modifiedSignatures . has ( method . signature ) ;
48+ const methodCanBeModeled =
49+ ! method . supported ||
50+ ( modeledMethod && modeledMethod ?. type !== "none" ) ||
51+ methodIsUnsaved ;
52+
53+ if ( methodCanBeModeled || ! hideModeledApis ) {
54+ methodsWithModelability . push ( { method, methodCanBeModeled } ) ;
55+ } else {
56+ numHiddenMethods += 1 ;
57+ }
58+ }
59+ return [ methodsWithModelability , numHiddenMethods ] ;
60+ } , [ hideModeledApis , methods , modeledMethods , modifiedSignatures ] ) ;
61+
62+ const someMethodsAreVisible = methodsWithModelability . length > 0 ;
3963
4064 return (
4165 < VSCodeDataGrid gridTemplateColumns = { GRID_TEMPLATE_COLUMNS } >
42- < VSCodeDataGridRow rowType = "header" >
43- < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 1 } >
44- API or method
45- </ VSCodeDataGridCell >
46- < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 2 } >
47- Model type
48- </ VSCodeDataGridCell >
49- < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 3 } >
50- Input
51- </ VSCodeDataGridCell >
52- < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 4 } >
53- Output
54- </ VSCodeDataGridCell >
55- < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 5 } >
56- Kind
57- </ VSCodeDataGridCell >
58- </ VSCodeDataGridRow >
59- { sortedMethods . map ( ( method ) => (
60- < MethodRow
61- key = { method . signature }
62- method = { method }
63- modeledMethod = { modeledMethods [ method . signature ] }
64- methodIsUnsaved = { modifiedSignatures . has ( method . signature ) }
65- modelingInProgress = { inProgressMethods . hasMethod (
66- packageName ,
67- method . signature ,
68- ) }
69- mode = { mode }
70- hideModeledApis = { hideModeledApis }
71- onChange = { onChange }
72- />
73- ) ) }
66+ { someMethodsAreVisible && (
67+ < >
68+ < VSCodeDataGridRow rowType = "header" >
69+ < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 1 } >
70+ API or method
71+ </ VSCodeDataGridCell >
72+ < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 2 } >
73+ Model type
74+ </ VSCodeDataGridCell >
75+ < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 3 } >
76+ Input
77+ </ VSCodeDataGridCell >
78+ < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 4 } >
79+ Output
80+ </ VSCodeDataGridCell >
81+ < VSCodeDataGridCell cellType = "columnheader" gridColumn = { 5 } >
82+ Kind
83+ </ VSCodeDataGridCell >
84+ </ VSCodeDataGridRow >
85+ { methodsWithModelability . map ( ( { method, methodCanBeModeled } ) => (
86+ < MethodRow
87+ key = { method . signature }
88+ method = { method }
89+ methodCanBeModeled = { methodCanBeModeled }
90+ modeledMethod = { modeledMethods [ method . signature ] }
91+ methodIsUnsaved = { modifiedSignatures . has ( method . signature ) }
92+ modelingInProgress = { inProgressMethods . hasMethod (
93+ packageName ,
94+ method . signature ,
95+ ) }
96+ mode = { mode }
97+ onChange = { onChange }
98+ />
99+ ) ) }
100+ </ >
101+ ) }
102+ < HiddenMethodsRow
103+ numHiddenMethods = { numHiddenMethods }
104+ someMethodsAreVisible = { someMethodsAreVisible }
105+ />
74106 </ VSCodeDataGrid >
75107 ) ;
76108} ;
0 commit comments