fix: datatrails: show a warning when search yields empty results (#81444)

* fix: datatrails: show a warning when search yields empty results
This commit is contained in:
Darren Janeczek 2024-01-29 16:54:56 -05:00 committed by GitHub
parent 226c76dc93
commit 24a6e6a1b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -217,9 +217,14 @@ export class MetricSelectScene extends SceneObjectBase<MetricSelectSceneState> {
};
public static Component = ({ model }: SceneComponentProps<MetricSelectScene>) => {
const { showHeading, searchQuery, showPreviews } = model.useState();
const { showHeading, searchQuery, showPreviews, body } = model.useState();
const { children } = body.useState();
const styles = useStyles2(getStyles);
const searchTooStrictWarning = children.length === 0 && searchQuery && (
<div className={styles.alternateMessage}>There are no results found. Try adjusting your search or filters.</div>
);
return (
<div className={styles.container}>
{showHeading && (
@ -231,6 +236,7 @@ export class MetricSelectScene extends SceneObjectBase<MetricSelectSceneState> {
<Input placeholder="Search metrics" value={searchQuery} onChange={model.onSearchChange} />
<InlineSwitch showLabel={true} label="Show previews" value={showPreviews} onChange={model.onTogglePreviews} />
</div>
{searchTooStrictWarning}
<model.state.body.Component model={model.state.body} />
</div>
);
@ -318,6 +324,11 @@ function getStyles(theme: GrafanaTheme2) {
gap: theme.spacing(2),
marginBottom: theme.spacing(1),
}),
alternateMessage: css({
fontStyle: 'italic',
marginTop: theme.spacing(7),
textAlign: 'center',
}),
};
}