mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Logs Volume: identify timeouts and provide remediation action * Supplementary result error: refactor updated component API * Create helper to identify timeout errors * Update timeout identifying function * Add unit test * Update panel unit test * Update public/app/features/explore/utils/logsVolumeResponse.ts Co-authored-by: Giordano Ricci <me@giordanoricci.com> * Use some instead of reduce * Change alert type to info * Add comment * Remove unnecessary optional chaining * Remove unnecessary condition * Remove unnecessary wrapping arrow function --------- Co-authored-by: Giordano Ricci <me@giordanoricci.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import React, { useState } from 'react';
|
|
|
|
import { DataQueryError } from '@grafana/data';
|
|
import { Alert, AlertVariant, Button } from '@grafana/ui';
|
|
|
|
type Props = {
|
|
error?: DataQueryError;
|
|
title: string;
|
|
severity?: AlertVariant;
|
|
suggestedAction?: string;
|
|
onSuggestedAction?(): void;
|
|
onRemove?(): void;
|
|
};
|
|
export function SupplementaryResultError(props: Props) {
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const SHORT_ERROR_MESSAGE_LIMIT = 100;
|
|
const { error, title, suggestedAction, onSuggestedAction, onRemove, severity = 'warning' } = props;
|
|
// generic get-error-message-logic, taken from
|
|
// /public/app/features/explore/ErrorContainer.tsx
|
|
const message = error?.message || error?.data?.message || '';
|
|
const showButton = !isOpen && message.length > SHORT_ERROR_MESSAGE_LIMIT;
|
|
|
|
return (
|
|
<Alert title={title} severity={severity} onRemove={onRemove}>
|
|
{showButton ? (
|
|
<Button
|
|
variant="secondary"
|
|
size="xs"
|
|
onClick={() => {
|
|
setIsOpen(true);
|
|
}}
|
|
>
|
|
Show details
|
|
</Button>
|
|
) : (
|
|
message
|
|
)}
|
|
{suggestedAction && onSuggestedAction && (
|
|
<Button variant="primary" size="xs" onClick={onSuggestedAction}>
|
|
{suggestedAction}
|
|
</Button>
|
|
)}
|
|
</Alert>
|
|
);
|
|
}
|