mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Command Palette: Add empty state (#81903)
* add an empty state for the command palette * cleaner logic
This commit is contained in:
parent
994aedaac3
commit
8c38ebfeae
@ -19,6 +19,7 @@ import { reportInteraction } from '@grafana/runtime';
|
|||||||
import { Icon, LoadingBar, useStyles2 } from '@grafana/ui';
|
import { Icon, LoadingBar, useStyles2 } from '@grafana/ui';
|
||||||
import { t } from 'app/core/internationalization';
|
import { t } from 'app/core/internationalization';
|
||||||
|
|
||||||
|
import { EmptyState } from './EmptyState';
|
||||||
import { KBarResults } from './KBarResults';
|
import { KBarResults } from './KBarResults';
|
||||||
import { ResultItem } from './ResultItem';
|
import { ResultItem } from './ResultItem';
|
||||||
import { useSearchResults } from './actions/dashboardActions';
|
import { useSearchResults } from './actions/dashboardActions';
|
||||||
@ -68,7 +69,7 @@ export function CommandPalette() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.resultsContainer}>
|
<div className={styles.resultsContainer}>
|
||||||
<RenderResults searchResults={searchResults} />
|
<RenderResults isFetchingSearchResults={isFetchingSearchResults} searchResults={searchResults} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</FocusScope>
|
</FocusScope>
|
||||||
@ -79,10 +80,11 @@ export function CommandPalette() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface RenderResultsProps {
|
interface RenderResultsProps {
|
||||||
|
isFetchingSearchResults: boolean;
|
||||||
searchResults: CommandPaletteAction[];
|
searchResults: CommandPaletteAction[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const RenderResults = ({ searchResults }: RenderResultsProps) => {
|
const RenderResults = ({ isFetchingSearchResults, searchResults }: RenderResultsProps) => {
|
||||||
const { results: kbarResults, rootActionId } = useMatches();
|
const { results: kbarResults, rootActionId } = useMatches();
|
||||||
const styles = useStyles2(getSearchStyles);
|
const styles = useStyles2(getSearchStyles);
|
||||||
const dashboardsSectionTitle = t('command-palette.section.dashboard-search-results', 'Dashboards');
|
const dashboardsSectionTitle = t('command-palette.section.dashboard-search-results', 'Dashboards');
|
||||||
@ -117,7 +119,11 @@ const RenderResults = ({ searchResults }: RenderResultsProps) => {
|
|||||||
return results;
|
return results;
|
||||||
}, [kbarResults, dashboardsSectionTitle, dashboardResultItems, foldersSectionTitle, folderResultItems]);
|
}, [kbarResults, dashboardsSectionTitle, dashboardResultItems, foldersSectionTitle, folderResultItems]);
|
||||||
|
|
||||||
return (
|
const showEmptyState = !isFetchingSearchResults && items.length === 0;
|
||||||
|
|
||||||
|
return showEmptyState ? (
|
||||||
|
<EmptyState />
|
||||||
|
) : (
|
||||||
<KBarResults
|
<KBarResults
|
||||||
items={items}
|
items={items}
|
||||||
maxHeight={650}
|
maxHeight={650}
|
||||||
|
31
public/app/features/commandPalette/EmptyState.tsx
Normal file
31
public/app/features/commandPalette/EmptyState.tsx
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { css } from '@emotion/css';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
|
import { Stack, Text, useStyles2 } from '@grafana/ui';
|
||||||
|
import { Trans } from 'app/core/internationalization';
|
||||||
|
|
||||||
|
export interface Props {}
|
||||||
|
|
||||||
|
export const EmptyState = ({}: Props) => {
|
||||||
|
const styles = useStyles2(getStyles);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.container}>
|
||||||
|
<Stack direction="column" alignItems="center">
|
||||||
|
<img src={'public/img/grot-not-found.svg'} width="200px" alt="grot" />
|
||||||
|
<Text variant="h5">
|
||||||
|
<Trans i18nKey="command-palette.empty-state.title">No results found</Trans>
|
||||||
|
</Text>
|
||||||
|
</Stack>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
EmptyState.displayName = 'EmptyState';
|
||||||
|
|
||||||
|
const getStyles = (theme: GrafanaTheme2) => ({
|
||||||
|
container: css({
|
||||||
|
padding: theme.spacing(8, 0),
|
||||||
|
}),
|
||||||
|
});
|
29
public/img/grot-not-found.svg
Normal file
29
public/img/grot-not-found.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 13 KiB |
@ -108,6 +108,9 @@
|
|||||||
"dark-theme": "Dark",
|
"dark-theme": "Dark",
|
||||||
"light-theme": "Light"
|
"light-theme": "Light"
|
||||||
},
|
},
|
||||||
|
"empty-state": {
|
||||||
|
"title": "No results found"
|
||||||
|
},
|
||||||
"search-box": {
|
"search-box": {
|
||||||
"placeholder": "Search or jump to..."
|
"placeholder": "Search or jump to..."
|
||||||
},
|
},
|
||||||
|
@ -108,6 +108,9 @@
|
|||||||
"dark-theme": "Đäřĸ",
|
"dark-theme": "Đäřĸ",
|
||||||
"light-theme": "Ŀįģĥŧ"
|
"light-theme": "Ŀįģĥŧ"
|
||||||
},
|
},
|
||||||
|
"empty-state": {
|
||||||
|
"title": "Ńő řęşūľŧş ƒőūʼnđ"
|
||||||
|
},
|
||||||
"search-box": {
|
"search-box": {
|
||||||
"placeholder": "Ŝęäřčĥ őř ĵūmp ŧő..."
|
"placeholder": "Ŝęäřčĥ őř ĵūmp ŧő..."
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user