-
Notifications
You must be signed in to change notification settings - Fork 13
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
Server side env var interpolation #285
Open
roshan-gh
wants to merge
25
commits into
main
Choose a base branch
from
server-side-env-var-interpolation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
dd2cd88
feat: envVariables subMenu and editor decorations
ada9fa3
Merge branch 'main' of github.com:dash0hq/otelbin into server-side-en…
7a2dfcf
fix: sonarCloud issue
6b21d06
fix: envVar form style for Safari
53977a8
fix: envVar data
a7b7a63
fix: duplicate import
9b4ebbe
fix: editor decoration unstable, envVars conditions
22889f0
Merge branch 'main' of github.com:dash0hq/otelbin into server-side-en…
2167c40
fix: test for extractVariables, set empty string for multiple default…
2ba4505
fix: sonarCloud bug
bdb9876
fix: line number changes with different conditions of envVar and defa…
532dc4a
fix: refactor extractEnvData
d84fcab
Merge branch 'main' of github.com:dash0hq/otelbin into server-side-en…
e3cb552
fix: remove commented codes
2ab1f94
fix: refactor envVarState name, minor improvements
8c8866d
Merge branch 'main' of github.com:dash0hq/otelbin into server-side-en…
54e9ebc
fix: lines number and re-render bug
5b23261
fix: default values
fa9343c
Merge branch 'main' of github.com:dash0hq/otelbin into server-side-en…
e5a5f5f
fix: improve editor decorations
0e94c11
fix: various improvements and fix bugs
118cfb1
fix: decorations after paste
a9c4e92
fix: default value on create a new envVar
3bd85bd
fix: minor fix
4a86382
fix: improve handling empty values
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
src/lib/urlState/jsurl2.ts | ||
src/lib/urlState/jsurl2.ts | ||
src/components/textArea.tsx |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,158 @@ | ||
// SPDX-FileCopyrightText: 2023 Dash0 Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useEffect, useRef, useState } from "react"; | ||
import { useEnvVarMenu } from "~/contexts/EditorContext"; | ||
import { IconButton } from "./icon-button"; | ||
import { Check, X, XCircle } from "lucide-react"; | ||
import { Label } from "./label"; | ||
import { Textarea } from "./textArea"; | ||
import { useUrlState } from "~/lib/urlState/client/useUrlState"; | ||
import { envVarBinding } from "./validation/binding"; | ||
import React from "react"; | ||
|
||
export interface IEnvVar { | ||
name: string; | ||
linesNumber: number[]; | ||
value: string; | ||
} | ||
|
||
export default function EnvVarForm({ envVarData }: { envVarData: Record<string, IEnvVar> }) { | ||
const { openEnvVarMenu, setOpenEnvVarMenu } = useEnvVarMenu(); | ||
const [{ env }] = useUrlState([envVarBinding]); | ||
|
||
function handleClose() { | ||
setOpenEnvVarMenu(false); | ||
} | ||
|
||
const unboundVariables = Object.values(envVarData).filter((envVar) => env[envVar.name] === undefined); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
width: openEnvVarMenu ? `${400}px` : 0, | ||
maxWidth: openEnvVarMenu ? `${400}px` : 0, | ||
transition: "all 0.2s ease-in-out", | ||
}} | ||
className="shrink-0 bg-default shadow-none border-b-default border-r overflow-hidden overflow-y-auto" | ||
> | ||
<div className="w-[400px] flex flex-col h-full"> | ||
<div className="flex justify-between items-center px-4 pl-4 pr-1 py-[4.5px] shadow-none border-b-default border-b"> | ||
<div className="text-sm text-default"> | ||
<span | ||
style={{ | ||
color: unboundVariables.length > 0 ? "#F87171" : "#69F18E", | ||
}} | ||
> | ||
{unboundVariables.length} | ||
</span>{" "} | ||
{`${unboundVariables.length > 1 ? "variables" : "variable"} unbound`} | ||
</div> | ||
<IconButton onClick={handleClose} variant={"transparent"} size={"xs"}> | ||
<X height={12} /> | ||
</IconButton> | ||
</div> | ||
<div className="px-4"> | ||
{Object.values(envVarData).map((envVar) => ( | ||
<EnvVar key={envVar.name} envVar={envVar} /> | ||
))} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function EnvVar({ envVar }: { envVar: IEnvVar }) { | ||
const textAreaRef = useRef<HTMLTextAreaElement>(null); | ||
const [{ env }, getLink] = useUrlState([envVarBinding]); | ||
const [envVarValue, setEnvVarValue] = useState(env[envVar.name] ?? envVar.value); | ||
|
||
function handleEnvVarChange(event: React.ChangeEvent<HTMLTextAreaElement>) { | ||
setEnvVarValue(event.target.value); | ||
} | ||
|
||
function handleEnvVarSubmit() { | ||
if (typeof window !== "undefined") { | ||
window.history.pushState(null, "", getLink({ env: { ...env, [envVar.name]: envVarValue } })); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
if (textAreaRef.current) { | ||
textAreaRef.current.style.height = "0px"; | ||
const scrollHeight = textAreaRef.current.scrollHeight; | ||
textAreaRef.current.style.height = scrollHeight + "px"; | ||
} | ||
}, [envVarValue]); | ||
|
||
return ( | ||
<div className="flex flex-col gap-y-1 my-6"> | ||
<div className="grid w-full items-center gap-1.5 h-full"> | ||
<div className="flex gap-x-1 items-center"> | ||
<Label htmlFor="envVar">{envVar.name}</Label> | ||
{envVarValue === env[envVar.name] && <Check height={14} color={"#69F18E"} />} | ||
</div> | ||
<div className="relative"> | ||
<Textarea | ||
value={envVarValue} | ||
ref={textAreaRef} | ||
onChange={handleEnvVarChange} | ||
className="placeholder:italic h-[35px] min-h-[35px] max-h-[100px] overflow-hidden resize-none w-full pr-10" | ||
id="envVar" | ||
placeholder={env[envVar.name] === "" ? "empty" : "enter value"} | ||
/> | ||
{envVarValue === env[envVar.name] ? ( | ||
<IconButton | ||
onClick={() => { | ||
setEnvVarValue(""); | ||
}} | ||
variant={"transparent"} | ||
size={"xs"} | ||
className="absolute right-2 top-[6px] z-10" | ||
> | ||
<XCircle height={16} /> | ||
</IconButton> | ||
) : envVarValue !== env[envVar.name] ? ( | ||
<IconButton | ||
onClick={handleEnvVarSubmit} | ||
variant={"transparent"} | ||
size={"xs"} | ||
className="absolute right-2 top-[6px] z-10" | ||
> | ||
<Check height={16} /> | ||
</IconButton> | ||
) : !envVarValue ? ( | ||
<IconButton | ||
onClick={handleEnvVarSubmit} | ||
variant={"transparent"} | ||
size={"xs"} | ||
className="absolute right-2 top-[6px] z-10" | ||
> | ||
<Check height={16} /> | ||
</IconButton> | ||
) : ( | ||
<IconButton | ||
onClick={() => { | ||
setEnvVarValue(""); | ||
}} | ||
variant={"transparent"} | ||
size={"xs"} | ||
className="absolute right-2 top-[6px] z-10" | ||
> | ||
<XCircle height={16} /> | ||
</IconButton> | ||
)} | ||
</div> | ||
</div> | ||
<Label className="text-[12px] text-[#AFAFB2]" htmlFor="envVar"> | ||
{`Used ${envVar.linesNumber.length} ${envVar.linesNumber.length > 1 ? `times` : `time`} on line `} | ||
{envVar.linesNumber.map((lineNumber, index) => ( | ||
<React.Fragment key={lineNumber}> | ||
<span className="text-blue-400">{lineNumber}</span> | ||
{index < envVar.linesNumber.length - 1 ? ` and ` : ``} | ||
</React.Fragment> | ||
))} | ||
</Label> | ||
</div> | ||
); | ||
} |
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,22 @@ | ||
// SPDX-FileCopyrightText: 2023 Dash0 Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
"use client"; | ||
|
||
import * as React from "react"; | ||
import * as LabelPrimitive from "@radix-ui/react-label"; | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
|
||
import { cn } from "~/lib/utils"; | ||
|
||
const labelVariants = cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"); | ||
|
||
const Label = React.forwardRef< | ||
React.ElementRef<typeof LabelPrimitive.Root>, | ||
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & VariantProps<typeof labelVariants> | ||
>(({ className, ...props }, ref) => ( | ||
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} /> | ||
)); | ||
Label.displayName = LabelPrimitive.Root.displayName; | ||
|
||
export { Label }; |
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,24 @@ | ||
// SPDX-FileCopyrightText: 2023 Dash0 Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import * as React from "react"; | ||
|
||
import { cn } from "~/lib/utils"; | ||
|
||
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {} | ||
|
||
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(({ className, ...props }, ref) => { | ||
return ( | ||
<textarea | ||
className={cn( | ||
"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50", | ||
className | ||
)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
); | ||
}); | ||
Textarea.displayName = "Textarea"; | ||
|
||
export { Textarea }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The spec of the env var detection is here: #156