-
Notifications
You must be signed in to change notification settings - Fork 1.8k
improvement(sync-secrets): add icon to show the sync status on secrets #5959
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
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a67df88
remove sticky from overview to fix horizontal scroll
adilsitos 190cad3
feat: add icon to show sync status into secrets
adilsitos 1cdb05f
enhancement: filter sync by env
adilsitos 0070ef5
fix sticky in single project
adilsitos 597bca3
feat: change status badge to be button instead of tooltip
adilsitos 18a9b95
fix: change column order
adilsitos 63de5e1
fix: refactor badge to be a component and change table UI for sync bu…
adilsitos 33dc079
style: adjust styling on sync popover display
scott-ray-wilson 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
137 changes: 137 additions & 0 deletions
137
frontend/src/pages/secret-manager/OverviewPage/components/SecretSyncStatusBadgeOverview.tsx
adilsitos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
adilsitos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
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,137 @@ | ||
| import { useMemo } from "react"; | ||
| import { useNavigate, useParams } from "@tanstack/react-router"; | ||
| import { formatDistanceToNow } from "date-fns"; | ||
| import { AlertTriangleIcon, CheckIcon, RefreshCwIcon } from "lucide-react"; | ||
|
|
||
| import { Badge, Tooltip, TooltipContent, TooltipTrigger } from "@app/components/v3"; | ||
| import { ROUTE_PATHS } from "@app/const/routes"; | ||
| import { useProject } from "@app/context"; | ||
| import { SecretSyncStatus, useListSecretSyncs } from "@app/hooks/api/secretSyncs"; | ||
| import { IntegrationsListPageTabs } from "@app/types/integrations"; | ||
|
|
||
| type BadgeState = { | ||
| variant: "neutral" | "danger" | "success"; | ||
| label: string; | ||
| Icon: typeof RefreshCwIcon; | ||
| isAnimated: boolean; | ||
| tooltipTitle: string; | ||
| }; | ||
|
|
||
| type Props = { | ||
| environmentSlugs?: string[]; | ||
| }; | ||
|
|
||
| export const SecretSyncStatusBadgeOverview = ({ environmentSlugs }: Props) => { | ||
| const navigate = useNavigate(); | ||
| const { projectId } = useProject(); | ||
| const orgId = useParams({ | ||
| from: ROUTE_PATHS.SecretManager.OverviewPage.id, | ||
| select: (el) => el.orgId | ||
| }); | ||
|
|
||
| const { data: secretSyncs = [] } = useListSecretSyncs(projectId, { | ||
| refetchInterval: 20_000 | ||
| }); | ||
adilsitos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const filteredSyncs = useMemo(() => { | ||
| if (!environmentSlugs || environmentSlugs.length === 0) return secretSyncs; | ||
| return secretSyncs.filter( | ||
| (s) => s.environment && environmentSlugs.includes(s.environment.slug) | ||
| ); | ||
| }, [secretSyncs, environmentSlugs]); | ||
|
|
||
| const { runningSyncs, failedSyncs, succeededSyncs } = useMemo(() => { | ||
| const running = filteredSyncs.filter( | ||
| (s) => s.syncStatus === SecretSyncStatus.Running || s.syncStatus === SecretSyncStatus.Pending | ||
| ); | ||
| const failed = filteredSyncs.filter((s) => s.syncStatus === SecretSyncStatus.Failed); | ||
| const succeeded = filteredSyncs.filter((s) => s.syncStatus === SecretSyncStatus.Succeeded); | ||
| return { runningSyncs: running, failedSyncs: failed, succeededSyncs: succeeded }; | ||
| }, [filteredSyncs]); | ||
|
|
||
| const badgeState = useMemo((): BadgeState | null => { | ||
| if (filteredSyncs.length === 0) return null; | ||
|
|
||
| if (runningSyncs.length > 0) { | ||
| return { | ||
| variant: "neutral", | ||
adilsitos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| label: `Syncing (${runningSyncs.length})`, | ||
| Icon: RefreshCwIcon, | ||
| isAnimated: true, | ||
| tooltipTitle: "Currently Syncing" | ||
| }; | ||
| } | ||
|
|
||
| if (failedSyncs.length > 0) { | ||
| return { | ||
| variant: "danger", | ||
| label: `Sync Failed (${failedSyncs.length})`, | ||
| Icon: AlertTriangleIcon, | ||
| isAnimated: false, | ||
| tooltipTitle: "Failed Syncs" | ||
| }; | ||
| } | ||
|
|
||
| if (succeededSyncs.length > 0) { | ||
| return { | ||
| variant: "success", | ||
| label: "Synced", | ||
| Icon: CheckIcon, | ||
adilsitos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| isAnimated: false, | ||
| tooltipTitle: "All Syncs Succeeded" | ||
| }; | ||
| } | ||
|
|
||
| return null; | ||
| }, [filteredSyncs, runningSyncs, failedSyncs, succeededSyncs]); | ||
|
|
||
| const displayedSyncs = useMemo(() => { | ||
| if (runningSyncs.length > 0) return runningSyncs; | ||
| if (failedSyncs.length > 0) return failedSyncs; | ||
| return succeededSyncs; | ||
| }, [runningSyncs, failedSyncs, succeededSyncs]); | ||
|
|
||
| if (!badgeState) return null; | ||
|
|
||
| const { variant, label, Icon, isAnimated, tooltipTitle } = badgeState; | ||
|
|
||
| const handleNavigateToSyncs = (e: React.MouseEvent) => { | ||
| e.stopPropagation(); | ||
| navigate({ | ||
| to: ROUTE_PATHS.SecretManager.IntegrationsListPage.path, | ||
| params: { orgId, projectId }, | ||
| search: { selectedTab: IntegrationsListPageTabs.SecretSyncs } | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <Badge asChild variant={variant}> | ||
| <button type="button" onClick={handleNavigateToSyncs}> | ||
| <Icon className={isAnimated ? "animate-spin" : ""} /> | ||
| {label} | ||
| </button> | ||
| </Badge> | ||
| </TooltipTrigger> | ||
| <TooltipContent className="max-w-xs"> | ||
| <div className="flex flex-col gap-1.5 py-1"> | ||
| <span className="text-xs font-medium">{tooltipTitle}</span> | ||
| {displayedSyncs.slice(0, 8).map((sync) => ( | ||
| <div key={sync.id} className="flex items-center gap-2 text-xs"> | ||
| <span className="truncate">{sync.name}</span> | ||
| {sync.lastSyncedAt && ( | ||
| <span className="ml-auto shrink-0 text-accent"> | ||
| {formatDistanceToNow(new Date(sync.lastSyncedAt), { addSuffix: true })} | ||
| </span> | ||
| )} | ||
| </div> | ||
| ))} | ||
| {displayedSyncs.length > 8 && ( | ||
| <span className="text-xs text-accent">and {displayedSyncs.length - 8} more...</span> | ||
| )} | ||
| </div> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| ); | ||
| }; | ||
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
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.