Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
features
/
dashboard
/
components
/
PanelEditor
/
File Content:
usePanelLatestData.ts
import { useEffect, useRef, useState } from 'react'; import { Unsubscribable } from 'rxjs'; import { LoadingState, PanelData } from '@grafana/data'; import { GetDataOptions } from '../../../query/state/PanelQueryRunner'; import { PanelModel } from '../../state'; interface UsePanelLatestData { data?: PanelData; hasError: boolean; isLoading: boolean; hasSeries: boolean; } /** * Subscribes and returns latest panel data from PanelQueryRunner */ export const usePanelLatestData = ( panel: PanelModel, options: GetDataOptions, checkSchema?: boolean ): UsePanelLatestData => { const querySubscription = useRef<Unsubscribable>(); const [latestData, setLatestData] = useState<PanelData>(); useEffect(() => { let lastRev = -1; let lastUpdate = 0; querySubscription.current = panel .getQueryRunner() // We apply field config later .getData({ withTransforms: options.withTransforms, withFieldConfig: false }) .subscribe({ next: (data) => { if (checkSchema) { if (lastRev === data.structureRev) { const now = Date.now(); const elapsed = now - lastUpdate; if (elapsed < 10000) { return; // avoid updates if the schema has not changed for 10s } lastUpdate = now; } lastRev = data.structureRev ?? -1; } setLatestData(data); }, }); return () => { if (querySubscription.current) { querySubscription.current.unsubscribe(); } }; /** * Adding separate options to dependencies array to avoid additional hook for comparing previous options with current. * Otherwise, passing different references to the same object might cause troubles. */ // eslint-disable-next-line react-hooks/exhaustive-deps }, [panel, options.withTransforms]); return { data: latestData, isLoading: latestData?.state === LoadingState.Loading, hasSeries: latestData ? !!latestData.series : false, hasError: Boolean( latestData && (latestData.error || latestData?.errors?.length || latestData.state === LoadingState.Error) ), }; };
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
state
---
0755
AngularPanelOptions.tsx
3907 bytes
0644
DynamicConfigValueEditor.tsx
3678 bytes
0644
OptionsPane.tsx
2615 bytes
0644
OptionsPaneCategory.tsx
5759 bytes
0644
OptionsPaneCategoryDescriptor.tsx
1835 bytes
0644
OptionsPaneItemDescriptor.tsx
3584 bytes
0644
OptionsPaneItemOverrides.tsx
1208 bytes
0644
OptionsPaneOptions.test.tsx
9120 bytes
0644
OptionsPaneOptions.tsx
7812 bytes
0644
OverrideCategoryTitle.tsx
2069 bytes
0644
PanelEditor.tsx
16794 bytes
0644
PanelEditorQueries.tsx
4139 bytes
0644
PanelEditorTableView.test.tsx
7264 bytes
0644
PanelEditorTableView.tsx
2203 bytes
0644
PanelEditorTabs.tsx
4931 bytes
0644
PanelHeaderCorner.test.tsx
708 bytes
0644
PanelHeaderCorner.tsx
3489 bytes
0644
PanelNotSupported.test.tsx
1398 bytes
0644
PanelNotSupported.tsx
849 bytes
0644
VisualizationButton.tsx
2277 bytes
0644
VisualizationSelectPane.tsx
6512 bytes
0644
getFieldOverrideElements.tsx
8273 bytes
0644
getLibraryPanelOptions.tsx
1704 bytes
0644
getPanelFrameOptions.tsx
11327 bytes
0644
getVisualizationOptions.test.ts
4366 bytes
0644
getVisualizationOptions.tsx
9787 bytes
0644
types.ts
1823 bytes
0644
usePanelLatestData.ts
2206 bytes
0644
utils.test.ts
5250 bytes
0644
utils.ts
2895 bytes
0644
N4ST4R_ID | Naxtarrr