-
Notifications
You must be signed in to change notification settings - Fork 471
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
UI - use new db user settings to persist user's host table column preferences #25185
Changes from 14 commits
a2131f0
64eb475
a7f2517
d753685
1476bee
525de5d
07f8b70
ec05dff
4e54144
6b4ed21
7aaadec
b1d4af6
cd8e467
91d60a4
8906ba2
8b24f56
4116122
472498b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Implement user-level settings, use them to persist a user's selection of which columns to display | ||
on the hosts table. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,9 @@ import { RouteProps } from "react-router/lib/Route"; | |
import { find, isEmpty, isEqual, omit } from "lodash"; | ||
import { format } from "date-fns"; | ||
import FileSaver from "file-saver"; | ||
import classNames from "classnames"; | ||
|
||
import enrollSecretsAPI from "services/entities/enroll_secret"; | ||
import usersAPI from "services/entities/users"; | ||
import labelsAPI, { ILabelsResponse } from "services/entities/labels"; | ||
import teamsAPI, { ILoadTeamsResponse } from "services/entities/teams"; | ||
import globalPoliciesAPI from "services/entities/global_policies"; | ||
|
@@ -46,7 +46,6 @@ import { | |
IEnrollSecret, | ||
IEnrollSecretsResponse, | ||
} from "interfaces/enroll_secret"; | ||
import { getErrorReason } from "interfaces/errors"; | ||
import { ILabel } from "interfaces/label"; | ||
import { IOperatingSystemVersion } from "interfaces/operating_system"; | ||
import { IPolicy, IStoredPolicyResponse } from "interfaces/policy"; | ||
|
@@ -143,6 +142,7 @@ const ManageHostsPage = ({ | |
isPremiumTier, | ||
isFreeTier, | ||
isSandboxMode, | ||
userSettings, | ||
setFilteredHostsPath, | ||
setFilteredPoliciesPath, | ||
setFilteredQueriesPath, | ||
|
@@ -175,11 +175,6 @@ const ManageHostsPage = ({ | |
}, | ||
}); | ||
|
||
const hostHiddenColumns = localStorage.getItem("hostHiddenColumns"); | ||
const storedHiddenColumns = hostHiddenColumns | ||
? JSON.parse(hostHiddenColumns) | ||
: null; | ||
Comment on lines
-178
to
-181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit torn on this, as it means breaking existing functionality for users. I confirmed that we're not clearing localstorage on logout, so the columns do persist between sessions (just not between browsers, or in incognito mode). On the other hand we wouldn't want to support this forever as eventually everyone will be using the new strategy. If it sparks a riot we can put it back in a patch, but likely no one will notice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my thinking too. We could include fallback behavior to use local storage, but I don't really see the scenario where the user has logged in, is actively using Fleet, and suddenly the server is somehow unavailable for this specific functionality. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't think of it as fallback behavior as much as, people right now have their columns set up and they're going to disappear when this deploys. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aaah, I see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a UI migration 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, in this initial rollout, check for local storage settings, and if present, immediately send them to the server to persist and set them as current UI context, then down the line remove that code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (or not remove it I suppose, but there would be no reason for anything to present in local storage after not too long) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is probably the way. It seems a bit heavy handed but considering the original ask, we'd ideally like the user to see the columns they expect and then also see them in another browser / incognito mode, without having to do any action to trigger persistence. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds like a plan |
||
|
||
// Functions to avoid race conditions | ||
const initialSortBy: ISortOption[] = (() => { | ||
let key = DEFAULT_SORT_HEADER; | ||
|
@@ -212,7 +207,7 @@ const ManageHostsPage = ({ | |
const [showTransferHostModal, setShowTransferHostModal] = useState(false); | ||
const [showDeleteHostModal, setShowDeleteHostModal] = useState(false); | ||
const [hiddenColumns, setHiddenColumns] = useState<string[]>( | ||
storedHiddenColumns || defaultHiddenColumns | ||
userSettings?.hidden_host_columns || defaultHiddenColumns | ||
); | ||
const [selectedHostIds, setSelectedHostIds] = useState<number[]>([]); | ||
const [isAllMatchingHostsSelected, setIsAllMatchingHostsSelected] = useState( | ||
|
@@ -766,10 +761,23 @@ const ManageHostsPage = ({ | |
router.push(`${PATHS.EDIT_LABEL(parseInt(labelID, 10))}`); | ||
}; | ||
|
||
const onSaveColumns = (newHiddenColumns: string[]) => { | ||
localStorage.setItem("hostHiddenColumns", JSON.stringify(newHiddenColumns)); | ||
setHiddenColumns(newHiddenColumns); | ||
setShowEditColumnsModal(false); | ||
const onSaveColumns = async (newHiddenColumns: string[]) => { | ||
if (!currentUser) { | ||
return; | ||
} | ||
try { | ||
await usersAPI.update(currentUser.id, { | ||
settings: { hidden_host_columns: newHiddenColumns }, | ||
}); | ||
// No success renderFlash, to make column setting more seamless | ||
// only set state and close modal if server persist succeeds, keeping UI and server state in | ||
// sync. | ||
// Can also add local storage fallback behavior in next iteration if we want. | ||
setHiddenColumns(newHiddenColumns); | ||
setShowEditColumnsModal(false); | ||
} catch (response) { | ||
renderFlash("error", "Couldn't save column settings. Please try again."); | ||
} | ||
}; | ||
|
||
// NOTE: this is called once on initial render and every time the query changes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All changes in this file are cleanup, no logic updates