Skip to content

Commit

Permalink
at least one environment check
Browse files Browse the repository at this point in the history
  • Loading branch information
lovincyrus committed Dec 6, 2024
1 parent c27f0e4 commit 7b623bb
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
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";
export let open = false;
Expand All @@ -45,6 +41,7 @@
let isProduction = false;
let isKeyAlreadyExists = false;
let inputErrors: { [key: number]: boolean } = {};
let showEnvironmentError = false;
$: organization = $page.params.organization;
$: project = $page.params.project;
Expand All @@ -55,7 +52,7 @@
initialEnvironment?.isDevelopment !== isDevelopment ||
initialEnvironment?.isProduction !== isProduction;
$: hasExistingKeys = Object.values(inputErrors).some((error) => error);
$: hasNoEnvironment = !isDevelopment && !isProduction;
$: hasNoEnvironment = showEnvironmentError && !isDevelopment && !isProduction;
const queryClient = useQueryClient();
const updateProjectVariables = createAdminServiceUpdateProjectVariables();
Expand Down Expand Up @@ -88,7 +85,7 @@
errors,
allErrors,
submitting,
reset,
reset: formReset,
} = superForm(defaults(initialValues, schema), {
// See: https://superforms.rocks/concepts/multiple-forms#setting-id-on-the-client
id: id,
Expand Down Expand Up @@ -201,11 +198,12 @@
}
function handleReset() {
reset();
formReset();
isDevelopment = false;
isProduction = false;
inputErrors = {};
isKeyAlreadyExists = false;
showEnvironmentError = false;
}
function checkForExistingKeys() {
Expand Down Expand Up @@ -248,9 +246,14 @@
}
function handleDialogOpen() {
handleReset();
setInitialCheckboxState();
}
function handleEnvironmentChange() {
showEnvironmentError = true;
}
onMount(() => {
handleDialogOpen();
});
Expand Down Expand Up @@ -292,11 +295,13 @@
bind:checked={isDevelopment}
id="development"
label="Development"
onCheckedChange={handleEnvironmentChange}
/>
<Checkbox
bind:checked={isProduction}
id="production"
label="Production"
onCheckedChange={handleEnvironmentChange}
/>
</div>
{#if hasNoEnvironment}
Expand Down

0 comments on commit 7b623bb

Please sign in to comment.