Skip to content

Commit 8e3d987

Browse files
committed
Fix types
1 parent dfc8a88 commit 8e3d987

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

site/src/modules/resources/ResourceCard.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CopyableValue } from "components/CopyableValue/CopyableValue";
66
import { DropdownArrow } from "components/DropdownArrow/DropdownArrow";
77
import { MemoizedInlineMarkdown } from "components/Markdown/Markdown";
88
import { Stack } from "components/Stack/Stack";
9-
import { Children, type FC, type PropsWithChildren, useState } from "react";
9+
import { Children, type FC, useState } from "react";
1010
import { ResourceAvatar } from "./ResourceAvatar";
1111
import { SensitiveValue } from "./SensitiveValue";
1212

@@ -75,14 +75,6 @@ export interface ResourceCardProps {
7575
agentRow: (agent: WorkspaceAgent) => JSX.Element;
7676
}
7777

78-
const p: FC<PropsWithChildren> = ({ children }) => {
79-
const childrens = Children.toArray(children);
80-
if (childrens.every((child) => typeof child === "string")) {
81-
return <CopyableValue value={childrens.join("")}>{children}</CopyableValue>;
82-
}
83-
return <>{children}</>;
84-
};
85-
8678
export const ResourceCard: FC<ResourceCardProps> = ({ resource, agentRow }) => {
8779
const [shouldDisplayAllMetadata, setShouldDisplayAllMetadata] =
8880
useState(false);
@@ -146,7 +138,25 @@ export const ResourceCard: FC<ResourceCardProps> = ({ resource, agentRow }) => {
146138
{meta.sensitive ? (
147139
<SensitiveValue value={meta.value} />
148140
) : (
149-
<MemoizedInlineMarkdown components={{ p }}>
141+
<MemoizedInlineMarkdown
142+
components={{
143+
p: ({ children }) => {
144+
const childrens = Children.toArray(children);
145+
if (
146+
childrens.every(
147+
(child) => typeof child === "string",
148+
)
149+
) {
150+
return (
151+
<CopyableValue value={childrens.join("")}>
152+
{children}
153+
</CopyableValue>
154+
);
155+
}
156+
return <>{children}</>;
157+
},
158+
}}
159+
>
150160
{meta.value}
151161
</MemoizedInlineMarkdown>
152162
)}

site/src/pages/WorkspacePage/ResourceMetadata.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ import type { WorkspaceResource } from "api/typesGenerated";
33
import { CopyableValue } from "components/CopyableValue/CopyableValue";
44
import { MemoizedInlineMarkdown } from "components/Markdown/Markdown";
55
import { SensitiveValue } from "modules/resources/SensitiveValue";
6-
import {
7-
Children,
8-
type FC,
9-
type HTMLAttributes,
10-
type PropsWithChildren,
11-
} from "react";
6+
import { Children, type FC, type HTMLAttributes } from "react";
127

138
type ResourceMetadataProps = Omit<HTMLAttributes<HTMLElement>, "resource"> & {
149
resource: WorkspaceResource;
@@ -41,7 +36,25 @@ export const ResourceMetadata: FC<ResourceMetadataProps> = ({
4136
{meta.sensitive ? (
4237
<SensitiveValue value={meta.value} />
4338
) : (
44-
<MemoizedInlineMarkdown components={{ p: MetaValue }}>
39+
<MemoizedInlineMarkdown
40+
components={{
41+
p: ({ children }) => {
42+
const childrenArray = Children.toArray(children);
43+
if (
44+
childrenArray.every(
45+
(child) => typeof child === "string",
46+
)
47+
) {
48+
return (
49+
<CopyableValue value={childrenArray.join("")}>
50+
{children}
51+
</CopyableValue>
52+
);
53+
}
54+
return <>{children}</>;
55+
},
56+
}}
57+
>
4558
{meta.value}
4659
</MemoizedInlineMarkdown>
4760
)}
@@ -54,16 +67,6 @@ export const ResourceMetadata: FC<ResourceMetadataProps> = ({
5467
);
5568
};
5669

57-
const MetaValue: FC<PropsWithChildren> = ({ children }) => {
58-
const childrenArray = Children.toArray(children);
59-
if (childrenArray.every((child) => typeof child === "string")) {
60-
return (
61-
<CopyableValue value={childrenArray.join("")}>{children}</CopyableValue>
62-
);
63-
}
64-
return <>{children}</>;
65-
};
66-
6770
const styles = {
6871
root: (theme) => ({
6972
padding: 24,

0 commit comments

Comments
 (0)