-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from tgstation/MoreWorkCauseWhyNot
Setup Home Page
- Loading branch information
Showing
21 changed files
with
314 additions
and
32 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
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
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,82 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { HomeCardPermissionsQuery } from "./graphql/__generated__/HomeCardPermissionsQuery.graphql"; | ||
import HomeCardPermissions from "./graphql/HomeCardPermissions"; | ||
import Home from "./Home"; | ||
|
||
import { WithRelayParameters } from "@/../.storybook/MockRelayEnvironment"; | ||
import SessionContext from "@/context/session/SessionContext"; | ||
import { DefaultUserPasswordCredentials, UserPasswordCredentials } from "@/lib/Credentials"; | ||
|
||
interface IArgs { | ||
defaultCredentials: boolean; | ||
} | ||
|
||
const TestComponent = (props: IArgs) => { | ||
const session = { | ||
currentSession: { | ||
bearer: "asdf", | ||
userId: "fdsa", | ||
originalCredentials: props.defaultCredentials | ||
? new DefaultUserPasswordCredentials() | ||
: new UserPasswordCredentials("asdf", "asdf") | ||
}, | ||
setSession: () => {} | ||
}; | ||
|
||
return ( | ||
<SessionContext.Provider value={session}> | ||
<Home /> | ||
</SessionContext.Provider> | ||
); | ||
}; | ||
|
||
const CreateRelay = (fieldsEnabled: boolean): WithRelayParameters<HomeCardPermissionsQuery> => ({ | ||
query: HomeCardPermissions, | ||
mockResolvers: { | ||
PermissionSet: () => ({ | ||
administrationRights: { | ||
canChangeVersion: fieldsEnabled, | ||
canDownloadLogs: fieldsEnabled, | ||
canEditOwnPassword: fieldsEnabled, | ||
canReadUsers: fieldsEnabled, | ||
canUploadVersion: fieldsEnabled, | ||
canWriteUsers: fieldsEnabled | ||
}, | ||
instanceManagerRights: { | ||
canList: fieldsEnabled, | ||
canRead: fieldsEnabled | ||
} | ||
}) | ||
} | ||
}); | ||
|
||
const config: Meta<typeof TestComponent> = { | ||
component: TestComponent, | ||
title: "Routed/Home" | ||
}; | ||
|
||
export default config; | ||
|
||
type Story = StoryObj<typeof config>; | ||
|
||
export const Default: Story = { | ||
parameters: { | ||
relay: CreateRelay(true) | ||
} | ||
}; | ||
|
||
export const DisabledPerms: Story = { | ||
parameters: { | ||
relay: CreateRelay(false) | ||
} | ||
}; | ||
|
||
export const WithDefaultAdminPassword: Story = { | ||
args: { | ||
defaultCredentials: true | ||
}, | ||
parameters: { | ||
relay: CreateRelay(true) | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,5 +1,41 @@ | ||
import { FormattedMessage } from "react-intl"; | ||
import { useLazyLoadQuery } from "react-relay"; | ||
|
||
import { HomeCardPermissionsQuery } from "./graphql/__generated__/HomeCardPermissionsQuery.graphql"; | ||
import HomeCardPermissions from "./graphql/HomeCardPermissions"; | ||
import HomeCard from "./HomeCard/HomeCard"; | ||
import HomeRoutes from "./HomeRoutes"; | ||
|
||
import { Alert, AlertDescription } from "@/components/ui/alert"; | ||
import useSession from "@/context/session/useSession"; | ||
|
||
const Home = () => { | ||
return <></>; | ||
const session = useSession(); | ||
const usingDefaultCredentials = | ||
!!session.currentSession?.originalCredentials.defaultCredentials; | ||
|
||
const data = useLazyLoadQuery<HomeCardPermissionsQuery>(HomeCardPermissions, { | ||
userID: session.currentSession!.userId | ||
}); | ||
|
||
return ( | ||
<> | ||
{usingDefaultCredentials ? ( | ||
<Alert className="clearfix bg-warning mb-4"> | ||
<AlertDescription className="font-bold text-warning-foreground text-lg text-center"> | ||
<FormattedMessage id="error.app.default_creds" /> | ||
</AlertDescription> | ||
</Alert> | ||
) : null} | ||
<div className="flex flex-row flex-wrap justify-center"> | ||
{HomeRoutes.map(route => ( | ||
<div className="basis-full sm:basis-1/2 md:basis-1/3 lg:basis-1/4"> | ||
<HomeCard key={route.localeNameId} {...route} queryData={data} /> | ||
</div> | ||
))} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Home; |
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,29 @@ | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { FormattedMessage } from "react-intl"; | ||
import { Link } from "react-router-dom"; | ||
|
||
import IHomeCardProps from "./HomeCardProps"; | ||
|
||
import { Card, CardContent, CardFooter } from "@/components/ui/card"; | ||
|
||
const HomeCard = (props: IHomeCardProps) => { | ||
const enabled = props.calculateEnabled ? props.calculateEnabled(props.queryData) : true; | ||
const RenderCard = () => ( | ||
<Card | ||
className={enabled ? "text-primary hover:text-primary-foreground" : "text-destructive"}> | ||
<CardContent style={{ height: "245px" }} className="text-center border-0"> | ||
<FontAwesomeIcon className="w-4/5 h-4/5 mt-4 mb-4" icon={props.icon} /> | ||
<hr /> | ||
</CardContent> | ||
<CardFooter className={"justify-center font-bold text-lg" + (enabled ? "" : "italic")}> | ||
<FormattedMessage id={props.localeNameId} /> | ||
</CardFooter> | ||
</Card> | ||
); | ||
return ( | ||
<div className="m-4"> | ||
{enabled ? <Link to={props.path}>{RenderCard()}</Link> : RenderCard()} | ||
</div> | ||
); | ||
}; | ||
export default HomeCard; |
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,11 @@ | ||
import { IconProp } from "@fortawesome/fontawesome-svg-core"; | ||
|
||
import { HomeCardPermissionsQuery$data } from "../graphql/__generated__/HomeCardPermissionsQuery.graphql"; | ||
|
||
export default interface IHomeCardProps { | ||
icon: IconProp; | ||
localeNameId: string; | ||
path: string; | ||
calculateEnabled?: (data: HomeCardPermissionsQuery$data) => boolean | undefined; | ||
queryData: HomeCardPermissionsQuery$data; | ||
} |
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,83 @@ | ||
import { | ||
faCogs, | ||
faHdd, | ||
faInfoCircle, | ||
faKey, | ||
faTools, | ||
faUser | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import { lazy } from "react"; | ||
import { RouteObject } from "react-router-dom"; | ||
|
||
import HomeCardProps from "./HomeCard/HomeCardProps"; | ||
|
||
import NotFound from "@/components/core/NotFound/NotFound"; | ||
import devDelay from "@/lib/devDelay"; | ||
|
||
const Configuration = lazy( | ||
async () => | ||
await devDelay( | ||
() => import("@/components/routed/Configuration/Configuration"), | ||
"Component Load: Configuration" | ||
) | ||
); | ||
|
||
interface IHomeRouteProtected { | ||
unprotected?: boolean; | ||
} | ||
|
||
type HomeRoute = RouteObject & IHomeRouteProtected & Omit<HomeCardProps, "queryData">; | ||
|
||
const HomeRoutes: HomeRoute[] = [ | ||
{ | ||
path: "instances", | ||
icon: faHdd, | ||
localeNameId: "routes.instancelist", | ||
calculateEnabled: data => | ||
data.node?.effectivePermissionSet?.instanceManagerRights.canList || | ||
data.node?.effectivePermissionSet?.instanceManagerRights.canRead, | ||
element: <NotFound /> | ||
}, | ||
{ | ||
path: "users", | ||
icon: faUser, | ||
localeNameId: "routes.usermanager", | ||
calculateEnabled: data => | ||
data.node?.effectivePermissionSet?.administrationRights.canReadUsers || | ||
data.node?.effectivePermissionSet?.administrationRights.canWriteUsers, | ||
element: <NotFound /> | ||
}, | ||
{ | ||
path: "admin", | ||
icon: faTools, | ||
localeNameId: "routes.admin", | ||
calculateEnabled: data => | ||
data.node?.effectivePermissionSet?.administrationRights.canChangeVersion || | ||
data.node?.effectivePermissionSet?.administrationRights.canDownloadLogs || | ||
data.node?.effectivePermissionSet?.administrationRights.canUploadVersion, | ||
element: <NotFound /> | ||
}, | ||
{ | ||
path: "/users/passwd", | ||
icon: faKey, | ||
localeNameId: "routes.passwd", | ||
calculateEnabled: data => | ||
data.node?.effectivePermissionSet?.administrationRights.canEditOwnPassword, | ||
element: <NotFound /> | ||
}, | ||
{ | ||
path: "/config", | ||
icon: faCogs, | ||
localeNameId: "routes.config", | ||
element: <Configuration />, | ||
unprotected: true | ||
}, | ||
{ | ||
path: "/info", | ||
icon: faInfoCircle, | ||
localeNameId: "routes.info", | ||
element: <NotFound /> | ||
} | ||
]; | ||
|
||
export default HomeRoutes; |
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,26 @@ | ||
import { graphql } from "react-relay"; | ||
|
||
const HomeCardPermissions = graphql` | ||
query HomeCardPermissionsQuery($userID: ID!) { | ||
node(id: $userID) { | ||
... on User { | ||
effectivePermissionSet { | ||
administrationRights { | ||
canChangeVersion | ||
canDownloadLogs | ||
canUploadVersion | ||
canEditOwnPassword | ||
canReadUsers | ||
canWriteUsers | ||
} | ||
instanceManagerRights { | ||
canList | ||
canRead | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default HomeCardPermissions; |
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
Oops, something went wrong.