mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
Fleet UI: Fix package form preinstall sql to handle invalid sql as savable (#37283)
This commit is contained in:
parent
1b60a539d3
commit
fffafed67a
1 changed files with 20 additions and 7 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import React from "react";
|
||||
|
||||
// @ts-ignore
|
||||
import validateQuery from "components/forms/validators/validate_query";
|
||||
import { validateQuery } from "components/forms/validators/validate_query";
|
||||
|
||||
import { getExtensionFromFileName } from "utilities/file/fileUtils";
|
||||
import { IPackageFormData, IPackageFormValidation } from "./PackageForm";
|
||||
|
|
@ -35,16 +34,22 @@ const FORM_VALIDATION_CONFIG: Record<
|
|||
validations: [
|
||||
{
|
||||
name: "invalidQuery",
|
||||
isValid: (formData) => {
|
||||
// Allow all SQL including empty SQL: this field never blocks form submission Request: #35058
|
||||
isValid: () => true,
|
||||
message: (formData) => {
|
||||
const query = formData.preInstallQuery;
|
||||
return (
|
||||
query === undefined || query === "" || validateQuery(query).valid
|
||||
);
|
||||
if (!query) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const { error } = validateQuery(query);
|
||||
// Return error text (or empty string)
|
||||
return error || "";
|
||||
},
|
||||
message: (formData) => validateQuery(formData.preInstallQuery).error,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
installScript: {
|
||||
validations: [
|
||||
{
|
||||
|
|
@ -182,6 +187,14 @@ export const generateFormValidation = (formData: IPackageFormData) => {
|
|||
if (!failedValidation) {
|
||||
formValidation[objKey] = {
|
||||
isValid: true,
|
||||
// still compute error message for preInstallQuery since it can have warnings
|
||||
// of bad SQL but still allow form submission
|
||||
...(objKey === "preInstallQuery" && {
|
||||
message: getErrorMessage(
|
||||
formData,
|
||||
FORM_VALIDATION_CONFIG[objKey].validations[0].message
|
||||
),
|
||||
}),
|
||||
};
|
||||
} else {
|
||||
formValidation.isValid = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue