mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Query and Policy Flow: SQL error in realtime (#3158)
This commit is contained in:
parent
2302606ca0
commit
cb4707cef0
3 changed files with 34 additions and 31 deletions
1
changes/issue-3141-sql-errors-show-in-realtime
Normal file
1
changes/issue-3141-sql-errors-show-in-realtime
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Query and Policy SQL errors showing on Save now show in realtime
|
||||
|
|
@ -107,6 +107,15 @@ const PolicyForm = ({
|
|||
|
||||
useEffect(() => {
|
||||
debounceCompatiblePlatforms(lastEditedQueryBody);
|
||||
|
||||
let valid = true;
|
||||
const { valid: isValidated, errors: newErrors } = validateQuerySQL(
|
||||
lastEditedQueryBody
|
||||
);
|
||||
valid = isValidated;
|
||||
setErrors({
|
||||
...newErrors,
|
||||
});
|
||||
}, [lastEditedQueryBody]);
|
||||
|
||||
const hasTeamMaintainerPermissions = isEditMode
|
||||
|
|
@ -136,7 +145,11 @@ const PolicyForm = ({
|
|||
});
|
||||
};
|
||||
|
||||
const handleSavePolicy = (forceNew = false) => (
|
||||
const onChangePolicy = (sqlString: string) => {
|
||||
setLastEditedQueryBody(sqlString);
|
||||
};
|
||||
|
||||
const promptSavePolicy = (forceNew = false) => (
|
||||
evt: React.MouseEvent<HTMLButtonElement>
|
||||
) => {
|
||||
evt.preventDefault();
|
||||
|
|
@ -149,15 +162,9 @@ const PolicyForm = ({
|
|||
}
|
||||
|
||||
let valid = true;
|
||||
const { valid: isValidated, errors: newErrors } = validateQuerySQL(
|
||||
lastEditedQueryBody
|
||||
);
|
||||
const { valid: isValidated } = validateQuerySQL(lastEditedQueryBody);
|
||||
|
||||
valid = isValidated;
|
||||
setErrors({
|
||||
...errors,
|
||||
...newErrors,
|
||||
});
|
||||
|
||||
if (valid) {
|
||||
if (!isEditMode || forceNew) {
|
||||
|
|
@ -168,15 +175,11 @@ const PolicyForm = ({
|
|||
description: lastEditedQueryDescription,
|
||||
query: lastEditedQueryBody,
|
||||
});
|
||||
|
||||
setErrors({});
|
||||
}
|
||||
|
||||
setIsEditingName(false);
|
||||
setIsEditingDescription(false);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const renderAuthor = (): JSX.Element | null => {
|
||||
|
|
@ -224,8 +227,6 @@ const PolicyForm = ({
|
|||
} else if (compatiblePlatforms[0] === "None") {
|
||||
return "No platforms (check your query for invalid tables or tables that are supported on different platforms)";
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const displayFormattedPlatforms = compatiblePlatforms.map((string) => {
|
||||
|
|
@ -424,10 +425,8 @@ const PolicyForm = ({
|
|||
name="query editor"
|
||||
onLoad={onLoad}
|
||||
wrapperClassName={`${baseClass}__text-editor-wrapper`}
|
||||
onChange={(sqlString: string) => {
|
||||
setLastEditedQueryBody(sqlString);
|
||||
}}
|
||||
handleSubmit={handleSavePolicy}
|
||||
onChange={onChangePolicy}
|
||||
handleSubmit={promptSavePolicy}
|
||||
/>
|
||||
{renderPlatformCompatibility()}
|
||||
{renderLiveQueryWarning()}
|
||||
|
|
@ -449,7 +448,7 @@ const PolicyForm = ({
|
|||
<Button
|
||||
className={`${baseClass}__save`}
|
||||
variant="brand"
|
||||
onClick={handleSavePolicy()}
|
||||
onClick={promptSavePolicy()}
|
||||
disabled={
|
||||
isAnyTeamMaintainerOrTeamAdmin &&
|
||||
!hasTeamMaintainerPermissions
|
||||
|
|
|
|||
|
|
@ -108,6 +108,15 @@ const QueryForm = ({
|
|||
|
||||
useEffect(() => {
|
||||
debounceCompatiblePlatforms(lastEditedQueryBody);
|
||||
|
||||
let valid = true;
|
||||
const { valid: isValidated, errors: newErrors } = validateQuerySQL(
|
||||
lastEditedQueryBody
|
||||
);
|
||||
valid = isValidated;
|
||||
setErrors({
|
||||
...newErrors,
|
||||
});
|
||||
}, [lastEditedQueryBody]);
|
||||
|
||||
const hasTeamMaintainerPermissions = isEditMode
|
||||
|
|
@ -137,6 +146,10 @@ const QueryForm = ({
|
|||
});
|
||||
};
|
||||
|
||||
const onChangeQuery = (sqlString: string) => {
|
||||
setLastEditedQueryBody(sqlString);
|
||||
};
|
||||
|
||||
const promptSaveQuery = (forceNew = false) => (
|
||||
evt: React.MouseEvent<HTMLButtonElement>
|
||||
) => {
|
||||
|
|
@ -150,15 +163,9 @@ const QueryForm = ({
|
|||
}
|
||||
|
||||
let valid = true;
|
||||
const { valid: isValidated, errors: newErrors } = validateQuerySQL(
|
||||
lastEditedQueryBody
|
||||
);
|
||||
const { valid: isValidated } = validateQuerySQL(lastEditedQueryBody);
|
||||
|
||||
valid = isValidated;
|
||||
setErrors({
|
||||
...errors,
|
||||
...newErrors,
|
||||
});
|
||||
|
||||
if (valid) {
|
||||
if (!isEditMode || forceNew) {
|
||||
|
|
@ -170,8 +177,6 @@ const QueryForm = ({
|
|||
query: lastEditedQueryBody,
|
||||
observer_can_run: lastEditedQueryObserverCanRun,
|
||||
});
|
||||
|
||||
setErrors({});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -432,9 +437,7 @@ const QueryForm = ({
|
|||
name="query editor"
|
||||
onLoad={onLoad}
|
||||
wrapperClassName={`${baseClass}__text-editor-wrapper`}
|
||||
onChange={(sqlString: string) => {
|
||||
setLastEditedQueryBody(sqlString);
|
||||
}}
|
||||
onChange={onChangeQuery}
|
||||
handleSubmit={promptSaveQuery}
|
||||
/>
|
||||
{renderPlatformCompatibility()}
|
||||
|
|
|
|||
Loading…
Reference in a new issue