From 8e55413cc091d99777a01a00d71dd2951e3607f4 Mon Sep 17 00:00:00 2001 From: RachelElysia Date: Fri, 15 Mar 2024 11:32:46 -0400 Subject: [PATCH 1/2] Fleet UI: Add reset results warning for modifying platform or min osquery version --- .../edit/components/EditQueryForm/EditQueryForm.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/pages/queries/edit/components/EditQueryForm/EditQueryForm.tsx b/frontend/pages/queries/edit/components/EditQueryForm/EditQueryForm.tsx index e6ac26e7c293..1fe019b7cec3 100644 --- a/frontend/pages/queries/edit/components/EditQueryForm/EditQueryForm.tsx +++ b/frontend/pages/queries/edit/components/EditQueryForm/EditQueryForm.tsx @@ -637,13 +637,24 @@ const EditQueryForm = ({ "differential", "differential_ignore_removals", ].includes(lastEditedQueryLoggingType); + // TODO: Account for equivalent platforms "linux,darwin" = "darwin,linux" + // TODO: Find out if "linux, darwin" is equivalent to "linux,darwin" and both work in backend + const changedPlatforms = + storedQuery && lastEditedQueryPlatforms !== 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; From 496f33e6eb119e55cd9fb94e2cdd54ac8c29bac9 Mon Sep 17 00:00:00 2001 From: RachelElysia Date: Tue, 19 Mar 2024 09:32:47 -0400 Subject: [PATCH 2/2] Reset warning accounts for combination not permutation --- .../components/EditQueryForm/EditQueryForm.tsx | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/frontend/pages/queries/edit/components/EditQueryForm/EditQueryForm.tsx b/frontend/pages/queries/edit/components/EditQueryForm/EditQueryForm.tsx index 1fe019b7cec3..5fc45797b833 100644 --- a/frontend/pages/queries/edit/components/EditQueryForm/EditQueryForm.tsx +++ b/frontend/pages/queries/edit/components/EditQueryForm/EditQueryForm.tsx @@ -637,10 +637,19 @@ const EditQueryForm = ({ "differential", "differential_ignore_removals", ].includes(lastEditedQueryLoggingType); - // TODO: Account for equivalent platforms "linux,darwin" = "darwin,linux" - // TODO: Find out if "linux, darwin" is equivalent to "linux,darwin" and both work in backend + + // Note: The backend is not resetting the query reports with equivalent platform strings + // 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 && lastEditedQueryPlatforms !== storedQuery.platform; + storedQuery && + formatPlatformEquivalences(lastEditedQueryPlatforms) !== + formatPlatformEquivalences(storedQuery?.platform); + const changedMinOsqueryVersion = storedQuery && lastEditedQueryMinOsqueryVersion !== storedQuery.min_osquery_version; @@ -671,6 +680,7 @@ const EditQueryForm = ({ const disableSaveFormErrors = (lastEditedQueryName === "" && !!lastEditedQueryId) || !!size(errors); + console.log("lastEditedQueryPlatforms", lastEditedQueryPlatforms); return ( <>
@@ -735,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."