Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(site): minor refactor to the resource metadata code#11746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 1 commit intomainfrombq/resource-metadata-truncate
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletionssite/src/pages/WorkspacePage/ResourceMetadata.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
import { MockWorkspaceResource } from "testHelpers/entities";
import type { Meta, StoryObj } from "@storybook/react";
import { ResourceMetadata } from "./ResourceMetadata";

const meta: Meta<typeof ResourceMetadata> = {
title: "pages/WorkspacePage/ResourceMetadata",
component: ResourceMetadata,
};

export default meta;
type Story = StoryObj<typeof ResourceMetadata>;

export const Markdown: Story = {
args: {
resource: {
...MockWorkspaceResource,
metadata: [
{ key: "text", value: "hello", sensitive: false },
{ key: "link", value: "[hello](#)", sensitive: false },
{ key: "b/i", value: "_hello_, **friend**!", sensitive: false },
{ key: "coder", value: "`beep boop`", sensitive: false },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should we have asensitive: true test case?

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, we should. I missed this comment so, I'm going to add it in a next PR.

Copy link
CollaboratorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

],
},
},
};

export const WithLongStrings: Story = {
args: {
resource: {
...MockWorkspaceResource,
metadata: [
{
key: "xxxxxxxxxxxx",
value: "14",
sensitive: false,
},
{
key: "Long",
value: "The quick brown fox jumped over the lazy dog",
sensitive: false,
},
{
key: "Really long",
value:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
sensitive: false,
},
],
},
},
};
91 changes: 91 additions & 0 deletionssite/src/pages/WorkspacePage/ResourceMetadata.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
import { MemoizedInlineMarkdown } from "components/Markdown/Markdown";
import { SensitiveValue } from "components/Resources/SensitiveValue";
import { CopyableValue } from "components/CopyableValue/CopyableValue";
import { WorkspaceResource } from "api/typesGenerated";
import { Children, FC, HTMLAttributes, PropsWithChildren } from "react";
import { Interpolation, Theme } from "@emotion/react";

type ResourceMetadataProps = Omit<HTMLAttributes<HTMLElement>, "resource"> & {
resource: WorkspaceResource;
};

export const ResourceMetadata: FC<ResourceMetadataProps> = ({
resource,
...headerProps
}) => {
const metadata = resource.metadata ? [...resource.metadata] : [];

if (resource.daily_cost > 0) {
metadata.push({
key: "Daily cost",
value: resource.daily_cost.toString(),
sensitive: false,
});
}

if (metadata.length === 0) {
return null;
}

return (
<header css={styles.root} {...headerProps}>
{metadata.map((meta) => {
return (
<div css={styles.item} key={meta.key}>
<div css={styles.value}>
{meta.sensitive ? (
<SensitiveValue value={meta.value} />
) : (
<MemoizedInlineMarkdown components={{ p: MetaValue }}>
{meta.value}
</MemoizedInlineMarkdown>
)}
</div>
<div css={styles.label}>{meta.key}</div>
</div>
);
})}
</header>
);
};

const MetaValue = ({ children }: PropsWithChildren) => {
const childrenArray = Children.toArray(children);
if (childrenArray.every((child) => typeof child === "string")) {
return (
<CopyableValue value={childrenArray.join("")}>{children}</CopyableValue>
);
}
return <>{children}</>;
};

