Skip to content

Commit

Permalink
feat: Show save badge in Dashboard Page (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-shorpo committed Dec 29, 2023
1 parent af70f7d commit 5b3b256
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-wasps-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

Show save badge in Dashboard page
28 changes: 25 additions & 3 deletions packages/app/src/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useQueryParam,
withDefault,
} from 'use-query-params';
import { Badge, Transition } from '@mantine/core';

import api from './api';
import AppNav from './AppNav';
Expand Down Expand Up @@ -624,6 +625,18 @@ export default function DashboardPage() {
}, [dashboardsData, dashboardId, isLocalDashboard, localDashboard]);

// Update dashboard
const [isSavedNow, _setSavedNow] = useState(false);
const savedNowTimerRef = useRef<any>(null);
const setSavedNow = useCallback(() => {
if (savedNowTimerRef.current != null) {
clearTimeout(savedNowTimerRef.current);
}
_setSavedNow(true);
savedNowTimerRef.current = setTimeout(() => {
_setSavedNow(false);
}, 1500);
}, []);

const setDashboard = useCallback(
(newDashboard: Dashboard) => {
if (isLocalDashboard) {
Expand All @@ -639,17 +652,19 @@ export default function DashboardPage() {
{
onSuccess: () => {
queryClient.invalidateQueries(['dashboards']);
setSavedNow();
},
},
);
}
},
[
dashboardId,
updateDashboard,
queryClient,
isLocalDashboard,
setLocalDashboard,
updateDashboard,
dashboardId,
queryClient,
setSavedNow,
],
);

Expand Down Expand Up @@ -895,6 +910,13 @@ export default function DashboardPage() {
})
}
/>
<Transition mounted={isSavedNow} transition="skew-down">
{style => (
<Badge fw="normal" tt="none" ml="xs" style={style}>
Saved now
</Badge>
)}
</Transition>
{isLocalDashboard && (
<span className="text-muted ms-3">(Unsaved Dashboard)</span>
)}
Expand Down

0 comments on commit 5b3b256

Please sign in to comment.