Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
better story for resource metadata designs
  • Loading branch information
aslilac committed Sep 22, 2023
commit e8bb034d78aeac96caf3c5daa809f75cb8c17eb3
95 changes: 36 additions & 59 deletions site/src/components/Resources/ResourceCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,14 @@ import { AgentRow } from "./AgentRow";
import { ResourceCard } from "./ResourceCard";
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
import type { Meta, StoryObj } from "@storybook/react";
import { type WorkspaceAgent } from "api/typesGenerated";

const meta: Meta<typeof ResourceCard> = {
title: "components/ResourceCard",
title: "components/Resources/ResourceCard",
component: ResourceCard,
args: {
resource: MockWorkspaceResource,
agentRow: (agent) => (
<ProxyContext.Provider
value={{
proxyLatencies: MockProxyLatencies,
proxy: getPreferredProxy([], undefined),
proxies: [],
isLoading: false,
isFetched: true,
setProxy: () => {
return;
},
clearProxy: () => {
return;
},
refetchProxyLatencies: (): Date => {
return new Date();
},
}}
>
<AgentRow
showApps
key={agent.id}
agent={agent}
workspace={MockWorkspace}
serverVersion=""
onUpdateAgent={action("updateAgent")}
/>
</ProxyContext.Provider>
),
agentRow: getAgentRow,
},
};

Expand Down Expand Up @@ -96,34 +69,38 @@ export const BunchOfMetadata: Story = {
},
],
},
agentRow: (agent) => (
<ProxyContext.Provider
value={{
proxyLatencies: MockProxyLatencies,
proxy: getPreferredProxy([], undefined),
proxies: [],
isLoading: false,
isFetched: true,
setProxy: () => {
return;
},
clearProxy: () => {
return;
},
refetchProxyLatencies: (): Date => {
return new Date();
},
}}
>
<AgentRow
showApps
key={agent.id}
agent={agent}
workspace={MockWorkspace}
serverVersion=""
onUpdateAgent={action("updateAgent")}
/>
</ProxyContext.Provider>
),
agentRow: getAgentRow,
},
};

function getAgentRow(agent: WorkspaceAgent): JSX.Element {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not create a component instead of having a getAgentRow? ExampleAgentRow?

Copy link
Member Author

Choose a reason for hiding this comment

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

idk, this is just the way that it's already set up. 😅

return (
<ProxyContext.Provider
value={{
proxyLatencies: MockProxyLatencies,
proxy: getPreferredProxy([], undefined),
proxies: [],
isLoading: false,
isFetched: true,
setProxy: () => {
return;
},
clearProxy: () => {
return;
},
refetchProxyLatencies: (): Date => {
return new Date();
},
}}
>
<AgentRow
showApps
key={agent.id}
agent={agent}
workspace={MockWorkspace}
serverVersion=""
onUpdateAgent={action("updateAgent")}
/>
</ProxyContext.Provider>
);
}
148 changes: 148 additions & 0 deletions site/src/components/Resources/Resources.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { action } from "@storybook/addon-actions";
import {
MockProxyLatencies,
MockWorkspace,
MockWorkspaceResource,
} from "testHelpers/entities";
import { AgentRow } from "./AgentRow";
import { Resources } from "./Resources";
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
import type { Meta, StoryObj } from "@storybook/react";
import { type WorkspaceAgent } from "api/typesGenerated";

const meta: Meta<typeof Resources> = {
title: "components/Resources/Resources",
component: Resources,
args: {
resources: [MockWorkspaceResource],
agentRow: getAgentRow,
},
};

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

export const Example: Story = {};

const nullDevice = {
created_at: "",
job_id: "",
workspace_transition: "start",
type: "null_resource",
hide: false,
icon: "",
daily_cost: 0,
} as const;

const short = {
key: "Short",
value: "Hi!",
sensitive: false,
};
const long = {
key: "Long",
value: "The quick brown fox jumped over the lazy dog",
sensitive: false,
};
const reallyLong = {
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,
};

