Skip to content

Commit da75a16

Browse files
committed
fix(webapp): address secret env var review feedback
1 parent 8c97d18 commit da75a16

3 files changed

Lines changed: 46 additions & 5 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: feature
4+
---
5+
6+
Existing environment variables can now be permanently marked as secret from the dashboard.

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables/route.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ import {
2020
import { json } from "@remix-run/server-runtime";
2121
import { useVirtualizer } from "@tanstack/react-virtual";
2222
import { fromPromise } from "neverthrow";
23-
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type RefObject } from "react";
23+
import {
24+
useEffect,
25+
useLayoutEffect,
26+
useMemo,
27+
useRef,
28+
useState,
29+
type FormEvent,
30+
type RefObject,
31+
} from "react";
2432
import { typedjson, useTypedLoaderData } from "remix-typedjson";
2533
import { z } from "zod";
2634
import { UserAvatar } from "~/components/UserProfilePhoto";
@@ -815,6 +823,26 @@ function EditEnvironmentVariablePanel({
815823

816824
const isLoading = fetcher.state !== "idle";
817825

826+
function handleOpenChange(open: boolean) {
827+
if (open) {
828+
setIsSecret(variable.isSecret);
829+
}
830+
831+
setIsOpen(open);
832+
}
833+
834+
function handleSubmit(event: FormEvent<HTMLFormElement>) {
835+
if (
836+
isSecret &&
837+
!variable.isSecret &&
838+
!window.confirm(
839+
"Making this variable secret is irreversible. The value will be hidden and cannot be revealed again. Continue?"
840+
)
841+
) {
842+
event.preventDefault();
843+
}
844+
}
845+
818846
// Close dialog on successful submission
819847
useEffect(() => {
820848
if (lastSubmission?.success && fetcher.state === "idle") {
@@ -834,13 +862,13 @@ function EditEnvironmentVariablePanel({
834862
});
835863

836864
return (
837-
<Dialog open={isOpen} onOpenChange={setIsOpen}>
865+
<Dialog open={isOpen} onOpenChange={handleOpenChange}>
838866
<DialogTrigger asChild>
839867
<Button variant="small-menu-item" LeadingIcon={PencilSquareIcon} fullWidth textAlignLeft />
840868
</DialogTrigger>
841869
<DialogContent>
842870
<DialogHeader>Edit environment variable</DialogHeader>
843-
<fetcher.Form method="post" {...getFormProps(form)}>
871+
<fetcher.Form method="post" {...getFormProps(form)} onSubmit={handleSubmit}>
844872
<input type="hidden" name="action" value="edit" />
845873
<input type="hidden" name="isSecret" value={isSecret ? "true" : "false"} />
846874
<input {...getInputProps(id, { type: "hidden" })} value={variable.id} />
@@ -898,7 +926,11 @@ function EditEnvironmentVariablePanel({
898926
</Button>
899927
}
900928
cancelButton={
901-
<Button onClick={() => setIsOpen(false)} variant="tertiary/medium" type="button">
929+
<Button
930+
onClick={() => handleOpenChange(false)}
931+
variant="tertiary/medium"
932+
type="button"
933+
>
902934
Cancel
903935
</Button>
904936
}

apps/webapp/app/v3/environmentVariables/repository.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ export const EditEnvironmentVariableValue = z.object({
6969
environmentId: z.string(),
7070
value: z.string(),
7171
lastUpdatedBy: EnvironmentVariableUpdaterSchema.optional(),
72-
isSecret: z.preprocess((val) => val === "true" || val === true, z.boolean()).optional(),
72+
isSecret: z.preprocess(
73+
(val) => (val === undefined ? undefined : val === "true" || val === true),
74+
z.boolean().optional()
75+
),
7376
});
7477
export type EditEnvironmentVariableValue = z.infer<typeof EditEnvironmentVariableValue>;
7578

0 commit comments

Comments
 (0)