Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add links to the resource card for workspace applications (#2067)
* fix: Use proper webpack config for dev mode This was broken when improving the build times. The typechecker unfortunately missed it! * feat: Add links to the resource card for workspace applications Fixes #1907 and #805. I'll make this pretty in another PR! * Improve style
- Loading branch information
Showing
9 changed files
with
298 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Story } from "@storybook/react" | ||
import { MockWorkspace } from "../../testHelpers/renderHelpers" | ||
import { AppLink, AppLinkProps } from "./AppLink" | ||
|
||
export default { | ||
title: "components/AppLink", | ||
component: AppLink, | ||
} | ||
|
||
const Template: Story<AppLinkProps> = (args) => <AppLink {...args} /> | ||
|
||
export const WithIcon = Template.bind({}) | ||
WithIcon.args = { | ||
userName: "developer", | ||
workspaceName: MockWorkspace.name, | ||
appName: "code-server", | ||
appIcon: "/code.svg", | ||
} | ||
|
||
export const WithoutIcon = Template.bind({}) | ||
WithoutIcon.args = { | ||
userName: "developer", | ||
workspaceName: MockWorkspace.name, | ||
appName: "code-server", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Link from "@material-ui/core/Link" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import React, { FC } from "react" | ||
import * as TypesGen from "../../api/typesGenerated" | ||
import { combineClasses } from "../../util/combineClasses" | ||
|
||
export interface AppLinkProps { | ||
userName: TypesGen.User["username"] | ||
workspaceName: TypesGen.Workspace["name"] | ||
appName: TypesGen.WorkspaceApp["name"] | ||
appIcon: TypesGen.WorkspaceApp["icon"] | ||
} | ||
|
||
export const AppLink: FC<AppLinkProps> = ({ userName, workspaceName, appName, appIcon }) => { | ||
const styles = useStyles() | ||
const href = `/@${userName}/${workspaceName}/apps/${appName}` | ||
|
||
return ( | ||
<Link href={href} target="_blank" className={styles.link}> | ||
<img | ||
className={combineClasses([styles.icon, appIcon === "" ? "empty" : ""])} | ||
alt={`${appName} Icon`} | ||
src={appIcon || ""} | ||
/> | ||
{appName} | ||
</Link> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
link: { | ||
color: theme.palette.text.secondary, | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
|
||
icon: { | ||
width: 16, | ||
height: 16, | ||
marginRight: theme.spacing(1.5), | ||
|
||
// If no icon is provided we still want the padding on the left | ||
// to occur. | ||
"&.empty": { | ||
opacity: 0, | ||
}, | ||
}, | ||
})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
site/src/pages/WorkspaceAppErrorPage/WorkspaceAppErrorPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { FC, useMemo } from "react" | ||
import { useParams } from "react-router-dom" | ||
import { WorkspaceAppErrorPageView } from "./WorkspaceAppErrorPageView" | ||
|
||
const WorkspaceAppErrorView: FC = () => { | ||
const { app } = useParams() | ||
const message = useMemo(() => { | ||
const tag = document.getElementById("api-response") | ||
if (!tag) { | ||
throw new Error("dev error: api-response meta tag not found") | ||
} | ||
return tag.getAttribute("data-message") as string | ||
}, []) | ||
|
||
return <WorkspaceAppErrorPageView appName={app as string} message={message} /> | ||
} | ||
|
||
export default WorkspaceAppErrorView |
Oops, something went wrong.