feat: Show save badge in Dashboard Page (#166)

This commit is contained in:
Shorpo 2023-12-28 22:35:40 -07:00 committed by GitHub
parent af70f7d2b1
commit 5b3b2564ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---
Show save badge in Dashboard page

View file

@ -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';
@ -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) {
@ -639,17 +652,19 @@ export default function DashboardPage() {
{
onSuccess: () => {
queryClient.invalidateQueries(['dashboards']);
setSavedNow();
},
},
);
}
},
[
dashboardId,
updateDashboard,
queryClient,
isLocalDashboard,
setLocalDashboard,
updateDashboard,
dashboardId,
queryClient,
setSavedNow,
],
);
@ -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>
)}