Bookmarks: Add empty state to page (#92693)

This commit is contained in:
Joao Silva 2024-08-29 16:58:19 +01:00 committed by GitHub
parent 6ab120a448
commit bdb1c7ee63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 46 additions and 18 deletions

View File

@ -1,8 +1,9 @@
import { css } from '@emotion/css'; import { css } from '@emotion/css';
import { GrafanaTheme2 } from '@grafana/data'; import { GrafanaTheme2, NavModelItem } from '@grafana/data';
import { useStyles2 } from '@grafana/ui'; import { EmptyState, useStyles2 } from '@grafana/ui';
import { Page } from 'app/core/components/Page/Page'; import { Page } from 'app/core/components/Page/Page';
import { t, Trans } from 'app/core/internationalization';
import { useSelector } from 'app/types'; import { useSelector } from 'app/types';
import { usePinnedItems } from '../AppChrome/MegaMenu/hooks'; import { usePinnedItems } from '../AppChrome/MegaMenu/hooks';
@ -14,15 +15,29 @@ export function BookmarksPage() {
const pinnedItems = usePinnedItems(); const pinnedItems = usePinnedItems();
const navTree = useSelector((state) => state.navBarTree); const navTree = useSelector((state) => state.navBarTree);
const validItems = pinnedItems.reduce((acc: NavModelItem[], url) => {
const item = findByUrl(navTree, url);
if (item) {
acc.push(item);
}
return acc;
}, []);
return ( return (
<Page navId="bookmarks"> <Page navId="bookmarks">
<Page.Contents> <Page.Contents>
{validItems.length === 0 ? (
<EmptyState
variant="call-to-action"
message={t('bookmarks-page.empty.message', 'It looks like you havent created any bookmarks yet')}
>
<Trans i18nKey="bookmarks-page.empty.tip">
Hover over any item in the nav menu and click on the bookmark icon to add it here.
</Trans>
</EmptyState>
) : (
<section className={styles.grid}> <section className={styles.grid}>
{pinnedItems.map((url) => { {validItems.map((item) => {
const item = findByUrl(navTree, url);
if (!item) {
return null;
}
return ( return (
<NavLandingPageCard <NavLandingPageCard
key={item.id || item.url} key={item.id || item.url}
@ -33,6 +48,7 @@ export function BookmarksPage() {
); );
})} })}
</section> </section>
)}
</Page.Contents> </Page.Contents>
</Page> </Page>
); );

View File

@ -233,6 +233,12 @@
"message": "No API keys found" "message": "No API keys found"
} }
}, },
"bookmarks-page": {
"empty": {
"message": "It looks like you havent created any bookmarks yet",
"tip": "Hover over any item in the nav menu and click on the bookmark icon to add it here."
}
},
"bouncing-loader": { "bouncing-loader": {
"label": "Loading" "label": "Loading"
}, },

View File

@ -233,6 +233,12 @@
"message": "Ńő ÅPĨ ĸęyş ƒőūʼnđ" "message": "Ńő ÅPĨ ĸęyş ƒőūʼnđ"
} }
}, },
"bookmarks-page": {
"empty": {
"message": "Ĩŧ ľőőĸş ľįĸę yőū ĥävęʼnŧ čřęäŧęđ äʼny þőőĸmäřĸş yęŧ",
"tip": "Ħővęř ővęř äʼny įŧęm įʼn ŧĥę ʼnäv męʼnū äʼnđ čľįčĸ őʼn ŧĥę þőőĸmäřĸ įčőʼn ŧő äđđ įŧ ĥęřę."
}
},
"bouncing-loader": { "bouncing-loader": {
"label": "Ŀőäđįʼnģ" "label": "Ŀőäđįʼnģ"
}, },