Skip to content

Commit f91a118

Browse files
committed
Fix for dev env vars getting deleted when another user edits theirs
1 parent 9971de6 commit f91a118

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

apps/webapp/app/presenters/v3/EnvironmentVariablesPresenter.server.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,26 +78,11 @@ export class EnvironmentVariablesPresenter {
7878
where: {
7979
project: {
8080
slug: projectSlug,
81-
},
82-
OR: [
83-
{
84-
type: {
85-
in: ["PREVIEW", "STAGING", "PRODUCTION"],
86-
},
87-
},
88-
{
89-
type: "DEVELOPMENT",
90-
orgMember: {
91-
userId,
92-
},
93-
},
94-
],
81+
}
9582
},
9683
});
9784

98-
const sortedEnvironments = sortEnvironments(environments).filter(
99-
(e) => e.orgMember?.userId === userId || e.orgMember === null
100-
);
85+
const sortedEnvironments = sortEnvironments(environments);
10186

10287
const repository = new EnvironmentVariablesRepository(this.#prismaClient);
10388
const variables = await repository.getProject(project.id);
@@ -119,7 +104,9 @@ export class EnvironmentVariablesPresenter {
119104
}, {} as Record<string, { value: string | undefined; environment: { type: string; id: string } }>),
120105
};
121106
}),
122-
environments: sortedEnvironments.map((environment) => ({
107+
environments: sortedEnvironments.filter(
108+
(e) => e.orgMember?.userId === userId || e.orgMember === null
109+
).map((environment) => ({
123110
id: environment.id,
124111
type: environment.type,
125112
})),

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ function EditEnvironmentVariablePanel({
301301
const lastSubmission = useActionData();
302302
const navigation = useNavigation();
303303

304+
const hiddenValues = Object.values(variable.values).filter((value) => !environments.map(e => e.id).includes(value.environment.id));
305+
304306
const isLoading =
305307
navigation.state !== "idle" &&
306308
navigation.formMethod === "post" &&
@@ -336,6 +338,12 @@ function EditEnvironmentVariablePanel({
336338
<input type="hidden" name="action" value="edit" />
337339
<input type="hidden" name="id" value={variable.id} />
338340
<input type="hidden" name="key" value={variable.key} />
341+
{hiddenValues.map((value, index) => (
342+
<Fragment key={index}>
343+
<input type="hidden" name={`values[${index}].environmentId`} value={value.environment.id} />
344+
<input type="hidden" name={`values[${index}].value`} value={value.value} />
345+
</Fragment>
346+
))}
339347
<FormError id={id.errorId}>{id.error}</FormError>
340348
<Fieldset>
341349
<InputGroup fullWidth className="mb-5 mt-2">
@@ -351,6 +359,7 @@ function EditEnvironmentVariablePanel({
351359
<div className="grid grid-cols-[auto_1fr] gap-x-2 gap-y-2">
352360
{environments.map((environment, index) => {
353361
const value = variable.values[environment.id]?.value;
362+
index += hiddenValues.length;
354363
return (
355364
<Fragment key={environment.id}>
356365
<input

0 commit comments

Comments
 (0)