Variables
@@ -378,17 +401,18 @@
on:click={() => {
open = false;
handleReset();
- }}>Cancel
+ Cancel
+
+ Create
+
diff --git a/web-admin/src/features/projects/environment-variables/EditDialog.svelte b/web-admin/src/features/projects/environment-variables/EditDialog.svelte
index f6c1f662021..50ccf108f1a 100644
--- a/web-admin/src/features/projects/environment-variables/EditDialog.svelte
+++ b/web-admin/src/features/projects/environment-variables/EditDialog.svelte
@@ -23,11 +23,9 @@
import { object, string } from "yup";
import { EnvironmentType, type VariableNames } from "./types";
import Input from "@rilldata/web-common/components/forms/Input.svelte";
- import {
- getCurrentEnvironment,
- getEnvironmentType,
- isDuplicateKey,
- } from "./utils";
+ import { getCurrentEnvironment, isDuplicateKey } from "./utils";
+ import { onMount } from "svelte";
+ import { debounce } from "lodash";
export let open = false;
export let id: string;
@@ -40,21 +38,22 @@
isDevelopment: boolean;
isProduction: boolean;
};
- let isDevelopment: boolean;
- let isProduction: boolean;
+ let isDevelopment = false;
+ let isProduction = false;
let isKeyAlreadyExists = false;
let inputErrors: { [key: number]: boolean } = {};
+ let showEnvironmentError = false;
$: organization = $page.params.organization;
$: project = $page.params.project;
- $: isEnvironmentSelected = isDevelopment || isProduction;
$: hasNewChanges =
$form.key !== initialValues.key ||
$form.value !== initialValues.value ||
initialEnvironment?.isDevelopment !== isDevelopment ||
initialEnvironment?.isProduction !== isProduction;
$: hasExistingKeys = Object.values(inputErrors).some((error) => error);
+ $: hasNoEnvironment = showEnvironmentError && !isDevelopment && !isProduction;
const queryClient = useQueryClient();
const updateProjectVariables = createAdminServiceUpdateProjectVariables();
@@ -79,40 +78,32 @@
}),
);
- const {
- form,
- enhance,
- formId,
- submit,
- errors,
- allErrors,
- submitting,
- reset,
- } = superForm(defaults(initialValues, schema), {
- // See: https://superforms.rocks/concepts/multiple-forms#setting-id-on-the-client
- id: id,
- SPA: true,
- validators: schema,
- async onUpdate({ form }) {
- if (!form.valid) return;
- const values = form.data;
-
- checkForExistingKeys();
- if (isKeyAlreadyExists) return;
-
- const flatVariable = {
- [values.key]: values.value,
- };
-
- try {
- await handleUpdateProjectVariables(flatVariable);
- open = false;
- handleReset();
- } catch (error) {
- console.error(error);
- }
- },
- });
+ const { form, enhance, formId, submit, errors, allErrors, submitting } =
+ superForm(defaults(initialValues, schema), {
+ id: id,
+ SPA: true,
+ validators: schema,
+ resetForm: false,
+ async onUpdate({ form }) {
+ if (!form.valid) return;
+ const values = form.data;
+
+ checkForExistingKeys();
+ if (isKeyAlreadyExists) return;
+
+ const flatVariable = {
+ [values.key]: values.value,
+ };
+
+ try {
+ await handleUpdateProjectVariables(flatVariable);
+ open = false;
+ handleReset();
+ } catch (error) {
+ console.error(error);
+ }
+ },
+ });
async function handleUpdateProjectVariables(
flatVariable: AdminServiceUpdateProjectVariablesBodyVariables,
@@ -200,28 +191,30 @@
}
function handleReset() {
- reset();
+ $form.environment = initialValues.environment;
+ $form.key = initialValues.key;
+ $form.value = initialValues.value;
isDevelopment = false;
isProduction = false;
inputErrors = {};
isKeyAlreadyExists = false;
+ showEnvironmentError = false;
}
function checkForExistingKeys() {
inputErrors = {};
isKeyAlreadyExists = false;
- const existingKey = {
- environment: getEnvironmentType(
- getCurrentEnvironment(isDevelopment, isProduction),
- ),
- name: $form.key,
- };
-
- const variableEnvironment = existingKey.environment;
- const variableKey = existingKey.name;
+ const newEnvironment = getCurrentEnvironment(isDevelopment, isProduction);
- if (isDuplicateKey(variableEnvironment, variableKey, variableNames)) {
+ if (
+ isDuplicateKey(
+ newEnvironment,
+ $form.key,
+ variableNames,
+ initialValues.key,
+ )
+ ) {
inputErrors[0] = true;
isKeyAlreadyExists = true;
}
@@ -240,19 +233,37 @@
isDevelopment = true;
isProduction = true;
}
- }
- function handleDialogOpen() {
- setInitialCheckboxState();
initialEnvironment = {
isDevelopment,
isProduction,
};
}
+ function handleDialogOpen() {
+ handleReset();
+ setInitialCheckboxState();
+ }
+
+ function handleEnvironmentChange() {
+ showEnvironmentError = true;
+ }
+
+ onMount(() => {
+ handleDialogOpen();
+ });
+
$: if (open) {
handleDialogOpen();
}
+
+ const debouncedCheckForExistingKeys = debounce(() => {
+ checkForExistingKeys();
+ }, 500);
+
+ $: if ($form.key) {
+ debouncedCheckForExistingKeys();
+ }
+ {#if hasNoEnvironment}
+
Variable
@@ -349,11 +369,12 @@
form={$formId}
disabled={$submitting ||
!hasNewChanges ||
- !isEnvironmentSelected ||
hasExistingKeys ||
- $allErrors.length > 0}
- submitForm>Edit
+ Edit
+
diff --git a/web-admin/src/features/projects/environment-variables/EnvironmentVariablesTable.svelte b/web-admin/src/features/projects/environment-variables/EnvironmentVariablesTable.svelte
index e896e6d9222..34bfbcb1996 100644
--- a/web-admin/src/features/projects/environment-variables/EnvironmentVariablesTable.svelte
+++ b/web-admin/src/features/projects/environment-variables/EnvironmentVariablesTable.svelte
@@ -42,7 +42,6 @@
{
header: "Activity",
accessorFn: (row) => row.createdOn,
- enableSorting: false,
cell: ({ row }) => {
return flexRender(ActivityCell, {
updatedOn: row.original.updatedOn,
diff --git a/web-admin/src/features/projects/environment-variables/ValueCell.svelte b/web-admin/src/features/projects/environment-variables/ValueCell.svelte
index b37f8cf0284..3c9a1267e4a 100644
--- a/web-admin/src/features/projects/environment-variables/ValueCell.svelte
+++ b/web-admin/src/features/projects/environment-variables/ValueCell.svelte
@@ -1,8 +1,10 @@
+
diff --git a/web-common/src/components/icons/EyeInvisible.svelte b/web-common/src/components/icons/EyeInvisible.svelte
index 649cfb79c61..fe3f60f59ad 100644
--- a/web-common/src/components/icons/EyeInvisible.svelte
+++ b/web-common/src/components/icons/EyeInvisible.svelte
@@ -1,16 +1,21 @@
+
+
diff --git a/web-common/src/components/table/BasicTable.svelte b/web-common/src/components/table/BasicTable.svelte
index 664606bbe23..9c7056df558 100644
--- a/web-common/src/components/table/BasicTable.svelte
+++ b/web-common/src/components/table/BasicTable.svelte
@@ -81,7 +81,7 @@
style={`margin-left: ${marginLeft};`}
class:cursor-pointer={header.column.getCanSort()}
class:select-none={header.column.getCanSort()}
- class="font-semibold text-gray-500 flex flex-row items-center gap-x-1 truncate"
+ class="font-semibold text-gray-500 flex flex-row items-center gap-x-1 truncate text-sm"
>