-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(admin): show recently impersonated users in admin panel #5750
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
Merged
+217
−140
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f2a165
feat(admin): show recently impersonated users in admin panel
TheodoreSpeaks 39a46b9
improvement(admin): align user table with settings list idiom
TheodoreSpeaks a636c3d
fix(admin): address review findings on recent impersonations
TheodoreSpeaks 24803be
fix(admin): exact server-side email filter for recent impersonation l…
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
apps/sim/app/workspace/[workspaceId]/settings/components/admin/use-recent-impersonations.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { useCallback, useState } from 'react' | ||
| import { RECENT_IMPERSONATIONS_STORAGE_KEY } from '@/stores' | ||
|
|
||
| const MAX_RECENT = 5 | ||
|
|
||
| function readRecentEmails(): string[] { | ||
| try { | ||
| const parsed = JSON.parse(localStorage.getItem(RECENT_IMPERSONATIONS_STORAGE_KEY) ?? '[]') | ||
| if (!Array.isArray(parsed)) return [] | ||
| return parsed.filter((e): e is string => typeof e === 'string').slice(0, MAX_RECENT) | ||
| } catch { | ||
| return [] | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Last {@link MAX_RECENT} emails the admin impersonated, most recent first, | ||
| * persisted in localStorage on this browser. | ||
| */ | ||
| export function useRecentImpersonations() { | ||
| const [recentEmails, setRecentEmails] = useState<string[]>(() => readRecentEmails()) | ||
|
|
||
| const recordImpersonation = useCallback((email: string) => { | ||
| const next = [email, ...readRecentEmails().filter((e) => e !== email)].slice(0, MAX_RECENT) | ||
| try { | ||
| localStorage.setItem(RECENT_IMPERSONATIONS_STORAGE_KEY, JSON.stringify(next)) | ||
| } catch { | ||
| /* best-effort: recording must never block the impersonation transition */ | ||
| } | ||
| setRecentEmails(next) | ||
| }, []) | ||
|
|
||
| return { recentEmails, recordImpersonation } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.