Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fleet UI: Add reset results warning for modifying platform or min osquery version #17663

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,32 @@ const EditQueryForm = ({
"differential_ignore_removals",
].includes(lastEditedQueryLoggingType);

// Note: The backend is not resetting the query reports with equivalent platform strings
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the best way I could think of to test equivalence, especially if we ever add new platforms. @jacobshandling would love your input on the naming of this equivalence checker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

// so we are not showing a warning unless the platform combinations differ
const formatPlatformEquivalences = (platforms?: string) => {
// Remove white spaces allowed by API and format into a sorted string converted from a sorted array
return platforms?.replace(/\s/g, "").split(",").sort().toString();
};

const changedPlatforms =
storedQuery &&
formatPlatformEquivalences(lastEditedQueryPlatforms) !==
formatPlatformEquivalences(storedQuery?.platform);

const changedMinOsqueryVersion =
storedQuery &&
lastEditedQueryMinOsqueryVersion !== storedQuery.min_osquery_version;

const enabledDiscardData =
storedQuery && lastEditedQueryDiscardData && !storedQuery.discard_data;

const confirmChanges =
currentlySavingQueryResults &&
(changedSQL || changedLoggingToDifferential || enabledDiscardData);
(changedSQL ||
changedLoggingToDifferential ||
enabledDiscardData ||
changedPlatforms ||
changedMinOsqueryVersion);

const showChangedSQLCopy =
changedSQL && !changedLoggingToDifferential && !enabledDiscardData;
Expand All @@ -660,6 +680,7 @@ const EditQueryForm = ({
const disableSaveFormErrors =
(lastEditedQueryName === "" && !!lastEditedQueryId) || !!size(errors);

console.log("lastEditedQueryPlatforms", lastEditedQueryPlatforms);
return (
<>
<form className={`${baseClass}`} autoComplete="off">
Expand Down Expand Up @@ -724,7 +745,7 @@ const EditQueryForm = ({
placeholder="Select"
label="Platform"
onChange={onChangeSelectPlatformOptions}
value={lastEditedQueryPlatforms}
value={lastEditedQueryPlatforms.replace(/\s/g, "")} // NOTE: FE requires no whitespace to render UI
multi
wrapperClassName={`${baseClass}__form-field form-field--platform`}
helpText="By default, your query collects data on all compatible platforms."
Expand Down
Loading