const styles = {
root: (theme) => ({
padding: 24,
display: "flex",
flexWrap: "wrap",
gap: 48,
rowGap: 24,
marginBottom: 24,
fontSize: 14,
background: `linear-gradient(180deg, ${theme.palette.background.default} 0%, rgba(0, 0, 0, 0) 100%)`,
}),

item: () => ({
lineHeight: "1.5",
}),

label: (theme) => ({
fontSize: 13,
color: theme.palette.text.secondary,
textOverflow: "ellipsis",
overflow: "hidden",
whiteSpace: "nowrap",
}),

value: () => ({
textOverflow: "ellipsis",
overflow: "hidden",
whiteSpace: "nowrap",
}),
} satisfies Record<string, Interpolation<Theme>>;
90 changes: 6 additions & 84 deletionssite/src/pages/WorkspacePage/Workspace.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
import { type Interpolation, type Theme } from "@emotion/react";
import Button from "@mui/material/Button";
import AlertTitle from "@mui/material/AlertTitle";
import {PropsWithChildren,type FC, Children } from "react";
import { type FC } from "react";
import { useNavigate } from "react-router-dom";
import type * as TypesGen from "api/typesGenerated";
import { Alert, AlertDetail } from "components/Alert/Alert";
Expand All@@ -21,9 +21,7 @@ import HubOutlined from "@mui/icons-material/HubOutlined";
import { ResourcesSidebar } from "./ResourcesSidebar";
import { WorkspacePermissions } from "./permissions";
import { resourceOptionValue, useResourcesNav } from "./useResourcesNav";
import { MemoizedInlineMarkdown } from "components/Markdown/Markdown";
import { SensitiveValue } from "components/Resources/SensitiveValue";
import { CopyableValue } from "components/CopyableValue/CopyableValue";
import { ResourceMetadata } from "./ResourceMetadata";

export interface WorkspaceProps {
handleStart: (buildParameters?: TypesGen.WorkspaceBuildParameter[]) => void;
Expand DownExpand Up@@ -187,7 +185,10 @@ export const Workspace: FC<WorkspaceProps> = ({
<div css={styles.content}>
<div css={styles.dotBackground}>
{selectedResource && (
<WorkspaceResourceData resource={selectedResource} />
<ResourceMetadata
resource={selectedResource}
css={{ margin: "-48px 0 24px -48px" }}
/>
)}
<div
css={{
Expand DownExpand Up@@ -282,55 +283,6 @@ export const Workspace: FC<WorkspaceProps> = ({
);
};

const WorkspaceResourceData: FC<{ resource: TypesGen.WorkspaceResource }> = ({
resource,
}) => {
const metadata = resource.metadata ? [...resource.metadata] : [];

if (resource.daily_cost > 0) {
metadata.push({
key: "Daily cost",
value: resource.daily_cost.toString(),
sensitive: false,
});
}

if (metadata.length === 0) {
return null;
}

return (
<header css={styles.resourceData}>
{metadata.map((meta) => {
return (
<div css={styles.resourceDataItem} key={meta.key}>
<div css={styles.resourceDataItemValue}>
{meta.sensitive ? (
<SensitiveValue value={meta.value} />
) : (
<MemoizedInlineMarkdown components={{ p: MetaValue }}>
{meta.value}
</MemoizedInlineMarkdown>
)}
</div>
<div css={styles.resourceDataItemLabel}>{meta.key}</div>
</div>
);
})}
</header>
);
};

const MetaValue = ({ children }: PropsWithChildren) => {
const childrenArray = Children.toArray(children);
if (childrenArray.every((child) => typeof child === "string")) {
return (
<CopyableValue value={childrenArray.join("")}>{children}</CopyableValue>
);
}
return <>{children}</>;
};

const countAgents = (resource: TypesGen.WorkspaceResource) => {
return resource.agents ? resource.agents.length : 0;
};
Expand DownExpand Up@@ -365,34 +317,4 @@ const styles = {
flexDirection: "column",
},
}),

resourceData: (theme) => ({
padding: 24,
margin: "-48px 0 0 -48px",
display: "flex",
flexWrap: "wrap",
gap: 48,
rowGap: 24,
marginBottom: 24,
fontSize: 14,
background: `linear-gradient(180deg, ${theme.palette.background.default} 0%, rgba(0, 0, 0, 0) 100%)`,
}),

resourceDataItem: () => ({
lineHeight: "1.5",
}),

resourceDataItemLabel: (theme) => ({
fontSize: 13,
color: theme.palette.text.secondary,
textOverflow: "ellipsis",
overflow: "hidden",
whiteSpace: "nowrap",
}),

resourceDataItemValue: () => ({
textOverflow: "ellipsis",
overflow: "hidden",
whiteSpace: "nowrap",
}),
} satisfies Record<string, Interpolation<Theme>>;

[8]ページ先頭

©2009-2025 Movatter.jp