2022-05-04 19:10:19 +10:00
import { useAtom } from "jotai" ;
2022-03-07 19:13:22 +11:00
import { Stack , Typography , Grid , Tooltip , IconButton } from "@mui/material" ;
2022-02-28 21:41:46 +08:00
import SecretsIcon from "@mui/icons-material/VpnKeyOutlined" ;
import FunctionsIcon from "@mui/icons-material/CloudOutlined" ;
import DocsIcon from "@mui/icons-material/DescriptionOutlined" ;
2022-03-07 19:13:22 +11:00
2022-07-18 14:40:46 +10:00
import { projectScope , projectIdAtom } from "@src/atoms/projectScope" ;
2021-10-14 23:50:00 +11:00
2021-09-01 15:54:20 +10:00
export interface ICodeEditorHelperProps {
2021-09-01 15:59:30 +10:00
docLink : string ;
additionalVariables ? : {
key : string ;
description : string ;
} [ ] ;
2021-09-01 15:54:20 +10:00
}
export default function CodeEditorHelper ( {
2021-09-01 15:59:30 +10:00
docLink ,
additionalVariables ,
2021-09-01 15:54:20 +10:00
} : ICodeEditorHelperProps ) {
2022-07-18 14:40:46 +10:00
const [ projectId ] = useAtom ( projectIdAtom , projectScope ) ;
2022-05-04 19:10:19 +10:00
2021-09-01 15:59:30 +10:00
const availableVariables = [
{
key : "db" ,
description : ` db object provides access to firestore database instance of this project. giving you access to any collection or document in this firestore instance ` ,
} ,
{
key : "auth" ,
description : ` auth provides access to a firebase auth instance, can be used to manage auth users or generate tokens. ` ,
} ,
{
key : "storage" ,
description : ` firebase Storage can be accessed through this, storage.bucket() returns default storage bucket of the firebase project. ` ,
} ,
{
2022-03-06 14:57:54 +11:00
key : "rowy" ,
2022-09-28 23:25:25 +01:00
description : ` rowy provides a set of functions that are commonly used, such as easy file uploads & access to GCP Secret Manager ` ,
2021-09-01 15:59:30 +10:00
} ,
2022-11-22 03:04:26 +08:00
{
key : "logging" ,
description : ` logging.log is encouraged to replace console.log ` ,
} ,
2021-09-01 15:59:30 +10:00
] ;
2021-09-01 15:54:20 +10:00
2021-09-01 15:59:30 +10:00
return (
< Stack
direction = "row"
2022-03-07 19:13:22 +11:00
alignItems = "flex-start"
2022-02-28 21:41:46 +08:00
justifyItems = "space-between"
spacing = { 1 }
2021-09-01 15:59:30 +10:00
justifyContent = "space-between"
2021-10-14 23:50:00 +11:00
sx = { { my : 1 } }
2021-09-01 15:59:30 +10:00
>
2022-03-07 19:13:22 +11:00
< Typography variant = "body2" color = "textSecondary" >
2021-11-01 13:18:32 +11:00
Available :
2021-09-01 15:59:30 +10:00
< / Typography >
2021-09-01 15:54:20 +10:00
2022-03-07 19:13:22 +11:00
< Grid
container
spacing = { 1 }
style = { { flexGrow : 1 , marginTop : - 8 , marginLeft : 0 } }
>
2021-09-01 15:59:30 +10:00
{ availableVariables . concat ( additionalVariables ? ? [ ] ) . map ( ( v ) = > (
< Grid item key = { v . key } >
< Tooltip title = { v . description } >
2021-10-14 23:50:00 +11:00
< code > { v . key } < / code >
2021-09-01 15:59:30 +10:00
< / Tooltip >
< / Grid >
) ) }
< / Grid >
2022-03-07 19:13:22 +11:00
< Stack
direction = "row"
alignItems = "center"
spacing = { 1 }
style = { { marginTop : - 4 } }
>
< Tooltip title = "Secret Manager ↗" >
2022-02-28 21:41:46 +08:00
< IconButton
size = "small"
color = "primary"
target = "_blank"
rel = "noopener noreferrer"
href = { ` https://console.cloud.google.com/security/secret-manager?project= ${ projectId } ` }
>
2022-03-07 19:13:22 +11:00
< SecretsIcon fontSize = "small" / >
2022-02-28 21:41:46 +08:00
< / IconButton >
< / Tooltip >
2022-03-07 19:13:22 +11:00
< Tooltip title = "Configure Cloud Function ↗" >
2022-02-28 21:41:46 +08:00
< IconButton
size = "small"
color = "primary"
target = "_blank"
rel = "noopener noreferrer"
2022-03-08 00:32:56 +08:00
href = { ` https://console.cloud.google.com/functions/list?project= ${ projectId } ` }
2022-02-28 21:41:46 +08:00
>
2022-03-07 19:13:22 +11:00
< FunctionsIcon fontSize = "small" / >
2022-02-28 21:41:46 +08:00
< / IconButton >
< / Tooltip >
2022-03-07 19:13:22 +11:00
< Tooltip title = "Examples & documentation ↗" >
2022-02-28 21:41:46 +08:00
< IconButton
size = "small"
color = "primary"
target = "_blank"
rel = "noopener noreferrer"
href = { docLink }
>
2022-03-07 19:13:22 +11:00
< DocsIcon fontSize = "small" / >
2022-02-28 21:41:46 +08:00
< / IconButton >
< / Tooltip >
2022-03-07 19:13:22 +11:00
< / Stack >
2021-09-01 15:59:30 +10:00
< / Stack >
) ;
2021-09-01 15:54:20 +10:00
}