Skip to content

Commit

Permalink
fix: validate form
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-harris committed Oct 10, 2024
1 parent 1c6bce5 commit b87525d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions frontends/dashboard/src/pages/dataset/CrawlingSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { toTitleCase } from "../../analytics/utils/titleCase";
import { Spacer } from "../../components/Spacer";
import { UserContext } from "../../contexts/UserContext";
import { createToast } from "../../components/ShowToasts";
import { ValidateErrors, ValidateFn } from "../../utils/validation";
import { ErrorMsg, ValidateErrors, ValidateFn } from "../../utils/validation";
import { cn } from "shared/utils";

export const defaultCrawlOptions: CrawlOptions = {
Expand Down Expand Up @@ -201,6 +201,9 @@ export const validateFlatCrawlOptions: ValidateFn<FlatCrawlOptions> = (
if (!value.max_depth) {
errors.max_depth = "Max depth must be greater than 0";
}
if (value.type === "openapi" && !value.openapi_schema_url) {
errors.openapi_schema_url = "OpenAPI Schema URL is required";
}
if (
value.type == "openapi" &&
value.openapi_tag &&
Expand All @@ -219,7 +222,7 @@ export const validateFlatCrawlOptions: ValidateFn<FlatCrawlOptions> = (
const RealCrawlingSettings = (props: RealCrawlingSettingsProps) => {
const [options, setOptions] = createStore(props.initialCrawlingSettings);
const [errors, setErrors] = createStore<
ReturnType<ValidateFn<CrawlOptions>>["errors"]
ReturnType<ValidateFn<FlatCrawlOptions>>["errors"]
>({});

const isShopify = createMemo(() => options.type === "shopify");
Expand Down Expand Up @@ -383,6 +386,7 @@ const RealCrawlingSettings = (props: RealCrawlingSettingsProps) => {
}}
class="block w-full rounded border border-neutral-300 px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
/>
<ErrorMsg error={errors.openapi_schema_url} />
</div>
<div class="grow">
<label class="block" for="">
Expand Down

0 comments on commit b87525d

Please sign in to comment.