export const BunchOfDevicesWithMetadata: Story = {
args: {
resources: [
MockWorkspaceResource,
{
...nullDevice,
id: "e8c846da",
name: "device1",
metadata: [short],
},
{
...nullDevice,
id: "a1b11343",
name: "device3",
metadata: [long],
},
{
...nullDevice,
id: "09ab7e8c",
name: "device3",
metadata: [reallyLong],
},
{
...nullDevice,
id: "0a09fa91",
name: "device2",
metadata: Array.from({ length: 8 }, (_, i) => ({
...short,
key: `Short ${i}`,
})),
},
{
...nullDevice,
id: "d0b9eb9d",
name: "device4",
metadata: Array.from({ length: 4 }, (_, i) => ({
...long,
key: `Short ${i}`,
})),
},
{
...nullDevice,
id: "a6c69587",
name: "device5",
metadata: Array.from({ length: 8 }, (_, i) =>
i % 2 === 0
? { ...short, key: `Short ${i}` }
: { ...long, key: `Long ${i}` },
),
},
{
...nullDevice,
id: "3af84e31",
name: "device6",
metadata: Array.from({ length: 8 }, (_, i) => ({
...reallyLong,
key: `Really long ${i}`,
})),
},
],
agentRow: getAgentRow,
},
};

function getAgentRow(agent: WorkspaceAgent): JSX.Element {
return (
<ProxyContext.Provider
value={{
proxyLatencies: MockProxyLatencies,
proxy: getPreferredProxy([], undefined),
proxies: [],
isLoading: false,
isFetched: true,
setProxy: () => {
return;
},
clearProxy: () => {
return;
},
refetchProxyLatencies: (): Date => {
return new Date();
},
}}
>
<AgentRow
showApps
key={agent.id}
agent={agent}
workspace={MockWorkspace}
serverVersion=""
onUpdateAgent={action("updateAgent")}
/>
</ProxyContext.Provider>
);
}
51 changes: 18 additions & 33 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,33 +718,11 @@ export const MockWorkspaceAgentOff: TypesGen.WorkspaceAgent = {
};

export const MockWorkspaceResource: TypesGen.WorkspaceResource = {
agents: [
MockWorkspaceAgent,
MockWorkspaceAgentConnecting,
MockWorkspaceAgentOutdated,
],
created_at: "",
id: "test-workspace-resource",
job_id: "",
name: "a-workspace-resource",
type: "google_compute_disk",
workspace_transition: "start",
hide: false,
icon: "",
metadata: [{ key: "api_key", value: "12345678", sensitive: true }],
daily_cost: 10,
};

export const MockWorkspaceResource2: TypesGen.WorkspaceResource = {
agents: [
MockWorkspaceAgent,
MockWorkspaceAgentDisconnected,
MockWorkspaceAgentOutdated,
],
agents: [MockWorkspaceAgent],
created_at: "",
id: "test-workspace-resource-2",
job_id: "",
name: "another-workspace-resource",
type: "google_compute_disk",
workspace_transition: "start",
hide: false,
Expand All @@ -753,22 +731,29 @@ export const MockWorkspaceResource2: TypesGen.WorkspaceResource = {
daily_cost: 10,
};

export const MockWorkspaceResource3: TypesGen.WorkspaceResource = {
export const MockWorkspaceResourceSensitive: TypesGen.WorkspaceResource = {
...MockWorkspaceResource,
id: "test-workspace-resource-sensitive",
name: "workspace-resource-sensitive",
metadata: [{ key: "api_key", value: "12345678", sensitive: true }],
};

export const MockWorkspaceResourceMultipleAgents: TypesGen.WorkspaceResource = {
...MockWorkspaceResource,
id: "test-workspace-resource-multiple-agents",
name: "workspace-resource-multiple-agents",
agents: [
MockWorkspaceAgent,
MockWorkspaceAgentDisconnected,
MockWorkspaceAgentOutdated,
],
created_at: "",
id: "test-workspace-resource-3",
job_id: "",
name: "another-workspace-resource",
type: "google_compute_disk",
workspace_transition: "start",
};

export const MockWorkspaceResourceHidden: TypesGen.WorkspaceResource = {
...MockWorkspaceResource,
id: "test-workspace-resource-hidden",
name: "workspace-resource-hidden",
hide: true,
icon: "",
metadata: [{ key: "size", value: "32GB", sensitive: false }],
daily_cost: 20,
};

export const MockWorkspaceAutostartDisabled: TypesGen.UpdateWorkspaceAutostartRequest =
Expand Down