Skip to content
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

fix: correct function env settings #1065

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 37 additions & 29 deletions packages/dashboard/lib/pages/function/FunctionSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,22 +390,30 @@ const FunctionSettings = ({ func, refetch }: FunctionSettingsProps) => {
initialValues={{
env: func?.env || {},
}}
onSubmit={async ({ env }) => {
onSubmit={async ({ env, envKey, envValue }) => {
if (!func) {
return;
}

const newEnv = Object.entries<string>(env).reduce(
(acc, [key, value]) => [...acc, { key, value }],
[] as { key: string; value: string }[],
);

if (envKey && envValue) {
newEnv.push({ key: envKey, value: envValue });
}

await updateFunction.mutateAsync({
functionId: func.id,
env: Object.entries<string>(env).reduce(
(acc, [key, value]) => [...acc, { key, value }],
[] as { key: string; value: string }[],
),
env: newEnv,
});
}}
onSubmitSuccess={async () => {
onSubmitSuccess={async (_, form) => {
toast.success('Function environment variables updated successfully.');
await refetch();
form.change('envKey', '');
form.change('envValue', '');
}}
>
{({ values, form }) => (
Expand All @@ -421,6 +429,29 @@ const FunctionSettings = ({ func, refetch }: FunctionSettingsProps) => {
}
>
<div className="flex flex-col items-start gap-4">
{Object.entries<string>(values.env).map(([key, value], index) => {
return (
<div
key={`${key}-${value}-${index}`}
className="flex flex-col items-start gap-2 md:flex-row md:items-center"
>
<Input name={`${key}-key`} placeholder={key} disabled />
<Input name={`${key}-value`} placeholder={new Array(value.length).fill('*').join('')} disabled />
<Button
disabled={updateFunction.isLoading}
variant="danger"
onClick={() => {
const newEnv = { ...values.env };
delete newEnv[key];

form.change('env', newEnv);
}}
>
{t('env.remove')}
</Button>
</div>
);
})}
<div className="flex flex-col items-start gap-2 md:flex-row md:items-center">
<Input
name="envKey"
Expand Down Expand Up @@ -473,29 +504,6 @@ const FunctionSettings = ({ func, refetch }: FunctionSettingsProps) => {
{t('env.add')}
</Button>
</div>
{Object.entries<string>(values.env).map(([key, value], index) => {
return (
<div
key={`${key}-${value}-${index}`}
className="flex flex-col items-start gap-2 md:flex-row md:items-center"
>
<Input name={`${key}-key`} placeholder={key} disabled />
<Input name={`${key}-value`} placeholder={new Array(value.length).fill('*').join('')} disabled />
<Button
disabled={updateFunction.isLoading}
variant="danger"
onClick={() => {
const newEnv = { ...values.env };
delete newEnv[key];

form.change('env', newEnv);
}}
>
{t('env.remove')}
</Button>
</div>
);
})}
<Button variant="primary" disabled={updateFunction.isLoading} submit>
{t('env.submit')}
</Button>
Expand Down
Loading