Skip to content

Commit 00dafc8

Browse files
committed
fix: 🐛 table view for the methods
1 parent 62a14d2 commit 00dafc8

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

packages/core/src/pages/components/methods.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const Methods: React.FC<PagePropsType & MethodsProps> = (props) => {
4343
title="Methods"
4444
reflections={methods}
4545
reflectionsTree={reflectionsTree}
46+
hideType
4647
/>
4748
);
4849
}

packages/core/src/pages/modules/table/table.tsx

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ import { JSONOutput } from "typedoc";
33
import { Code } from "pages/components/code";
44
import { Type } from "pages/components/type";
55
import { PagePropsType } from "types/page.types";
6-
import { getCallPreview } from "pages/utils/parsing.utils";
76
import { getCommentNode } from "pages/handlers/comment";
7+
import { getSignaturePreview } from "pages/utils";
88

99
export const Table = ({
1010
reflections,
1111
reflectionsTree,
1212
pageProps,
1313
title,
1414
className = "",
15+
hideType = false,
1516
}: {
1617
reflections: JSONOutput.SomeReflection[];
1718
reflectionsTree: JSONOutput.ProjectReflection[];
1819
pageProps: PagePropsType;
1920
title?: string;
2021
className?: string;
22+
hideType?: boolean;
2123
}) => {
2224
return (
2325
<div className={`api-docs__table-wrapper ${className}`}>
@@ -26,31 +28,42 @@ export const Table = ({
2628
<thead>
2729
<tr>
2830
<th>Name</th>
29-
<th>Type</th>
31+
{!hideType && <th>Type</th>}
3032
<th>Description</th>
3133
</tr>
3234
</thead>
3335
<tbody>
3436
{reflections.map((reflection, index) => {
3537
const isMethod = "signatures" in reflection;
36-
const callSignature =
37-
("signatures" in reflection &&
38-
reflection?.signatures &&
39-
getCallPreview({ signature: reflection.signatures[0], reflectionsTree })) ||
40-
"";
38+
const name =
39+
"signatures" in reflection && reflection?.signatures
40+
? getSignaturePreview({
41+
reflection: reflection.signatures[0],
42+
reflectionsTree,
43+
useArrow: true,
44+
hideGenerics: true,
45+
hideParamTypes: true,
46+
hideReturns: true,
47+
})
48+
: reflection.name;
4149
const type = "type" in reflection && typeof reflection.type !== "string" ? reflection.type : reflection;
4250

4351
return (
4452
<tr className="api-docs__table-row" key={index}>
45-
<td className="api-docs__table-name">
46-
{reflection.name}
47-
{isMethod ? callSignature : ""}
48-
</td>
49-
<td className="api-docs__table-type">
50-
<Code>
51-
<Type {...pageProps} reflection={type} />
52-
</Code>
53-
</td>
53+
{isMethod ? (
54+
<td className="api-docs__table-type">
55+
<Code>{name}</Code>
56+
</td>
57+
) : (
58+
<td className="api-docs__table-name">{name}</td>
59+
)}
60+
{!hideType && (
61+
<td className="api-docs__table-type">
62+
<Code>
63+
<Type {...pageProps} reflection={type} />
64+
</Code>
65+
</td>
66+
)}
5467
<td className="api-docs__table-description">{getCommentNode(reflection)}</td>
5568
</tr>
5669
);

packages/core/src/pages/utils/signature.utils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ export const getSignaturePreview = ({
4040
reflectionsTree,
4141
useArrow,
4242
hideName,
43+
hideGenerics,
44+
hideParamTypes,
45+
hideReturns,
4346
}: {
4447
reflection: JSONOutput.SignatureReflection;
4548
reflectionsTree: JSONOutput.ProjectReflection[];
4649
useArrow?: boolean;
4750
hideName?: boolean;
51+
hideGenerics?: boolean;
52+
hideParamTypes?: boolean;
53+
hideReturns?: boolean;
4854
}): string => {
4955
const hasName = !hideName && reflection.name !== "__type";
5056
const isConstructor = reflection.kind === ReflectionKind.Constructor;
@@ -53,14 +59,23 @@ export const getSignaturePreview = ({
5359

5460
const name = hasName ? reflection.name : constructorName;
5561

56-
const generics = getGenericParamsPreview({ generics: reflection.typeParameter });
62+
const generics = !hideGenerics ? getGenericParamsPreview({ generics: reflection.typeParameter }) : "";
5763
const params =
5864
reflection.parameters
5965
?.map((param) => {
66+
if (hideParamTypes) {
67+
return param.name;
68+
}
6069
const type = getTypePreview({ typeReflection: param.type, reflectionsTree });
6170
return `${param.flags?.isRest ? "..." : ""}${param.name}${param.flags?.isOptional ? "?" : ""}: ${type}`;
6271
})
6372
.join(", ") || "";
73+
const returns = !hideReturns
74+
? `${useArrow ? " => " : ": "}${getTypePreview({
75+
typeReflection: reflection.type,
76+
reflectionsTree,
77+
})}`
78+
: "";
6479

65-
return `${name}${generics}(${params})${useArrow ? " => " : ": "}${getTypePreview({ typeReflection: reflection.type, reflectionsTree })}`;
80+
return `${name}${generics}(${params})${returns}`;
6681
};

0 commit comments

Comments
 (0)