mirror of
https://github.com/grafana/grafana.git
synced 2026-01-15 05:35:41 +00:00
Compare commits
2 Commits
ihm/251217
...
ash/react-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e9f164d9f2 | ||
|
|
86fc051c58 |
@@ -22,7 +22,7 @@ import { getBarColorByDiff, getBarColorByPackage, getBarColorByValue } from './c
|
||||
import { CollapseConfig, CollapsedMap, FlameGraphDataContainer, LevelItem } from './dataTransform';
|
||||
|
||||
type RenderOptions = {
|
||||
canvasRef: RefObject<HTMLCanvasElement>;
|
||||
canvasRef: RefObject<HTMLCanvasElement | null>;
|
||||
data: FlameGraphDataContainer;
|
||||
root: LevelItem;
|
||||
direction: 'children' | 'parents';
|
||||
@@ -373,7 +373,7 @@ function useColorFunction(
|
||||
);
|
||||
}
|
||||
|
||||
function useSetupCanvas(canvasRef: RefObject<HTMLCanvasElement>, wrapperWidth: number, numberOfLevels: number) {
|
||||
function useSetupCanvas(canvasRef: RefObject<HTMLCanvasElement | null>, wrapperWidth: number, numberOfLevels: number) {
|
||||
const [ctx, setCtx] = useState<CanvasRenderingContext2D>();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -7,7 +7,7 @@ const CAUGHT_KEYS = ['ArrowUp', 'ArrowDown', 'Home', 'End', 'Enter', 'Tab'];
|
||||
|
||||
/** @internal */
|
||||
export interface UseListFocusProps {
|
||||
localRef: RefObject<HTMLUListElement>;
|
||||
localRef: RefObject<HTMLUListElement | null>;
|
||||
options: TimeOption[];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RefObject, useRef } from 'react';
|
||||
|
||||
export function useFocus(): [RefObject<HTMLInputElement>, () => void] {
|
||||
const ref = useRef<HTMLInputElement>(null);
|
||||
export function useFocus(): [RefObject<HTMLInputElement | null>, () => void] {
|
||||
const ref = useRef<HTMLInputElement | null>(null);
|
||||
const setFocus = () => {
|
||||
ref.current && ref.current.focus();
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ const UNFOCUSED = -1;
|
||||
|
||||
/** @internal */
|
||||
export interface UseMenuFocusProps {
|
||||
localRef: RefObject<HTMLDivElement>;
|
||||
localRef: RefObject<HTMLDivElement | null>;
|
||||
isMenuOpen?: boolean;
|
||||
close?: () => void;
|
||||
onOpen?: (focusOnItem: (itemId: number) => void) => void;
|
||||
|
||||
@@ -22,7 +22,7 @@ interface Props extends Omit<BoxProps, 'display' | 'direction' | 'element' | 'fl
|
||||
*
|
||||
* https://developers.grafana.com/ui/latest/index.html?path=/docs/layout-scrollcontainer--docs
|
||||
*/
|
||||
export const ScrollContainer = forwardRef<HTMLDivElement, PropsWithChildren<Props>>(
|
||||
export const ScrollContainer = forwardRef<HTMLDivElement | null, PropsWithChildren<Props>>(
|
||||
(
|
||||
{
|
||||
children,
|
||||
|
||||
@@ -20,7 +20,7 @@ export interface TableCellTooltipProps {
|
||||
field: Field;
|
||||
getActions: (field: Field, rowIdx: number) => ActionModel[];
|
||||
getTextColorForBackground: (bgColor: string) => string;
|
||||
gridRef: RefObject<DataGridHandle>;
|
||||
gridRef: RefObject<DataGridHandle | null>;
|
||||
height: number;
|
||||
placement?: TableCellTooltipPlacement;
|
||||
renderer: TableCellRenderer;
|
||||
|
||||
@@ -463,7 +463,7 @@ export function useColumnResize(
|
||||
return dataGridResizeHandler;
|
||||
}
|
||||
|
||||
export function useScrollbarWidth(ref: RefObject<DataGridHandle>, height: number) {
|
||||
export function useScrollbarWidth(ref: RefObject<DataGridHandle | null>, height: number) {
|
||||
const [scrollbarWidth, setScrollbarWidth] = useState(0);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
|
||||
@@ -135,7 +135,7 @@ export const Table = memo((props: Props) => {
|
||||
// `useTableStateReducer`, which is needed to construct options for `useTable` (the hook that returns
|
||||
// `toggleAllRowsExpanded`), and if we used a variable, that variable would be undefined at the time
|
||||
// we initialize `useTableStateReducer`.
|
||||
const toggleAllRowsExpandedRef = useRef<(value?: boolean) => void>();
|
||||
const toggleAllRowsExpandedRef = useRef<((value?: boolean) => void) | null>(null);
|
||||
|
||||
// Internal react table state reducer
|
||||
const stateReducer = useTableStateReducer({
|
||||
|
||||
@@ -14,8 +14,8 @@ import { GrafanaTableState } from './types';
|
||||
Select the scrollbar element from the VariableSizeList scope
|
||||
*/
|
||||
export function useFixScrollbarContainer(
|
||||
variableSizeListScrollbarRef: React.RefObject<HTMLDivElement>,
|
||||
tableDivRef: React.RefObject<HTMLDivElement>
|
||||
variableSizeListScrollbarRef: React.RefObject<HTMLDivElement | null>,
|
||||
tableDivRef: React.RefObject<HTMLDivElement | null>
|
||||
) {
|
||||
useEffect(() => {
|
||||
if (variableSizeListScrollbarRef.current && tableDivRef.current) {
|
||||
@@ -43,7 +43,7 @@ export function useFixScrollbarContainer(
|
||||
*/
|
||||
export function useResetVariableListSizeCache(
|
||||
extendedState: GrafanaTableState,
|
||||
listRef: React.RefObject<VariableSizeList>,
|
||||
listRef: React.RefObject<VariableSizeList | null>,
|
||||
data: DataFrame,
|
||||
hasUniqueId: boolean
|
||||
) {
|
||||
|
||||
@@ -19,7 +19,7 @@ interface EventsCanvasProps {
|
||||
}
|
||||
|
||||
export function EventsCanvas({ id, events, renderEventMarker, mapEventToXYCoords, config }: EventsCanvasProps) {
|
||||
const plotInstance = useRef<uPlot>();
|
||||
const plotInstance = useRef<uPlot | null>(null);
|
||||
// render token required to re-render annotation markers. Rendering lines happens in uPlot and the props do not change
|
||||
// so we need to force the re-render when the draw hook was performed by uPlot
|
||||
const [renderToken, setRenderToken] = useState(0);
|
||||
|
||||
@@ -140,7 +140,7 @@ export const TooltipPlugin2 = ({
|
||||
|
||||
const [{ plot, isHovering, isPinned, contents, style, dismiss }, setState] = useReducer(mergeState, null, initState);
|
||||
|
||||
const sizeRef = useRef<TooltipContainerSize>();
|
||||
const sizeRef = useRef<TooltipContainerSize | null>(null);
|
||||
const styles = useStyles2(getStyles, maxWidth);
|
||||
|
||||
const renderRef = useRef(render);
|
||||
|
||||
@@ -96,7 +96,7 @@ export interface GraphNGState {
|
||||
export class GraphNG extends Component<GraphNGProps, GraphNGState> {
|
||||
static contextType = PanelContextRoot;
|
||||
panelContext: PanelContext = {} as PanelContext;
|
||||
private plotInstance: React.RefObject<uPlot>;
|
||||
private plotInstance: React.RefObject<uPlot | null>;
|
||||
|
||||
private subscription = new Subscription();
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ const defaultMatchers = {
|
||||
* "Time as X" core component, expects ascending x
|
||||
*/
|
||||
export class GraphNG extends Component<GraphNGProps, GraphNGState> {
|
||||
private plotInstance: React.RefObject<uPlot>;
|
||||
private plotInstance: React.RefObject<uPlot | null>;
|
||||
|
||||
constructor(props: GraphNGProps) {
|
||||
super(props);
|
||||
|
||||
@@ -33,7 +33,7 @@ global.ResizeObserver = jest.fn().mockImplementation((callback) => {
|
||||
});
|
||||
|
||||
// Helper function to assign a mock div to a ref
|
||||
function assignMockDivToRef(ref: React.RefObject<HTMLDivElement>, mockDiv: HTMLDivElement) {
|
||||
function assignMockDivToRef(ref: React.RefObject<HTMLDivElement | null>, mockDiv: HTMLDivElement) {
|
||||
// Use type assertion to bypass readonly restriction in tests
|
||||
(ref as { current: HTMLDivElement | null }).current = mockDiv;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import grafanaTextLogoDarkSvg from 'img/grafana_text_logo_dark.svg';
|
||||
import grafanaTextLogoLightSvg from 'img/grafana_text_logo_light.svg';
|
||||
|
||||
interface SoloPanelPageLogoProps {
|
||||
containerRef: React.RefObject<HTMLDivElement>;
|
||||
containerRef: React.RefObject<HTMLDivElement | null>;
|
||||
isHovered: boolean;
|
||||
hideLogo?: UrlQueryValue;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ interface State {
|
||||
|
||||
class UnThemedTransformationsEditor extends React.PureComponent<TransformationsEditorProps, State> {
|
||||
subscription?: Unsubscribable;
|
||||
ref: RefObject<HTMLDivElement>;
|
||||
ref: RefObject<HTMLDivElement | null>;
|
||||
|
||||
constructor(props: TransformationsEditorProps) {
|
||||
super(props);
|
||||
|
||||
@@ -43,7 +43,7 @@ export const LibraryPanelsView = ({
|
||||
}
|
||||
);
|
||||
const asyncDispatch = useMemo(() => asyncDispatcher(dispatch), [dispatch]);
|
||||
const abortControllerRef = useRef<AbortController>();
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
|
||||
useDebounce(
|
||||
() => {
|
||||
|
||||
@@ -12,7 +12,7 @@ export interface Props {}
|
||||
|
||||
export const LiveConnectionWarning = memo(function LiveConnectionWarning() {
|
||||
const [show, setShow] = useState<boolean | undefined>(undefined);
|
||||
const subscriptionRef = useRef<Unsubscribable>();
|
||||
const subscriptionRef = useRef<Unsubscribable | null>(null);
|
||||
const styles = useStyles2(getStyle);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -38,7 +38,7 @@ export function useSearchKeyboardNavigation(
|
||||
): ItemSelection {
|
||||
const highlightIndexRef = useRef<ItemSelection>({ x: 0, y: -1 });
|
||||
const [highlightIndex, setHighlightIndex] = useState<ItemSelection>({ x: 0, y: -1 });
|
||||
const urlsRef = useRef<Field>();
|
||||
const urlsRef = useRef<Field | null>(null);
|
||||
|
||||
// Clear selection when the search results change
|
||||
useEffect(() => {
|
||||
|
||||
@@ -77,7 +77,7 @@ export const SuggestionsInput = ({
|
||||
const theme = useTheme2();
|
||||
const styles = getStyles(theme, inputHeight);
|
||||
|
||||
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement>();
|
||||
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
scrollRef.current?.scrollTo(0, scrollTop);
|
||||
|
||||
@@ -11,7 +11,7 @@ import checkboxWhitePng from 'img/checkbox_white.png';
|
||||
|
||||
import { ALL_VARIABLE_VALUE } from '../../constants';
|
||||
|
||||
export interface Props extends React.HTMLProps<HTMLUListElement>, Themeable2 {
|
||||
export interface Props extends Omit<React.HTMLProps<HTMLUListElement>, 'onToggle'>, Themeable2 {
|
||||
multi: boolean;
|
||||
values: VariableOption[];
|
||||
selectedValues: VariableOption[];
|
||||
|
||||
@@ -20,8 +20,8 @@ interface CodeEditorProps {
|
||||
export const LogsQLCodeEditor = (props: CodeEditorProps) => {
|
||||
const { query, datasource, onChange } = props;
|
||||
|
||||
const monacoRef = useRef<Monaco>();
|
||||
const disposalRef = useRef<monacoType.IDisposable>();
|
||||
const monacoRef = useRef<Monaco | null>(null);
|
||||
const disposalRef = useRef<monacoType.IDisposable | undefined>(undefined);
|
||||
|
||||
const onFocus = useCallback(async () => {
|
||||
disposalRef.current = await reRegisterCompletionProvider(
|
||||
|
||||
@@ -42,8 +42,8 @@ interface LogsCodeEditorProps {
|
||||
export const PPLQueryEditor = (props: LogsCodeEditorProps) => {
|
||||
const { query, datasource, onChange } = props;
|
||||
|
||||
const monacoRef = useRef<Monaco>();
|
||||
const disposalRef = useRef<monacoType.IDisposable>();
|
||||
const monacoRef = useRef<Monaco | null>(null);
|
||||
const disposalRef = useRef<monacoType.IDisposable | undefined>(undefined);
|
||||
|
||||
const onFocus = useCallback(async () => {
|
||||
disposalRef.current = await reRegisterCompletionProvider(
|
||||
|
||||
@@ -20,8 +20,8 @@ interface SQLCodeEditorProps {
|
||||
export const SQLQueryEditor = (props: SQLCodeEditorProps) => {
|
||||
const { query, datasource, onChange } = props;
|
||||
|
||||
const monacoRef = useRef<Monaco>();
|
||||
const disposalRef = useRef<monacoType.IDisposable>();
|
||||
const monacoRef = useRef<Monaco | null>(null);
|
||||
const disposalRef = useRef<monacoType.IDisposable | undefined>(undefined);
|
||||
|
||||
const onFocus = useCallback(async () => {
|
||||
disposalRef.current = await reRegisterCompletionProvider(
|
||||
|
||||
@@ -94,7 +94,7 @@ const EDITOR_HEIGHT_OFFSET = 2;
|
||||
* Hook that returns function that will set up monaco autocomplete for the label selector
|
||||
*/
|
||||
function useAutocomplete(getLabelValues: (label: string) => Promise<string[]>, labels?: string[]) {
|
||||
const providerRef = useRef<CompletionProvider>();
|
||||
const providerRef = useRef<CompletionProvider | null>(null);
|
||||
if (providerRef.current === undefined) {
|
||||
providerRef.current = new CompletionProvider();
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ export function LokiContextUi(props: LokiContextUiProps) {
|
||||
window.localStorage.getItem(SHOULD_INCLUDE_PIPELINE_OPERATIONS) === 'true'
|
||||
);
|
||||
|
||||
const timerHandle = useRef<number>();
|
||||
const timerHandle = useRef<number | null>(null);
|
||||
const previousInitialized = useRef<boolean>(false);
|
||||
const previousContextFilters = useRef<ContextFilter[]>([]);
|
||||
|
||||
@@ -191,14 +191,18 @@ export function LokiContextUi(props: LokiContextUiProps) {
|
||||
}, 1500);
|
||||
|
||||
return () => {
|
||||
clearTimeout(timerHandle.current);
|
||||
if (timerHandle.current) {
|
||||
clearTimeout(timerHandle.current);
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [contextFilters, initialized]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
clearTimeout(timerHandle.current);
|
||||
if (timerHandle.current) {
|
||||
clearTimeout(timerHandle.current);
|
||||
}
|
||||
onClose();
|
||||
};
|
||||
}, [onClose]);
|
||||
|
||||
@@ -52,7 +52,7 @@ export function TraceQLEditor(props: Props) {
|
||||
const onRunQueryRef = useRef(onRunQuery);
|
||||
onRunQueryRef.current = onRunQuery;
|
||||
|
||||
const errorTimeoutId = useRef<number>();
|
||||
const errorTimeoutId = useRef<number | null>(null);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -103,7 +103,9 @@ export function TraceQLEditor(props: Props) {
|
||||
}
|
||||
|
||||
// Remove previous callback if existing, to prevent squiggles from been shown while the user is still typing
|
||||
window.clearTimeout(errorTimeoutId.current);
|
||||
if (errorTimeoutId.current) {
|
||||
window.clearTimeout(errorTimeoutId.current);
|
||||
}
|
||||
|
||||
const errorNodes = getErrorNodes(model.getValue());
|
||||
const cursorPosition = changeEvent.changes[0].rangeOffset;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export function renderHistogram(
|
||||
can: React.RefObject<HTMLCanvasElement>,
|
||||
can: React.RefObject<HTMLCanvasElement | null>,
|
||||
histCanWidth: number,
|
||||
histCanHeight: number,
|
||||
xVals: number[],
|
||||
|
||||
@@ -196,7 +196,7 @@ export const LogsPanel = ({
|
||||
const dataSourcesMap = useDatasourcesFromTargets(panelData.request?.targets);
|
||||
// Prevents the scroll position to change when new data from infinite scrolling is received
|
||||
const keepScrollPositionRef = useRef<null | 'infinite-scroll' | 'user'>(null);
|
||||
let closeCallback = useRef<() => void>();
|
||||
const closeCallback = useRef<(() => void) | null>(null);
|
||||
const { app, eventBus, onAddAdHocFilter } = usePanelContext();
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -70,7 +70,7 @@ export function useLayout(
|
||||
const currentSignature = createDataSignature(rawNodes, rawEdges);
|
||||
|
||||
const isMounted = useMountedState();
|
||||
const layoutWorkerCancelRef = useRef<(() => void) | undefined>();
|
||||
const layoutWorkerCancelRef = useRef<(() => void) | null>(null);
|
||||
|
||||
useUnmount(() => {
|
||||
if (layoutWorkerCancelRef.current) {
|
||||
|
||||
@@ -133,7 +133,7 @@ export const AnnotationsPlugin2 = ({
|
||||
const newRangeRef = useRef(newRange);
|
||||
newRangeRef.current = newRange;
|
||||
|
||||
const xAxisRef = useRef<HTMLDivElement>();
|
||||
const xAxisRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
config.addHook('ready', (u) => {
|
||||
|
||||
@@ -23,7 +23,7 @@ export const ExemplarsPlugin = ({
|
||||
maxHeight,
|
||||
maxWidth,
|
||||
}: ExemplarsPluginProps) => {
|
||||
const plotInstance = useRef<uPlot>();
|
||||
const plotInstance = useRef<uPlot | null>(null);
|
||||
|
||||
const [lockedExemplarRowIndex, setLockedExemplarRowIndex] = useState<number | undefined>();
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ interface ThresholdControlsPluginProps {
|
||||
}
|
||||
|
||||
export const OutsideRangePlugin = ({ config, onChangeTimeRange }: ThresholdControlsPluginProps) => {
|
||||
const plotInstance = useRef<uPlot>();
|
||||
const plotInstance = useRef<uPlot | null>(null);
|
||||
const [timevalues, setTimeValues] = useState<number[] | TypedArray>([]);
|
||||
const [timeRange, setTimeRange] = useState<Scale | undefined>();
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ interface ThresholdControlsPluginProps {
|
||||
}
|
||||
|
||||
export const ThresholdControlsPlugin = ({ config, fieldConfig, onThresholdsChange }: ThresholdControlsPluginProps) => {
|
||||
const plotInstance = useRef<uPlot>();
|
||||
const plotInstance = useRef<uPlot | null>(null);
|
||||
const [renderToken, setRenderToken] = useState(0);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user