Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: display user apps in the workspaces table #17744

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
MockTemplate,
MockUserOwner,
MockWorkspace,
MockWorkspaceAgent,
MockWorkspaceAppStatus,
mockApiError,
} from "testHelpers/entities";
Expand Down Expand Up @@ -299,6 +300,42 @@ export const InvalidPageNumber: Story = {
},
};

export const MultipleApps: Story = {
args: {
workspaces: [
{
...MockWorkspace,
latest_build: {
...MockWorkspace.latest_build,
resources: [
{
...MockWorkspace.latest_build.resources[0],
agents: [
{
...MockWorkspaceAgent,
apps: [
{
...MockWorkspaceAgent.apps[0],
display_name: "App 1",
id: "app-1",
},
{
...MockWorkspaceAgent.apps[0],
display_name: "App 2",
id: "app-2",
},
],
},
],
},
],
},
},
],
count: allWorkspaces.length,
},
};

export const ShowOrganizations: Story = {
args: {
workspaces: [{ ...MockWorkspace, organization_name: "limbus-co" }],
Expand Down
69 changes: 58 additions & 11 deletions site/src/pages/WorkspacesPage/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Avatar } from "components/Avatar/Avatar";
import { AvatarData } from "components/Avatar/AvatarData";
import { AvatarDataSkeleton } from "components/Avatar/AvatarDataSkeleton";
import { Button } from "components/Button/Button";
import { ExternalImage } from "components/ExternalImage/ExternalImage";
import { VSCodeIcon } from "components/Icons/VSCodeIcon";
import { VSCodeInsidersIcon } from "components/Icons/VSCodeInsidersIcon";
import { InfoTooltip } from "components/InfoTooltip/InfoTooltip";
Expand Down Expand Up @@ -63,6 +64,7 @@ import {
getVSCodeHref,
openAppInNewWindow,
} from "modules/apps/apps";
import { useAppLink } from "modules/apps/useAppLink";
import { useDashboard } from "modules/dashboard/useDashboard";
import { WorkspaceAppStatus } from "modules/workspaces/WorkspaceAppStatus/WorkspaceAppStatus";
import { WorkspaceDormantBadge } from "modules/workspaces/WorkspaceDormantBadge/WorkspaceDormantBadge";
Expand Down Expand Up @@ -622,6 +624,9 @@ const PrimaryAction: FC<PrimaryActionProps> = ({
);
};

// The total number of apps that can be displayed in the workspace row
const WORKSPACE_APPS_SLOTS = 4;
Copy link
Member

Choose a reason for hiding this comment

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

perhaps create a storybook to express this use case?


type WorkspaceAppsProps = {
workspace: Workspace;
};
Expand All @@ -647,11 +652,18 @@ const WorkspaceApps: FC<WorkspaceAppsProps> = ({ workspace }) => {
return null;
}

const builtinApps = new Set(agent.display_apps);
builtinApps.delete("port_forwarding_helper");
builtinApps.delete("ssh_helper");

const remainingSlots = WORKSPACE_APPS_SLOTS - builtinApps.size;
const userApps = agent.apps.slice(0, remainingSlots);

const buttons: ReactNode[] = [];

if (agent.display_apps.includes("vscode")) {
if (builtinApps.has("vscode")) {
buttons.push(
<AppLink
<BaseIconLink
key="vscode"
isLoading={!token}
label="Open VSCode"
Expand All @@ -664,13 +676,13 @@ const WorkspaceApps: FC<WorkspaceAppsProps> = ({ workspace }) => {
})}
>
<VSCodeIcon />
</AppLink>,
</BaseIconLink>,
);
}

if (agent.display_apps.includes("vscode_insiders")) {
if (builtinApps.has("vscode_insiders")) {
buttons.push(
<AppLink
<BaseIconLink
key="vscode-insiders"
label="Open VSCode Insiders"
isLoading={!token}
Expand All @@ -683,18 +695,29 @@ const WorkspaceApps: FC<WorkspaceAppsProps> = ({ workspace }) => {
})}
>
<VSCodeInsidersIcon />
</AppLink>,
</BaseIconLink>,
);
}

if (agent.display_apps.includes("web_terminal")) {
for (const app of userApps) {
buttons.push(
<IconAppLink
key={app.id}
app={app}
workspace={workspace}
agent={agent}
/>,
);
}

if (builtinApps.has("web_terminal")) {
const href = getTerminalHref({
username: workspace.owner_name,
workspace: workspace.name,
agent: agent.name,
});
buttons.push(
<AppLink
<BaseIconLink
key="terminal"
href={href}
onClick={(e) => {
Expand All @@ -704,21 +727,45 @@ const WorkspaceApps: FC<WorkspaceAppsProps> = ({ workspace }) => {
label="Open Terminal"
>
<SquareTerminalIcon />
</AppLink>,
</BaseIconLink>,
);
}

return buttons;
};

type AppLinkProps = PropsWithChildren<{
type IconAppLinkProps = {
app: WorkspaceApp;
workspace: Workspace;
agent: WorkspaceAgent;
};

const IconAppLink: FC<IconAppLinkProps> = ({ app, workspace, agent }) => {
const link = useAppLink(app, {
workspace,
agent,
});

return (
<BaseIconLink
key={app.id}
label={`Open ${link.label}`}
href={link.href}
onClick={link.onClick}
>
<ExternalImage src={app.icon ?? "/icon/widgets.svg"} />
</BaseIconLink>
);
};

type BaseIconLinkProps = PropsWithChildren<{
label: string;
href: string;
isLoading?: boolean;
onClick?: (e: React.MouseEvent<HTMLAnchorElement>) => void;
}>;

const AppLink: FC<AppLinkProps> = ({
const BaseIconLink: FC<BaseIconLinkProps> = ({
href,
isLoading,
label,
Expand Down
7 changes: 0 additions & 7 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,17 +896,10 @@ export const MockWorkspaceApp: TypesGen.WorkspaceApp = {
id: "test-app",
slug: "test-app",
display_name: "Test App",
icon: "",
subdomain: false,
health: "disabled",
external: false,
url: "",
sharing_level: "owner",
healthcheck: {
url: "",
interval: 0,
threshold: 0,
},
hidden: false,
open_in: "slim-window",
statuses: [],
Expand Down
Loading