Move calculation of hidden/modelable rows into ModeledMethodDataGrid

This commit is contained in:
Robert
2023-09-08 16:52:06 +01:00
parent 3a8028cb6f
commit 58d38ff867
2 changed files with 23 additions and 14 deletions

View File

@@ -62,26 +62,17 @@ const modelTypeOptions: Array<{ value: ModeledMethodType; label: string }> = [
type Props = {
method: Method;
methodCanBeModeled: boolean;
modeledMethod: ModeledMethod | undefined;
methodIsUnsaved: boolean;
modelingInProgress: boolean;
mode: Mode;
hideModeledApis: boolean;
onChange: (method: Method, modeledMethod: ModeledMethod) => void;
};
export const MethodRow = (props: Props) => {
const { method, modeledMethod, methodIsUnsaved, hideModeledApis } = props;
const methodCanBeModeled =
!method.supported ||
(modeledMethod && modeledMethod?.type !== "none") ||
methodIsUnsaved;
if (methodCanBeModeled) {
if (props.methodCanBeModeled) {
return <ModelableMethodRow {...props} />;
} else if (hideModeledApis) {
return null;
} else {
return <UnmodelableMethodRow {...props} />;
}

View File

@@ -35,7 +35,25 @@ export const ModeledMethodDataGrid = ({
hideModeledApis,
onChange,
}: Props) => {
const sortedMethods = useMemo(() => sortMethods(methods), [methods]);
const methodsWithModelability: Array<{
method: Method;
methodCanBeModeled: boolean;
}> = useMemo(() => {
const methodsWithModelability = [];
for (const method of sortMethods(methods)) {
const modeledMethod = modeledMethods[method.signature];
const methodIsUnsaved = modifiedSignatures.has(method.signature);
const methodCanBeModeled =
!method.supported ||
(modeledMethod && modeledMethod?.type !== "none") ||
methodIsUnsaved;
if (methodCanBeModeled || !hideModeledApis) {
methodsWithModelability.push({ method, methodCanBeModeled });
}
}
return methodsWithModelability;
}, [hideModeledApis, methods, modeledMethods, modifiedSignatures]);
return (
<VSCodeDataGrid gridTemplateColumns={GRID_TEMPLATE_COLUMNS}>
@@ -56,10 +74,11 @@ export const ModeledMethodDataGrid = ({
Kind
</VSCodeDataGridCell>
</VSCodeDataGridRow>
{sortedMethods.map((method) => (
{methodsWithModelability.map(({ method, methodCanBeModeled }) => (
<MethodRow
key={method.signature}
method={method}
methodCanBeModeled={methodCanBeModeled}
modeledMethod={modeledMethods[method.signature]}
methodIsUnsaved={modifiedSignatures.has(method.signature)}
modelingInProgress={inProgressMethods.hasMethod(
@@ -67,7 +86,6 @@ export const ModeledMethodDataGrid = ({
method.signature,
)}
mode={mode}
hideModeledApis={hideModeledApis}
onChange={onChange}
/>
))}